Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/142.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ CreateWindowsEx()失败,已触发断点_C++_Winapi_Opengl_Createwindowex - Fatal编程技术网

C++ CreateWindowsEx()失败,已触发断点

C++ CreateWindowsEx()失败,已触发断点,c++,winapi,opengl,createwindowex,C++,Winapi,Opengl,Createwindowex,我在从应用程序打开OpenGL窗口时遇到问题 我正在使用一个64位控制台应用程序,我想从该控制台中打开另一个窗口,供OpenGL使用 调用在CreateWindowEx()处失败,并因“MyApp.exe已触发断点”而失败 下面的代码初始化窗口本身 bool OpenGL_Display::CreateGLWindow(char* title, int width, int height, int bits, bool fullscreenflag, int posX, int posY) {

我在从应用程序打开OpenGL窗口时遇到问题

我正在使用一个64位控制台应用程序,我想从该控制台中打开另一个窗口,供OpenGL使用

调用在CreateWindowEx()处失败,并因“MyApp.exe已触发断点”而失败 下面的代码初始化窗口本身

bool OpenGL_Display::CreateGLWindow(char* title, int width, int height, int bits, bool fullscreenflag, int posX, int posY)
{
    GLuint      PixelFormat;            // Holds The Results After Searching For A Match
    WNDCLASS    wc;                     // Windows Class Structure
    DWORD       dwExStyle;              // Window Extended Style
    DWORD       dwStyle;                // Window Style
    RECT        WindowRect;             // Grabs Rectangle Upper Left / Lower Right Values
    WindowRect.left=(long)0;            // Set Left Value To 0
    WindowRect.right=(long)width;       // Set Right Value To Requested Width
    WindowRect.top=(long)0;             // Set Top Value To 0
    WindowRect.bottom=(long)height;     // Set Bottom Value To Requested Height

    hInstance           = GetModuleHandle(NULL);                // Grab An Instance For Our Window
    wc.style            = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;   // Redraw On Size, And Own DC For Window.
    wc.lpfnWndProc      = NULL;                 // WndProc Handles Messages
    wc.cbClsExtra       = 0;                                    // No Extra Window Data
    wc.cbWndExtra       = 0;                                    // No Extra Window Data
    wc.hInstance        = hInstance;                            // Set The Instance
    wc.hIcon            = LoadIcon(NULL, IDI_WINLOGO);          // Load The Default Icon
    wc.hCursor          = LoadCursor(NULL, IDC_ARROW);          // Load The Arrow Pointer
    wc.hbrBackground    = NULL;                                 // No Background Required For GL
    wc.lpszMenuName     = NULL;                                 // We Don't Want A Menu
    wc.lpszClassName    = "OpenGL";                             // Set The Class Name

    if (!RegisterClass(&wc))                                    // Attempt To Register The Window Class
    {
        MessageBox(NULL,"Failed To Register The Window Class.","ERROR",MB_OK|MB_ICONEXCLAMATION);
        return FALSE;                                           // Return FALSE
    }

    dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;           // Window Extended Style
    dwStyle=WS_OVERLAPPEDWINDOW;                            // Windows Style

    AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle);     // Adjust Window To True Requested Size
    HWND hwndC = GetConsoleWindow();
    // Create The Window
    if (!(hWnd=CreateWindowEx(  dwExStyle,                          // Extended Style For The Window
                                "OpenGL",                           // Class Name
                                title,                              // Window Title
                                dwStyle |                           // Defined Window Style
                                WS_CLIPSIBLINGS |                   // Required Window Style
                                WS_CLIPCHILDREN,                    // Required Window Style
                                0, 0,                               // Window Position
                                WindowRect.right-WindowRect.left,   // Calculate Window Width
                                WindowRect.bottom-WindowRect.top,   // Calculate Window Height
                                hwndC,                              // No Parent Window
                                NULL,                               // No Menu
                                hInstance,                          // Instance
                                NULL)))                             // Dont Pass Anything To WM_CREATE
    {
        KillGLWindow();                             // Reset The Display
        MessageBox(NULL,"Window Creation Error.","ERROR",MB_OK|MB_ICONEXCLAMATION);
        return FALSE;                               // Return FALSE
    }
}
前面的代码指向它:

extern "C" __declspec(dllexport) void OpenGLDisplay_Init(int width, int height, int posX, int posY)
{
    oglDisp.Init_Display(width, height, posX, posY);
}

void OpenGL_Display::Init_Display(int width, int height, int posX, int posY)
{
    if (!CreateGLWindow("Ophthametrics Live Display", width, height, 24, false, posX, posY))
    {
        throw;
    }   
}
那里出了什么问题?我不知道,我正在使用我用于另一个应用程序的代码,它工作得很好。在这里,尽管它失败得很厉害(在原始代码中,它不是控制台应用程序,而是没有控制台的Win32应用程序)


最终的解决方案是在一个被调用的DLL中,一旦它被调用,它应该为OpenGL创建一个窗口以供绘制。

如果您将窗口进程指向一个实际函数,会怎么样


由slugo编写,就是这样。

HWND-hwndC=GetConsoleWindow()-是否返回有效的
HWND
?另外,对于无父级,只需在
hwndC
的位置传递
NULL
。是的,它将返回一个有效句柄。我也尝试过使用NULL作为父窗口,但仍然会发生相同的错误。如果您将window proc指向一个真实的函数会怎么样?记录您在输出窗口中看到的内容,它应该描述触发断点的原因。然后发布调用堆栈窗口的内容。Slugo,有趣的是,这就是错误所在,它现在正在工作。你能把这个作为答案贴出来吗?这样我就可以接受了?