我正努力向OpenGL迈出第一步。
但是,似乎不会发生这种情况,因为在尝试调试解决方案时会出现此错误:
msvcrdt.lib(crtexe.obj):错误LNK2019:函数tmainCRTStartup中引用的未解析外部符号main
我知道编译器希望看到int main() ...,但它没有看到WinMain调用吗?
代码如下:

#include <Windows.h>
#include <stdio.h>
#include <stdlib.h>

typedef struct {
    HWND hWnd;
} Glab_t;

static Glab_t glab;

char szClassName[ ] = "GLab";

static LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
    switch (message) {
        case WM_DESTROY:
            PostQuitMessage (0);
            break;
        default:
            return DefWindowProc (hwnd, message, wParam, lParam);
    }

    return 0;
}


int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {

    MSG messages;
    RECT rect;
    WNDCLASSEX wndClass;
    int screenWidth, screenHeight;
    int x, y, w, h;

    screenWidth = GetSystemMetrics(SM_CXSCREEN);
    screenHeight = GetSystemMetrics(SM_CYSCREEN);

    rect.left = (screenWidth - 582) / 2;
    rect.top = (screenHeight - 358) / 2;
    rect.right = rect.left + 582;
    rect.bottom = rect.top + 358;

    x = rect.left;
    y = rect.top;
    w = 640;
    h = 480;



    wndClass.hInstance = hInstance;
    wndClass.lpszClassName = szClassName;
    wndClass.lpfnWndProc = WindowProcedure;
    wndClass.style = CS_DBLCLKS;
    wndClass.cbSize = sizeof (WNDCLASSEX);
    wndClass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wndClass.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wndClass.hCursor = LoadCursor (NULL, IDC_ARROW);
    wndClass.lpszMenuName = NULL;
    wndClass.cbClsExtra = 0;
    wndClass.cbWndExtra = 0;
    wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);

    if (!RegisterClassEx (&wndClass)) {
        return 0;
    }

    glab.hWnd = CreateWindowEx (
           0,
           szClassName,
           "GLab - OpenGL",
           WS_OVERLAPPEDWINDOW,
           x,
           y,
           w,
           h,
           HWND_DESKTOP,
           NULL,
           hInstance,
           NULL
           );

    ShowWindow (glab.hWnd, nCmdShow);
    while (GetMessage (&messages, NULL, 0, 0)) {
        TranslateMessage(&messages);
        DispatchMessage(&messages);
    }

    return true;
}

我使用的是MS Visual C++ 2010 Express。

最佳答案

您有一个subsystemConsole而不是Windows的项目。从项目属性中更改它,它将工作。在链接器->系统->子系统中。

09-08 01:06