NO

Author Topic: WinAPI tutorial program -> POLINK error "unresolved external(s)"  (Read 6161 times)

hanzf

  • Guest
Hello,

I tried a program from this tutorial: http://www.win-api.de/tutorials.php?tutid=3

Code: [Select]
#define STRICT
#include <windows.h>

LRESULT CALLBACK Ereignishandler(HWND, UINT, WPARAM, LPARAM);

const char Programmname[] = "WinAPI Tutorial Kapitel 2";

// später mal probieren, ob es auch mit char * statt char[] klappt

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
HWND hWnd;
MSG msg;
WNDCLASS WndClass;

WndClass.style = CS_HREDRAW | CS_VREDRAW;
WndClass.lpfnWndProc = Ereignishandler;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.hInstance = hInstance;
WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
WndClass.lpszClassName = Programmname;
WndClass.lpszMenuName = 0;

(void)RegisterClass(&WndClass);

hWnd = CreateWindow(
Programmname,
"Fenstertitel",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL
);

(void)ShowWindow(hWnd, iCmdShow);
(void)UpdateWindow(hWnd);

while (GetMessage(&msg, NULL, 0, 0))
{
(void)TranslateMessage(&msg);
(void)DispatchMessage(&msg);
}

return(msg.wParam);
}

LRESULT CALLBACK Ereignishandler(HWND hWnd, UINT uInt, WPARAM wParam, LPARAM lParam)
{
switch(uInt)
{
case WM_DESTROY: { PostQuitMessage(0); return(0); }
}
return(DefWindowProc(hWnd, uInt, wParam, lParam));
}

It compiles with no problems but when trying to build the .exe, POLINK reports 13 unresolved externals:

Code: [Select]
POLINK: error: Unresolved external symbol '__imp__LoadCursorA@8'.
POLINK: error: Unresolved external symbol '__imp__LoadIconA@8'.
POLINK: error: Unresolved external symbol '__imp__GetStockObject@4'.
POLINK: error: Unresolved external symbol '__imp__RegisterClassA@4'.
POLINK: error: Unresolved external symbol '__imp__CreateWindowExA@48'.
POLINK: error: Unresolved external symbol '__imp__ShowWindow@8'.
POLINK: error: Unresolved external symbol '__imp__UpdateWindow@4'.
POLINK: error: Unresolved external symbol '__imp__TranslateMessage@4'.
POLINK: error: Unresolved external symbol '__imp__DispatchMessageA@4'.
POLINK: error: Unresolved external symbol '__imp__GetMessageA@16'.
POLINK: error: Unresolved external symbol '__imp__PostQuitMessage@4'.
POLINK: error: Unresolved external symbol '__imp__DefWindowProcA@16'.
POLINK: error: Unresolved external symbol '_main'.
POLINK: fatal error: 13 unresolved external(s).
*** Error code: 1 ***

Here's what I've tried up to now:

- compiler settings: enabled Microsoft extensions
- compiler settings: changed "calling convention" from "__cdecl" to "__stdcall"
- compiler settings: tried all 3 possibilities for "runtime library"

I found that the linker settings allow to specify "Library an object files" and the given ones are:
"kernel32.lib advapi32.lib delayimp.lib"
but there's so many libs in Pelles C's folders that I don't want to try them all...

What's wrong here?

Hans

Windows XP SP3 - Pelles C 7.00.355 - AMD Athlon 64

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Re: WinAPI tutorial program -> POLINK error "unresolved external(s)"
« Reply #1 on: July 18, 2013, 05:36:58 AM »
What's wrong here?
missing user32.lib from libraries
wrong subsystem type, should be subsystem:window

next time select 'Win32 Program (EXE)' for GUI project.
May the source be with you

hanzf

  • Guest
Re: WinAPI tutorial program -> POLINK error "unresolved external(s)"
« Reply #2 on: July 18, 2013, 01:34:59 PM »
Thank you timovjl, now it works

missing user32.lib from libraries

how can I find this without trying hundreds of libs?

Hans

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Re: WinAPI tutorial program -> POLINK error "unresolved external(s)"
« Reply #3 on: July 19, 2013, 01:30:26 PM »
how can I find this without trying hundreds of libs?
Look function info from MSDN / WSDK help, there is normally header/library info for that.
May the source be with you

hanzf

  • Guest
Re: WinAPI tutorial program -> POLINK error "unresolved external(s)"
« Reply #4 on: July 21, 2013, 09:53:41 PM »
Thank you, that looks useful.