'glfwCreateWindow'在Dllmain中调用时冻结

'glfwCreateWindow' freezes when called in Dllmain

本文关键字:冻结 调用 glfwCreateWindow Dllmain      更新时间:2024-09-28

当我在DllMain中调用glfwCreateWindow时,程序冻结,CPU使用率降至0%。

如果我将程序类型从.dll更改为.exe,并将DllMain替换为main,我的代码就可以正常工作。

这是我的部分代码:

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;
}

当我运行程序时,1会被打印出来,但程序会冻结,2永远不会被打印出来。

DllMain中可以做的事情非常有限,如下所述。

你必须想办法推迟打给GLFW的电话。也许对DLL进行明确的初始化调用是可行的。