Share via


error LNK2019: unresolved external symbol __imp_MessageBoxA referenced in function WinMain

Question

Sunday, April 28, 2019 6:57 AM

#include <stdio.h>
#include <windows.h>

#define winmain(p1,p2,p3,p4)   \
int WINAPI WinMain (HINSTANCE p1, HINSTANCE p2, PSTR p3, int p4)

int a;
int b;

//winmain(p1,p2,p3,p4)

int WINAPI WinMain (HINSTANCE p1, HINSTANCE p2, PSTR p3, int p4)
{

printf("om");

MessageBox(NULL,TEXT("Om"),TEXT("Krim"),0);

return  0;
}

All replies (3)

Sunday, April 28, 2019 8:51 AM

Which compiler are you using? Which version? 

How are you building this? In an IDE? From the command line? 

Did you create a project using one of the project templates in Visual Studio?
If so, which one?

Since the message you show refers to MessageBoxA it suggests that Unicode is
not enabled for the build, which further suggests that you did not use a
project template in one of the recent versions of Visual Studio as they
default to Unicode enabled.

When you use an appropriate template in the IDE then the proper settings are
used in the build to specify which *.lib files to use as well as where to
find them.

Give us answers to the above questions and we may be able to give you directions
on how best to proceed.

  • Wayne

Sunday, April 28, 2019 4:06 PM

The documentation for these functions tells you what you need to link against in order to resolve the reference.

The requirements section of the documentation states which header to include, which import library to link against and what DLL to use if you want to runtime dynamically link.

The requirements state that library is User32.lib, this means you must link against User32.lib to resolve __imp_MessageBoxA.

This is a signature. Any samples given are not meant to have error checking or show best practices. They are meant to just illustrate a point. I may also give inefficient code or introduce some problems to discourage copy/paste coding. This is because the major point of my posts is to aid in the learning process.


Tuesday, May 7, 2019 7:43 AM

Hello,

Have you got any updates? If your case has been solved, please help to mark answers. If not, just feel free to contact us.

Your understanding and cooperation will be grateful.

Best Wishes,

Jack Zhang

MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.