Folls 2020-12-28 08:35 采纳率: 0%
浏览 1136

VS2019中报错LNK2019 无法解析的外部符号 _main,函数 "int

#include<Windows.h>
#include<iostream>
#include<stdio.h>
#ifdef _UNICODE
#define __T(x) L ## x
#else
#define __T(x) x
#endif
#define _T(x) __T(x)
#define _TEXT __T(x)

LRESULT CALLBACK WinSunProc(
    HWND hwnd,
    UINT uMsg,
    WPARAM wParam,
    LPARAM lParam
);

int WINAPI WinMain(
    _In_ HINSTANCE hInstance,
    _In_opt_ HINSTANCE hPrevInstance,
    _In_ LPSTR lpCmdLine,
    _In_ int nShowCmd
)
{
    WNDCLASS wndcls;
    wndcls.cbClsExtra = 0;
    wndcls.cbWndExtra = 0;
    wndcls.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
    wndcls.hCursor = LoadCursor(NULL, IDC_ARROW);
    wndcls.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wndcls.hInstance = hInstance;
    wndcls.lpfnWndProc = WinSunProc;
    wndcls.lpszClassName = _T("winxin2003");
    wndcls.lpszMenuName = NULL;
    wndcls.style = CS_HREDRAW || CS_VREDRAW;
    RegisterClass(&wndcls);

    HWND hwnd;
    hwnd = CreateWindow(_T("weixin2003"), _T("winxin"), WS_OVERLAPPEDWINDOW, 0, 0, 600, 400, NULL, NULL, hInstance, NULL);

    ShowWindow(hwnd, SW_SHOWNORMAL);
    UpdateWindow(hwnd);

    MSG msg;

    while (GetMessage(&msg, NULL, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    return 0;
}

LRESULT CALLBACK WinSunProc(
    HWND hwnd,
    UINT uMsg,
    WPARAM wParam,
    LPARAM lParam
)
{
    switch (uMsg)
    {
    case WM_CHAR:
        char szChar[20];
        sprintf_s(szChar, "char is %d", wParam);
        MessageBoxA(hwnd, szChar, "weixin", 0);
        break;
    case WM_LBUTTONDOWN:
        MessageBox(hwnd, _T("mose clicked"), _T("weixin"), 0);
        HDC hdc;
        hdc = GetDC(hwnd);
        TextOut(hdc, 0, 50, _T("天佑中华"), strlen("天佑中华"));
        ReleaseDC(hwnd, hdc);

        break;
    case WM_PAINT:
        HDC hdc1;
        PAINTSTRUCT ps;
        hdc1 = BeginPaint(hwnd, &ps);
        TextOut(hdc1, 0, 0, _T("测试实例一二三四"), strlen("测试实例一二三四"));
        EndPaint(hwnd, &ps);
        break;
    case WM_CLOSE:
        if (IDYES == MessageBox(hwnd, _T("是否真的结束"), _T("weixin"), MB_YESNO))
        {
            DestroyWindow(hwnd);
        }
        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hwnd, uMsg, wParam, lParam);
    }
    return 0;
}


错误    LNK2019    无法解析的外部符号 _main,函数 "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ) 中引用了该符号    ConsoleApplication2    
错误    LNK1120    1 个无法解析的外部命令    
 

  • 写回答

2条回答 默认 最新

  • SoftwareTeacher 《编程之美》作者 2020-12-28 09:33
    关注
    评论

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮