Dear Sir ,
I had been working to write a program in Visual C ++ to show a couple of push buttons on a window space. Putting bits and pieces together , I managed to write the code and Build, compile and execute it. It was satisfying to see , that it worked. Widow with button was displayed. Clicking each button provided the desired message. Program was saved .
However on the next day , when I tried to run it again , it gave an error message. There were 2 errors and no warning.
Quote :
--------Configuration: Assgt3_Sajid - Win32 Debug----------
Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/Assgt3_Sajid.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
Assgt3_Sajid.exe - 2 error(s), 0 warning(s)
UnQuote
I fail to understand , how this error developed. What meaning does it carry and how to rectify. I am sending the error log ( which I have not been able to interpret ) , requesting a solution to this problem. Plz let me know what happened over night , and how to deal with similar problems if they reappear.
Thanking you .
Abdul Hayee .
The Actual code is as under ( for reference )
/* 786 */
/* Assignment : CS 410_3 Q1 */
/* Solution by : bc030490065 */
/* File Name : First.cpp */
#include <windows.h>
#define ID_FIRSTBUTTON 1
#define ID_SECONDBUTTON 2
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
HWND hWindow=NULL;
HWND hButtonFirst=NULL;
HWND hButtonSecond=NULL;
WNDPROC OldButtonFirstProc=NULL;
char captionText[256];
bool OnDestroy()
{
PostQuitMessage(0);
return true;
}
bool OnMaximize(HWND hWnd)
{
char str[512];
lstrcpy(str,captionText);
lstrcat(str,"-Maximized");
SetWindowText(hWnd,str);
return true;
}
bool OnMinimize(HWND hWnd)
{
char str[512];
lstrcpy(str,captionText);
lstrcat(str,"-Minimized");
SetWindowText(hWnd,str);
return true;
}
//---------------------------------------------------
// bool OnRestore(HWND hWnd)
// when applcation to restore
//----------------------------------------------------
bool OnRestore(HWND hWnd)
{
SetWindowText(hWnd,captionText);
return true;
}
LRESULT CALLBACK ButtonFirstProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
{
switch(LOWORD(wParam))
{
case ID_FIRSTBUTTON:
{
MessageBox(hWnd,"First button is Clicked","Virtual University ",MB_ICONINFORMATION);
return 0;
}
}
return CallWindowProc(OldButtonFirstProc,hWnd,message,wParam,lParam);
}
bool OnCreate(HWND hWnd)
{
int bX=50;
int bY=90;
int width=100;int height=30;
//Create the first button
hButtonFirst=CreateWindowEx(0,"Button","Button 1",WS_CHILD|WS_VISIBLE,
bX,bY,width,height,hWnd,(HMENU)ID_FIRSTBUTTON,NULL,NULL);
//Create the second button
bX+=(width*2);
hButtonSecond=CreateWindowEx(0,"Button","Button 2",WS_CHILD|WS_VISIBLE,
bX,bY,width,height,hWnd,(HMENU)ID_SECONDBUTTON,NULL,NULL);
OldButtonFirstProc=(WNDPROC)(__int64)SetWindowLong(hButtonFirst,GWL_WNDPROC,(LONG)(__int64)ButtonFirstProc);
if(OldButtonFirstProc==NULL)
{
return false;
}
return true;
}
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_CREATE:
{
OnCreate(hWnd);
return 0;
}
case WM_SYSCOMMAND:
{
switch(wParam)
{
case SC_MAXIMIZE:
{
OnMaximize(hWnd);
break;
}
case SC_MINIMIZE:
{
OnMinimize(hWnd);
break;
}
case SC_RESTORE:
{
OnRestore(hWnd);
break;
}
}
break;
}
case WM_COMMAND:
{
switch(LOWORD(wParam))
{
case ID_SECONDBUTTON:
{
MessageBox(hWnd,"Button 2 is Clicked","Virtual University ",MB_ICONINFORMATION);
break;
}
case ID_FIRSTBUTTON:
{
MessageBox(hWnd,"Button 1 is Clicked","Virtual University ",MB_ICONINFORMATION);
break;
}
}
return 0;
}
case WM_DESTROY:
{
OnDestroy();
return 0;
}
}
//default message processing
return DefWindowProc(hWnd, message, wParam, lParam);
}
int Run()
{
MSG msg;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam ;
}
bool InitApplication(HINSTANCE hInstance)
{
WNDCLASS wndClass;
char *szClassName = "MainWnd_Class"; //windows class name
wndClass.hbrBackground = (HBRUSH) GetStockObject(GRAY_BRUSH);//Background brush
wndClass.lpszClassName = szClassName; //class name
wndClass.lpfnWndProc = WindowProc; //Window procedure
wndClass.hInstance = hInstance; //handle to application instance
wndClass.hCursor = LoadCursor(NULL, (LPCTSTR)IDC_ARROW); //loading default Arrow style cursor
wndClass.cbClsExtra = 0; //no extra class bytes.
wndClass.cbWndExtra = 0; //no extra window bytes.
wndClass.hIcon = NULL; //window class icon
wndClass.lpszMenuName = NULL; //no menu attached.
wndClass.style = 0; //no class style needed
if(!RegisterClass(&wndClass))
{
MessageBox(NULL,"Application Main class could not be registered","Application Error",MB_ICONHAND);
return 0;
}
lstrcpy(captionText,"AHS_3 ");
hWindow=CreateWindowEx(0,szClassName,captionText,WS_OVERLAPPED|WS_MINIMIZEBOX| WS_CAPTION|WS_SYSMENU|WS_THICKFRAME,
CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,NULL,NULL);
if(hWindow == NULL)
{
return 0;
}
ShowWindow(hWindow,SW_SHOWNORMAL);
UpdateWindow(hWindow);
return true;
}
int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
if(!InitApplication(hInstance))
{
MessageBox(NULL,"Cannot run application","",MB_ICONHAND);
return 0;
}
return Run();
}