Linker error in WINAPI code

I am trying to compile the following code but getting linker errors. Thank you for telling me what I am missing.

#include <Windows.h> #pragma comment(lib,"user32.dll") int main() { return MessageBoxA(0,"Message","Warn",0x01); } 

fatal error LNK1104: cannot open file 'user32.dll'

+4
source share
1 answer

Since the LIB file is used to link to the DLL at compile time, MessageBoxA is located in user32.dll and requires the user32.lib to be bound correctly.
So change user32.dll to user32.lib in #pragma comment as

#pragma comment(lib,"user32.lib")

+4
source

All Articles