Hello,
I'm learning WinAPI and I can't run the code from tutorial. There is this link error:
Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/main.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
main.exe - 2 error(s), 0 warning(s)
the code is as follows
#include <windows.h>
#define _MainClassName TEXT("WinAPIMainClass")
#define _AppName TEXT("We learn WinAPI")
HINSTANCE g_hInstance;
HWND g_hwndMain;
LRESULT CALLBACK WindowProcMain(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch ( message )
{
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProc(hwnd, message, wParam, lParam);
}
BOOL InitApp()
{
WNDCLASSEX wc;
wc.cbSize = sizeof(WNDCLASSEX);
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
wc.hInstance = g_hInstance;
wc.lpfnWndProc = WindowProcMain;
wc.lpszClassName = _MainClassName;
wc.lpszMenuName = NULL;
wc.style = CS_HREDRAW | CS_VREDRAW;
if ( !RegisterClassEx(&wc) )
return FALSE;
g_hwndMain = CreateWindowEx(0, _MainClassName,
_AppName,
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
100, 100, 450, 350,
NULL, NULL, g_hInstance, NULL);
if ( g_hwndMain == NULL )
return FALSE;
return TRUE;
}
MSG msg;
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nShow)
{
if ( !InitApp() )
return FALSE;
g_hInstance = hInstance;
while ( GetMessage(&msg, NULL, 0, 0) )
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
thanks for answer
Start Free Trial