Link to home
Start Free TrialLog in
Avatar of prinx
prinx

asked on

Error: Unresolved external '_main' referenced from C:\BORLAND\C++\LIB\C0X32.OBJ

i tried to compile the code below :

#include <windows.h>

LRESULT WINAPI MainWndProc( HWND, UINT, WPARAM, LPARAM );

HANDLE ghInstance;

int PASCAL WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow )

{

WNDCLASS wc;
MSG msg;
HWND hWnd;

if( !hPrevInstance ) {
 wc.lpszClassName = "GenericAppClass";
wc.lpfnWndProc = MainWndProc;
wc.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
wc.hCursor = LoadCursor( NULL, IDC_ARROW );
wc.hbrBackground = (HBRUSH)( COLOR_WINDOW+1 );
wc.lpszMenuName = NULL;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0; RegisterClass( &wc );
}

ghInstance = hInstance;

hWnd = CreateWindow( "GenericAppClass", "Generic Application", WS_OVERLAPPEDWINDOW|WS_HSCROLL|WS_VSCROLL, 0, 0, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL );

ShowWindow( hWnd, nCmdShow );
while( GetMessage( &msg, NULL, 0, 0 ) ) {
TranslateMessage( &msg ); DispatchMessage( &msg );
}
return msg.wParam;

}
LRESULT CALLBACK MainWndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
switch( msg ) {
case WM_DESTROY: PostQuitMessage( 0 ); break;
default: return( DefWindowProc( hWnd, msg, wParam, lParam ));
 }
 return 0;
 }


and it generates an error on my borland c++ compiler
"
Error: Unresolved external '_main' referenced from C:\BORLAND\C++\LIB\C0X32.OBJ"
is this something wrong wif the compiler or the code ?

and another thing is..can someone explain to me y "
ghInstance = hInstance;" is declared ?
i was referin to this example "http://msdn.microsoft.com/library/psdk/buildapp/generic_8038.htm" when i did the code above

thanx alot
Avatar of MichaelS
MichaelS

Check you preprocess definition in compiler. I think you have it wrong. How did you created your project?
You probably running console application. So you need:
1. create new win32 project (not console)
OR
2. change the compiler instruction:
  entry point (/ENTRY) to WinMainCRTStartup
  subsystem (/SUBSYSTEM) to winmain

check MSDN for mor detail

--EC--
Avatar of prinx

ASKER

hmmm..i jus found out to use -tW at the comand line to create windows app

so e 1st error msg prob is solved.

and another thing is..can someone explain to me y "
ghInstance = hInstance;" is declared ?
i was referin to this example "http://msdn.microsoft.com/library/psdk/buildapp/generic_8038.htm" when i did the code above
ASKER CERTIFIED SOLUTION
Avatar of nietod
nietod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
...what nietod said.

As per custom, when a variable is prefixed with a lower case 'g', the intent is to inform the reader that the variable is in the global scope.
Strange question :(
I think it was elcaptian that really answered the question.