Help! I keep getting this error message.

This is a discussion on Help! I keep getting this error message. within the Windows Programming forums, part of the Platform Specific Boards category; I am just starting Windows programming. Doing so, I decided to copy this tutorial program from a site and examine ...

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    27

    Help! I keep getting this error message.

    I am just starting Windows programming. Doing so, I decided to copy this tutorial program from a site and examine it:

    Code:
    #include <windows.h>
    
    const char *ClsName = "BasicApp";
    const char *WndName = "A Simple Window";
    
    LRESULT CALLBACK WndProcedure(HWND hWnd, UINT uMsg,
    			   WPARAM wParam, LPARAM lParam);
    
    INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine, int nCmdShow)
    {
    	MSG        Msg;
    	HWND       hWnd;
    	WNDCLASSEX WndClsEx;
    
    	// Create the application window
    	WndClsEx.cbSize        = sizeof(WNDCLASSEX);
    	WndClsEx.style         = CS_HREDRAW | CS_VREDRAW;
    	WndClsEx.lpfnWndProc   = WndProcedure;
    	WndClsEx.cbClsExtra    = 0;
    	WndClsEx.cbWndExtra    = 0;
    	WndClsEx.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
    	WndClsEx.hCursor       = LoadCursor(NULL, IDC_ARROW);
    	WndClsEx.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
    	WndClsEx.lpszMenuName  = NULL;
    	WndClsEx.lpszClassName = ClsName;
    	WndClsEx.hInstance     = hInstance;
    	WndClsEx.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);
    
    	// Register the application
    	RegisterClassEx(&WndClsEx);
    
    	// Create the window object
    	hWnd = CreateWindow(ClsName,
    			  WndName,
    			  WS_OVERLAPPEDWINDOW,
    			  CW_USEDEFAULT,
    			  CW_USEDEFAULT,
    			  CW_USEDEFAULT,
    			  CW_USEDEFAULT,
    			  NULL,
    			  NULL,
    			  hInstance,
    			  NULL);
    	
    	// Find out if the window was created
    	if( !hWnd ) // If the window was not created,
    		return 0; // stop the application
    
    	// Display the window to the user
    	ShowWindow(hWnd, SW_SHOWNORMAL);
    	UpdateWindow(hWnd);
    
    	// Decode and treat the messages
    	// as long as the application is running
    	while( GetMessage(&Msg, NULL, 0, 0) )
    	{
                 TranslateMessage(&Msg);
                 DispatchMessage(&Msg);
    	}
    
    	return Msg.wParam;
    }
    
    LRESULT CALLBACK WndProcedure(HWND hWnd, UINT Msg,
    			   WPARAM wParam, LPARAM lParam)
    {
        switch(Msg)
        {
        // If the user wants to close the application
        case WM_DESTROY:
            // then close it
            PostQuitMessage(WM_QUIT);
            break;
        default:
            // Process the left-over messages
            return DefWindowProc(hWnd, Msg, wParam, lParam);
        }
        // If something was not done, let it go
        return 0;
    }
    Anyway, I keep getting this error from my compiler (Borland C++ Compiler 5.5, the free one Borland released.):

    Unresolved external '_main' referenced from C:\BORLAND\BCC55\LIB\COX32.OBJ

    What is causing this and how can I fix this please?

  2. #2
    Registered User
    Join Date
    Nov 2003
    Posts
    161
    For borland set the parameters to compile to win32 or create this function
    Code:
    int main(int arg, char *argv[])
    {
    
    return 0;
    }

  3. #3
    Registered User
    Join Date
    Mar 2004
    Posts
    27
    Added the function, but now WinMain won't execute.

  4. #4
    Registered User
    Join Date
    Mar 2004
    Posts
    27
    Last edited by vulcan_146; 03-06-2004 at 09:37 PM.

  5. #5
    Registered User
    Join Date
    Nov 2003
    Posts
    161
    when you are using borland you are compiling to console aplication and the free version compiles to 16bit mode which will not be able to use api's and that will not work correctly. Iam not an expert in borland nor I don't use or have it. There is another compiler called GCC you can just download dev-cpp and it will give you lots of free tools. here you can find dev-cpp and download it.

    Try calling winmain from main. Look at the manual for borland compiler and try to find something there that will compile to win32 that way you don't need main.

    Hope this helps!

  6. #6
    Registered User
    Join Date
    Mar 2004
    Posts
    27
    I FINALLY GOT IT!
    The command line was -tW. It was just very hard to find that!

  7. #7
    Registered User
    Join Date
    May 2010
    Posts
    11

    Unresolved external '_main' referenced from C:\BORLAND\BCC55\LIB\COX32.OBJ

    Thanks to vulcan_146's post on 03-06-2004 at 08:25 PM about the Unresolved external '_main' referenced from C:\BORLAND\BCC55\LIB\COX32.OBJ. I was able to fix my problem of Borland C++ Complier Error Missing cox32.obj that I posted on 5-3-2010.

    The problem in both cases came from the complier switch settings. Although we were dealing with different switche settings when I cleared the -v (source level debugging switch) the "Unable to open file 'C0X32.OBJ' " went away.

    Again thanks to vulcan_146 for pointing to the source of the problem.

    Bill Agnor
    5-4-2010

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21