'glfwCreateWindow'在Dllmain中调用时冻结
'glfwCreateWindow' freezes when called in Dllmain
当我在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进行明确的初始化调用是可行的。
相关文章:
- 什么时候调用组成单元对象的析构函数
- 对RValue对象调用的LValue ref限定成员函数
- 为什么使用 "this" 指针调用派生成员函数?
- 函数调用中参数的顺序重要吗
- OpenGL - 在抛出"__gnu_cxx::recursive_init_error"实例后终止调用?
- 基于另一个成员参数将函数调用从类传递给它的一个成员
- 为什么我的C#代码在调用回C++COM直到Task时会暂停.等待/线程.加入
- 在c++类上调用void函数
- 为什么 std::unique 不调用 std::sort?
- 调用专用模板时出错"no matching function for call to [...]"
- 选择要调用的构造函数
- C++为什么尽管我调用了void函数,它却不起作用
- 构造函数正在调用一个使用当前类类型的函数
- 变量没有改变?通过向量的函数调用
- WIN32:C++,为什么在WM_CLOSE上调用Messagebox函数程序正在冻结
- 程序在对mouse_event的 Windows API 调用中冻结
- 调用删除会导致程序冻结C++
- 函数调用会导致C++程序冻结,除非在调试器中逐步执行
- 当我调用一个函数时,c++列表程序冻结
- 程序在脚本调用时冻结