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 #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();
}
Comments
: 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 .
:
[blue]sounds like your computer was infected by gremlins :-) The error message means you created a console program, not a windows program. Create a new windows program and copy your code into it.[/blue]
: : 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 .
: :
: [blue]sounds like your computer was infected by gremlins :-) The error message means you created a console program, not a windows program. Create a new windows program and copy your code into it.[/blue]
:
:
: [red]
Thanks for the reply , You suggestion is really convincing , and I cannot think of any other reason .
But I positively remember that i creates this project as a win32 applicatiion , and did the coding in source file within the same application. Console application was a sperate selection , and I did not touch it during initialization / creation of the project . I cannot understand , how a win32 application could autmatically change to console application .
But the fact is that it has happened.
Now please guide me.
Do I have to create the program again in win32 application . All my efforts of yesterday ahve been wasted ? Do I have some procedure to convert Console application into win32 application.
I feel highly disappointed , that all efforts gone waste every time i shut down the system.
Please let me know if something can be done.
An other piont that I have noted , and might be of some clue .
There are 7 files in the project now. C++ Source file created , and other six were created during compiling/ building. the dot exe file is not there . Once the system also informed , " dot exe file is not available , do you want it to be created ? " . I clicked " Yesd" , but it did not develop. and the fault remains , as it is.
Best regards.
ahs.
[/red]
Another suggestion: Look in the Project Settings --> Link tab --> Project Options list box. win32 programs contains [b][blue]/subsystem:windows[/blue][/b] If yours does not then add it.