# Passing GLFWwindowsizefun into function

**URL:** <https://discourse.glfw.org/t/passing-glfwwindowsizefun-into-function/299>\
**Category:** support\
**Created:** [December 1, 2010, 2:45am UTC](https://discourse.glfw.org/t/passing-glfwwindowsizefun-into-function/299 "2010-12-01T02:45:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)\
**Post date:** [December 1, 2010, 2:45am UTC](https://discourse.glfw.org/t/passing-glfwwindowsizefun-into-function/299/1 "2010-12-01T02:45:19Z")

</div>

**[trulystupidnewb](https://sourceforge.net/u/trulystupidnewb/)** wrote on [Wednesday, December 01, 2010](https://sourceforge.net/p/glfw/discussion/247562/thread/1a10cfca/#227d):

Hello. I’m having a bit of trouble with passing a function pointer from a  
function parameter into glfwSetWindowSizeCallback. I’ve been trying to do it  
for about 5 hours. I’m running VC++ 2010 under both Window XP (one computer)  
and Windows 7 (another computer).

I’m trying to pass this function:

// declaration  
static void GLFWCALL Resize(int width, int height);

// definition  
void GLFWCALL TestGame::Resize(int width, int height)  
{  
glViewport(0, 0, width, height); // Sets the viewport to fit the size of the  
new window

glMatrixMode(GL\_PROJECTION); // Prepare to set up the projection matrix  
glLoadIdentity(); // First reset the matrix

// Then calculate new projection matrix  
gluPerspective(45.0f, // angle of view  
(float)width/height, // screen aspect ratio  
5.0f, // near plane for drawing cutoff  
600.0f); // far plane for drawing cutoff

glMatrixMode(GL\_MODELVIEW); // Now switch back to the modelview matrix  
glLoadIdentity(); // Reset it and we are ready to draw  
}

through this function:

// declaration  
void SetResizeFunction(void (\*resizeFunction) (int, int));  
//definition  
void GlfwWindow::SetResizeFunction(void (\*resizeFunction) (int, int))  
{  
glfwSetWindowSizeCallback((GLFWwindowsizefun)resizeFunction);  
}

and calling it like this:

#include “TestGame.h”  
#include “GlfwWindow.h”  
#include “TWInput.h”

#include   
#include

std::auto\_ptr g\_glfwWindow;  
std::auto\_ptr g\_TWInput;  
std::auto\_ptr g\_TWGame;

int main()  
{  
try  
{  
g\_glfwWindow = GlfwWindow::CreateGlfwWindow(“Star Sema”, 800, 600);  
g\_glfwWindow-\>SetResizeFunction(TestGame::Resize);  
g\_glfwWindow-\>SetCloseFunction(TestGame::Close);

g\_TWInput = TWInput::CreateTWInput();  
g\_TWGame = TestGame::CreateGame();

double deltaTime = 0.0;  
while ( g\_TWGame-\>IsRunning() )  
{  
deltaTime = g\_glfwWindow-\>GetElapsedSeconds();

g\_TWGame-\>Update(deltaTime);  
g\_TWGame-\>Render();

g\_glfwWindow-\>SwapBuffers();  
}  
}  
catch(std::string errorMessage)  
{  
std::cout \<\< errorMessage \<\< std::endl;  
}

return 0;  
}

The SetCloseFunction works. However, the SetResizeFunction throws “Unhandled  
exception at 0x00000258 in Barebones.exe: 0xC0000005: Access violation.”

This is truly mysterious because both functions are written similarily but one  
works and the other doesnt:

this works:

void GlfwWindow::SetCloseFunction(int (\*closeFunction) (void))  
{  
glfwSetWindowCloseCallback((GLFWwindowclosefun)closeFunction);  
}

does anyone have any suggestions on passing GLFWwindowsizefun as a param?  
Thanks in advance!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)\
**Post date:** [December 1, 2010, 3:15am UTC](https://discourse.glfw.org/t/passing-glfwwindowsizefun-into-function/299/2 "2010-12-01T03:15:48Z")

</div>

**[trulystupidnewb](https://sourceforge.net/u/trulystupidnewb/)** wrote on [Wednesday, December 01, 2010](https://sourceforge.net/p/glfw/discussion/247562/thread/1a10cfca/#534f):

I did another 30 minutes of experiments. It seems that the linker is like  
bugging up. Calling SetCloseFunction(width, height) works perfectly inside a  
GlfwWindow (custom class) function, but somehow when I try to use it in  
main, the linker sometimes cannot resolve TestGame::Resize or other random  
issues. It seems like the function is passing the param correctly. Something  
else is wrong. Any hints?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)\
**Post date:** [December 1, 2010, 3:36am UTC](https://discourse.glfw.org/t/passing-glfwwindowsizefun-into-function/299/3 "2010-12-01T03:36:41Z")

</div>

**[trulystupidnewb](https://sourceforge.net/u/trulystupidnewb/)** wrote on [Wednesday, December 01, 2010](https://sourceforge.net/p/glfw/discussion/247562/thread/1a10cfca/#423d):

Nevermind, I solved the issue. I had to includ glfw.lib instead of glfwdll.lib  
and remove all the #define GLFW\_DLL. It works perfectly now. Thanks.
