# Problems with glfwGetWindowUserPointer

**URL:** <https://discourse.glfw.org/t/problems-with-glfwgetwindowuserpointer/2093>\
**Category:** support\
**Created:** [July 10, 2022, 4:26pm UTC](https://discourse.glfw.org/t/problems-with-glfwgetwindowuserpointer/2093 "2022-07-10T16:26:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![lillis](https://avatars.discourse-cdn.com/v4/letter/l/a183cd/32.png) [@lillis](https://discourse.glfw.org/u/lillis)\
**Post date:** [July 10, 2022, 4:26pm UTC](https://discourse.glfw.org/t/problems-with-glfwgetwindowuserpointer/2093/1 "2022-07-10T16:26:25Z")

</div>

Hey!  
So i am very new to both C++ and glfw in general. I am attempting to make a game engine and i have been following a youtube series but i ran into a problem regarding  
the function glfwGetWindowUserPointer.

The Code is the following:  
/In a file called Window.h  
/

```auto
 class Window
        {

        public:
            static Window* INSTANCE;

            

        private: 
            
            const char *m_Title;
            int m_Width, m_Height;
            GLFWwindow *m_Window;
            bool m_Closed;

            
            static bool m_Keys[1024];
            static bool m_MouseButtons[32];
            static double mx, my;

        public:
            Window(const char* name, int widht, int height);
            ~Window();
            void clear() const;
            bool closed() const;
            void update();
            
            inline int getwidht() const { return m_Width; }
            inline int getheight() const { return m_Height; }

            static bool isKeyPressed(unsigned int keycode);

        private:
            bool init();
           
            
            
            
            friend static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods);
           

        };
    }

```

//In Window.cpp

```auto
namespace graphics {

		bool Window::m_Keys[1024];
		bool Window::m_MouseButtons[32];
		double Window::mx, my;
		

		void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods);

		Window::Window(const char* title, int widht, int height)
		{
			m_Title = title;
			m_Width = widht;
			m_Height = height;
			
			if (!init())
				glfwTerminate();

			INSTANCE = this;
			
			for (int i = 0; i < 1024; i++)
			{
				m_Keys[i] = false;
			}

			for (int i = 0; i < 32; i++)
			{
				m_MouseButtons[i] = false;
			}
		}

		Window::~Window()
		{
			glfwTerminate();
		}

		bool Window::init() 
		{
			if (!glfwInit())
			{
				std::cout << "Failed to initialize GLFW" << std::endl;
				return false;
			}
				
			
			m_Window = glfwCreateWindow(m_Width, m_Height, m_Title, NULL, NULL);
			if (!m_Window)
			{
		
				std::cout << "failed to create GLFW window" << std::endl;
				return false;
			}
			glfwMakeContextCurrent(m_Window);
			glfwGetWindowUserPointer(m_Window);
			glfwSetKeyCallback(m_Window, key_callback);
			
		    std::cout << "OpenGL" << glGetString(GL_VERSION) << std::endl;

			if(glewInit() != GLEW_OK)
			{
				std::cout << "could not initialize GLEW" << std::endl;
				return false;
			}

			return true;

		}
	 	
		bool Window::isKeyPressed(unsigned int keycode) 
		{
			if (keycode >= 1024)
				return false;

			return m_Keys[keycode];
		}

		void Window::clear() const
		{
			glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		}

		bool Window::closed() const
		{
			return glfwWindowShouldClose(m_Window);
		}

		
		void Window::update()
	    {
			glfwPollEvents();
			glfwGetFramebufferSize(m_Window, &m_Width, &m_Height);
			glViewport(0, 0, m_Width, m_Height);
			
			 glfwSwapBuffers(m_Window);
			
		}

		void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
		{
			Window* win = (Window*) glfwGetWindowUserPointer(window);
			
			win->m_Keys[key] = action != GLFW_RELEASE;

		}
		
	}

```

now the problem is that i cannot type the following:  
glfwSetWindowUserPointer(m\_window, this);  
writing “this”, makes so that there are to many arguments but without it i dont have a pointer.  
Are there any easy fixes to this?  
I am very new to this so this is probably something small but thank you in advance for the help.

---

<div class="post-metadata">

**Author:** ![mmozeiko](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/mmozeiko/32/29_2.png) [@mmozeiko](https://discourse.glfw.org/u/mmozeiko)\
**Post date:** [July 11, 2022, 5:37am UTC](https://discourse.glfw.org/t/problems-with-glfwgetwindowuserpointer/2093/2 "2022-07-11T05:37:18Z")

</div>

Are you sure you’re writing `glfwSetWindowUserPointer(m_window, this) `and not `glfwGetWindowUserPointer`?

In your `Window::init` method you have `glfwGetWindowUserPointer` call after `glfwCreateWindow` which does not seem right.
