簡體   English   中英

使用 winmain 和簡單代碼編譯錯誤,“WinMain 的先前聲明”

[英]Compile error with winmain and simple code, “Previous decleration of WinMain”

#include <stdio.h> 
#include <windows.h>
int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
    return(0);
}

我是 C 的新手。 當我嘗試編譯時,上面的代碼返回以下錯誤:

main.c:3:5: error: conflicting types for 'WinMain'
 int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
     ^~~~~~~
In file included from c:\mingw\include\windows.h:44:0,
                 from main.c:2:
c:\mingw\include\winbase.h:1263:14: note: previous declaration of 'WinMain' was here
 int APIENTRY WinMain (HINSTANCE, HINSTANCE, LPSTR, int);

您應該使 function 定義與庫的聲明相匹配。 你有

int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)

這需要

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)

它缺少APIENTRY

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM