-1

当我调用glfwCreateWindowDllMain,程序冻结,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。

4

1 回答 1

0

您可以做的事情非常有限DllMain,详见此处

你将不得不找到一些方法来推迟对 GLFW 的调用。也许对您的 DLL 进行显式初始化调用是可行的方法。

于 2022-01-24T17:48:57.347 回答