''glfwCreateWindow' freezes when called in Dllmain
When I call glfwCreateWindow in DllMain, the program freezes and CPU usage drops to 0%.
My code works fine if I change the type of program from .dll to .exe, and replace DllMain with main.
Here is part of my code:
BOOL WINAPI DllMain(
HINSTANCE hinstDLL,
DWORD fdwReason,
LPVOID lpReserved)
{
GLFWwindow* window;
/* Initialize the library */
if (!glfwInit())
{
std::cout << "glfw init failed" << std::endl;
return;
}
std::cout << "1" << std::endl;
/* Create a windowed mode window and its OpenGL context */
window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
if (!window)
{
std::cout << "window creation failed" << std::endl;
glfwTerminate();
return;
}
std::cout << "2" << std::endl;
/* Make the window's context current */
glfwMakeContextCurrent(window);
return TRUE;
}
When I run the program, 1 gets printed, however the program freezes and 2 never gets printed.
Solution 1:[1]
There is a very limited number of things you can do in DllMain, as detailed here.
You're going to have to find some way to defer the calls to GLFW. Perhaps an explicit initialisation call on your DLL is the way to go.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Paul Sanders |
