[resolved] VC++ 2005 Link errors with win32api code
I'm experimenting with a managed VC++ 2005 app to call win32api. I put #include <windows.h> in stdafx.h and call the api function from the global namespace:
Code:
HWND hWnd = (HWND)this->Handle.ToPointer();
::MessageBox(hWnd, L"testing win32api", L"", 0);
The link errors are:
Code:
Error 1 error LNK2028: unresolved token (0A00000E) "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 __clrcall MessageBox(struct HWND__ *,wchar_t const *,wchar_t const *,unsigned int)" (?MessageBox@@$$J0YMHPAUHWND__@@PB_W1I@Z) MyApp.obj
Error 2 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 __clrcall MessageBox(struct HWND__ *,wchar_t const *,wchar_t const *,unsigned int)" (?MessageBox@@$$J0YMHPAUHWND__@@PB_W1I@Z) MyApp.obj
I'm sure it's something simple I'm overlooking.
Re: VC++ 2005 Link errors with win32api code
Seems like you're not linking against the Windows libraries. Add user32.lib to your library list.
Re: VC++ 2005 Link errors with win32api code
Quote:
Originally Posted by CornedBee
Seems like you're not linking against the Windows libraries. Add user32.lib to your library list.
Additional Dependencies in the Linker was set to "$(NOINHERIT)"
Checking 'Inherit from parent or project defaults' imports all of the default Windows libs.