Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Visual C++

ABDUL HAYEEABDUL HAYEE Member Posts: 81
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

  • Griz803Griz803 Member Posts: 100
    : 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 .

    I don't see anything dramatically wrong with the code, which it would have to be to complain about the errors you gave. Try double checking the parameters the IDE is passing to the compiler. If this computer is in a position to be used by others, they could've accidently or intentionally changed parameters on your project. This seems to me the likely problem, though I didn't thoroughly desk check the code. I hope this helps you find it.
  • MT2002MT2002 Member Posts: 1,444
    : : 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 .
    :
    : I don't see anything dramatically wrong with the code, which it would have to be to complain about the errors you gave. Try double checking the parameters the IDE is passing to the compiler. If this computer is in a position to be used by others, they could've accidently or intentionally changed parameters on your project. This seems to me the likely problem, though I didn't thoroughly desk check the code. I hope this helps you find it.
    :
    [blue]
    The linker is looking for the _main() routine rather then
    the Win32 WinMain() routine. Because _main isnt defined, your
    linker is complaining.

    I believe you are building it as a [b]counsol[/b] application,
    rather then a [b]Win32[/b] application. Check your settings,
    and [b]make sure[/b] it is set to [b]Win32[/b].

    ~mt2002[/blue]
    [hr][italic]"There are ten kinds of people in the world--Those who speak binary, and those who dont!"[/italic]

  • ABDUL HAYEEABDUL HAYEE Member Posts: 81
    : : : 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 .
    : :
    : : I don't see anything dramatically wrong with the code, which it would have to be to complain about the errors you gave. Try double checking the parameters the IDE is passing to the compiler. If this computer is in a position to be used by others, they could've accidently or intentionally changed parameters on your project. This seems to me the likely problem, though I didn't thoroughly desk check the code. I hope this helps you find it.
    : :
    : [blue]
    : The linker is looking for the _main() routine rather then
    : the Win32 WinMain() routine. Because _main isnt defined, your
    : linker is complaining.
    :
    : I believe you are building it as a [b]counsol[/b] application,
    : rather then a [b]Win32[/b] application. Check your settings,
    : and [b]make sure[/b] it is set to [b]Win32[/b].
    :
    : ~mt2002[/blue]
    : [hr][italic]"There are ten kinds of people in the world--Those who speak binary, and those who dont!"[/italic]
    :
    :


    : [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]


  • AsmGuru62AsmGuru62 Member Posts: 6,519
    [blue]Why do you ned to recreate the whole thing as Win32? Simply create an empty Win32 project and add the source file to it. What version of Visual C++ do you have?[/blue]
  • stoberstober Member Posts: 9,765 ✭✭✭
    The quickest way to solve your problem is to simply create a new win32 windows program then copy the source files (*.cpp and *.h) from your original progam into this new program, finally add the new files to the project using menu Project --> Add To Project --> Files.

    Another suggestion: Look in the Project Settings --> Link tab --> Project Options list box. win32 programs contains /subsystem:windows If yours does not then add it.

  • ABDUL HAYEEABDUL HAYEE Member Posts: 81
    : The quickest way to solve your problem is to simply create a new win32 windows program then copy the source files (*.cpp and *.h) from your original progam into this new program, finally add the new files to the project using menu Project --> Add To Project --> Files.
    :
    : Another suggestion: Look in the Project Settings --> Link tab --> Project Options list box. win32 programs contains /subsystem:windows If yours does not then add it.
    :
    :
    Dear Sirs ,
    I am thankful to both of you . The help really worked. Now I make an empty project and add the source file to it. It works fine.
    Thanks again.
    ah.
Sign In or Register to comment.