Basic Window application Help

This is a discussion on Basic Window application Help within the Windows Programming forums, part of the Platform Specific Boards category; I basically just want to create a window.. however I keep getting a, " Error: Unresolved external '_main' referenced from ...

  1. #1
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903

    Basic Window application Help

    I basically just want to create a window.. however I keep getting a, " Error: Unresolved external '_main' referenced from C:\BORLAND\BCC55\LIB\C0X32.OBJ " error.. I am not sure what I am doing wrong.. any advice would be much appreciated

    Code:
     #include<windows.h>
    
    LRESULT CALLBACK WndProc(HWND hWindow, UINT msg, WPARAM wParam, LPARAM lParam);
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
    {
        static TCHAR    szAppName[]=TEXT("Skeleton");
        WNDCLASSEX        wndclass;
        HWND            hWindow;
        MSG                msg;
    
        wndclass.cbSize            = sizeof(wndclass);
        wndclass.style            = CS_HREDRAW | CS_VREDRAW;
        wndclass.lpfnWndProc    = WndProc;
        wndclass.cbClsExtra        = 0;
        wndclass.cbWndExtra        = 0;
        wndclass.hInstance        = hInstance;
        wndclass.hIcon            = NULL; 
        wndclass.hIconSm        = NULL; 
        wndclass.hCursor        = LoadCursor(NULL, IDC_ARROW);
        wndclass.hbrBackground    = (HBRUSH)(COLOR_WINDOW + 1);
        wndclass.lpszMenuName    = NULL;
        wndclass.lpszClassName    = szAppName;
    
        if(!RegisterClassEx(&wndclass))
            return 0;
    
        hWindow = CreateWindow(szAppName, szAppName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 
                               CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
    
        ShowWindow(hWindow, iCmdShow);
        UpdateWindow(hWindow);
    
        while(GetMessage(&msg, NULL, 0, 0))
        {
            TranslateMessage(&msg);
            DispatchMessage (&msg);
        }
        return (int)msg.wParam;
     
    }
    
    LRESULT CALLBACK WndProc(HWND hWindow, UINT msg, WPARAM wParam, LPARAM lParam)
    {
        HDC                hDC;
        PAINTSTRUCT        ps;
        RECT            rect;
    
        switch(msg)
        {
            case WM_PAINT:
    
                hDC = BeginPaint(hWindow, &ps);
                GetClientRect(hWindow, &rect);
                DrawText(hDC, TEXT("This is a noob skeleton application!"), -1, &rect,
                         DT_SINGLELINE | DT_CENTER | DT_VCENTER);
                EndPaint(hWindow, &ps);
                return 0;
    
            case WM_DESTROY:
                PostQuitMessage(0);
                return 0;
    
        }
        return DefWindowProc(hWindow, msg, wParam, lParam);
    
    }
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  2. #2
    return 0;
    Join Date
    Jan 2005
    Location
    Netherlands
    Posts
    89
    Well I don't have Borland, but here's what I think might be your problem: in a normal console application, main() is the function that gets executed. In a win32 api program, the function the OS calls is WinMain(). Since you get an error that there is no main(), the compiler probably thinks you're making a normal console app. So you should let it know it has to compile your code as a win32 program. In Dev-C++ for example, I go to Project -> Project options and there I can change the project type from "Win32 Console" to "Win32 GUI"

    [edit]
    I googled and found this, which is what I described above. Hope that takes care of your problem
    [/edit]
    Last edited by Snip; 02-11-2005 at 01:08 PM.

  3. #3
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    Wow.. That was a great find Snip.. I simply used the -W switch when compiling my windows application
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why only 32x32? (OpenGL) [Please help]
    By Queatrix in forum Game Programming
    Replies: 2
    Last Post: 01-23-2006, 01:39 PM
  2. Window scrollbar
    By maxorator in forum Windows Programming
    Replies: 2
    Last Post: 10-07-2005, 12:31 PM
  3. My Window Class
    By Epo in forum Game Programming
    Replies: 2
    Last Post: 07-10-2005, 02:33 PM
  4. problem with open gl engine.
    By gell10 in forum Game Programming
    Replies: 1
    Last Post: 08-21-2003, 04:10 AM
  5. OpenGL and Windows
    By sean345 in forum Game Programming
    Replies: 5
    Last Post: 06-24-2002, 10:14 PM

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