简体   繁体   中英

Linker error in c program

I am trying to code c program that uses Win32 api to display message box, but i am getting this linker error. How could it be resolved?

code :

#include<windows.h>

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevsInstance,LPSTR SZCmdLine,int iCmdShow)
{
    MessageBox(NULL,TEXT("hello"),TEXT("this is me"),MB_ICONEXCLAMATION |  MB_OK);
   return 0;
}

error:

1>------ Build started: Project: winfirstprog, Configuration: Debug Win32 ------
1>Compiling...
1>winfirstprog.cpp
1>Linking...
1>winfirstprog.obj : error LNK2028: unresolved token (0A000030) "extern "C" int __stdcall MessageBoxW(struct HWND__ *,wchar_t const *,wchar_t const *,unsigned int)" (?MessageBoxW@@$$J216YGHPAUHWND__@@PB_W1I@Z) referenced in function "extern "C" int __cdecl MessageBox(struct HWND__ *,wchar_t const *,wchar_t const *,unsigned int)" (?MessageBox@@$$J0YAHPAUHWND__@@PB_W1I@Z)
1>winfirstprog.obj : error LNK2019: unresolved external symbol "extern "C" int __stdcall MessageBoxW(struct HWND__ *,wchar_t const *,wchar_t const *,unsigned int)" (?MessageBoxW@@$$J216YGHPAUHWND__@@PB_W1I@Z) referenced in function "extern "C" int __cdecl MessageBox(struct HWND__ *,wchar_t const *,wchar_t const *,unsigned int)" (?MessageBox@@$$J0YAHPAUHWND__@@PB_W1I@Z)
1>F:\my_doc\C programming Prog & Documentation\Data structure in c\STARTOVER\winfirstprog\Debug\winfirstprog.exe : fatal error LNK1120: 2 unresolved externals
1>Build log was saved at "file://f:\my_doc\C programming Prog & Documentation\Data structure in c\STARTOVER\winfirstprog\winfirstprog\Debug\BuildLog.htm"
1>winfirstprog - 3 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Getting started with the correct project template is 99% of the Hello World problems. You didn't, this code got compiled by the C++/CLI compiler. File + New Project and select the Win32 + Win32 Project template. – Hans Passant

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM