CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12

Threaded View

  1. #7
    Join Date
    Feb 2010
    Posts
    11

    Re: Difficulty Compiling Resource files (.rc, .h, and .res) in Visual C++

    Well, now I am really getting frustrated! I can't even get my program to compile now!!! I just wanted to learn a bit about Microsoft Programming, and it seems like no matter how much time I spend trying to fix this problem, things get worse!!!

    To me, I really don't mind what compiler I use - I just want to be able to easily code my program and run it. Maybe it's my inexperience in using compilers that is leading to so such frustration, or maybe I just haven't set a simple option. Regardless, please allow me to go back a few steps and see if I can get assistance getting my simple program running on Visual C++ 6.0, which allows for resource editing. After that, I'd like to approach the real problem at hand (trying to get my resources to compile correctly)! Please note that I have no problem getting this project to work (without the resources) on Visual C++ 2008 Express Edition, just on Visual C++6.0 Standard Edition.

    Steps I do:

    1.) File > New > Projects > Win32 Console Application
    Project Name is "WindowsPractice"

    2.) Click on "File View" (not from the upper menu), right click on the main project, and left click on "Add Files to Project..."

    3.) I add the file "main.cpp" from my desktop.
    This file contains the following code (which only displays two, empty white windows):



    Code:
    #define WIN32_LEAN_AND_MEAN
    
    #include <windows.h> //windows headers
    #include <windowsx.h> //macros
    #include <stdio.h>
    #include <math.h>
    
    #define WINDOW_CLASS_NAME "MYCLASS"
    
    //my super awesome message handler
    LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
    {
    	PAINTSTRUCT ps;
    	HDC hdc;
    	switch(msg)
    	{
    	case WM_CREATE:
    		{
    			return(0);
    		}
    		break;
    
    	case WM_PAINT:
    		{
    			hdc = BeginPaint(hwnd, &ps);
    			EndPaint(hwnd, &ps);
    			return(0);
    		}
    		break;
    
    	case WM_DESTROY:
    		{
    			PostQuitMessage(0);
    			return(0);
    		}
    		break;
    
    	default:break;
    	}
    
    	//let Windows handle the rest
    	return (DefWindowProc(hwnd, msg, wparam, lparam));
    
    }//WinProc is over
    
    //WINMAIN - consider this your main loop
    int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline, int ncmdshow)
    {
    	WNDCLASSEX winclass; //holds the class we create
    	HWND hwnd; //generic window handle
    	MSG msg; //generic message
    
    	//first we have to define what our structure will be
    	winclass.cbSize = sizeof(WNDCLASSEX);
    	winclass.style = CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
    	winclass.lpfnWndProc = WindowProc; //how the messages are handled
    	winclass.cbClsExtra = 0;
    	winclass.cbWndExtra = 0;
    	winclass.hInstance = hinstance;
    	winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    	winclass.hCursor = LoadCursor(hinstance, IDC_ARROW);
    	winclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
    	winclass.lpszMenuName = NULL;
    	winclass.lpszClassName = WINDOW_CLASS_NAME;
    	winclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
    
    	//register this class now
    	if (!RegisterClassEx(&winclass))
    		return(0);
    
    	//----------------------------------------------------------------------
    	//create the window time!!!
    	if (!(hwnd = CreateWindowEx(NULL, WINDOW_CLASS_NAME, "My first window!",
    		WS_OVERLAPPEDWINDOW | WS_VISIBLE,
    		0,0, //inital x and y
    		400,400, //initial width, height
    		NULL,
    		NULL,
    		hinstance,//histance of application
    		NULL)))
    		return(0);
    
    	//----------------------------------------------------------------------
    	//let's create a second window
    	if (!(hwnd = CreateWindowEx(NULL, WINDOW_CLASS_NAME, "Here is a second window!!!",
    		WS_OVERLAPPEDWINDOW | WS_VISIBLE,
    		0,0,
    		600,800,
    		NULL,
    		NULL,
    		hinstance,
    		NULL)))
    		return(0);
    
    
    	//main event loop time
    	while(GetMessage(&msg, NULL, 0,0))
    	{
    		TranslateMessage(&msg);
    		DispatchMessage(&msg);
    	}
    
    	//return to basic Windows
    	return(msg.wParam);
    }
    I hit "Control + F7" to compile it (0 errors and 0 warnings).
    Then, I hit "Control + F5" to run it, and I get this error:


    --------------------Configuration: WindowsPractice - Win32 Debug--------------------
    Linking...
    LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
    Debug/WindowsPractice.exe : fatal error LNK1120: 1 unresolved externals
    Error executing link.exe.

    Windows7.exe - 2 error(s), 0 warning(s)


    Why am I able to compile this program so easily on the express edition, yet not at all on the 6.0 edition? Perhaps if I can resolve this issue, it may take care of my resource problem as well!

    [ Added by ovidiucucu ]
    Please place source code between [CODE] tags!
    See BB Code List.
    Last edited by ovidiucucu; February 4th, 2010 at 02:07 AM. Reason: Added [CODE] tags for source code

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured