Having problems with Microsoft's Visual C++ Express

Discussion in 'C++' started by Lief Webster, Jul 25, 2008.

  1. Lief Webster

    Lief Webster New Member

    Oct 16, 2007
    Likes Received:
    Trophy Points:
    I've been starting to work through a tutorial for DirectX that I found on the internet, and it starts by teaching basic windows programming, for which it recommends Visual C++ Standard Edition (2005 or later). So I went to download it and ended up getting Visual C++ Express Edition (2008), which looked like the most up-to-date program on the site. Now I've typed in my first windows program to a source file in a new solution, but when I try to build it, I'm given errors. Here's the program:

    // include the basic windows header file
    #include <windows.h>
    #include <windowsx.h>
    // the WindowProc function prototype
                             UINT message,
                             WPARAM wParam,
                             LPARAM lParam);
    // the entry point for any Windows program
    int WINAPI WinMain(HINSTANCE hInstance,
                       HINSTANCE hPrevInstance,
                       LPSTR lpCmdLine,
                       int nCmdShow)
        // the handle for the window, filled by a function
        HWND hWnd;
        // this struct holds information for the window class
        WNDCLASSEX wc;
        // clear out the window class for use
        ZeroMemory(&wc, sizeof(WNDCLASSEX));
        // fill in the struct with the needed information
        wc.cbSize = sizeof(WNDCLASSEX);
        wc.style = CS_HREDRAW | CS_VREDRAW;
        wc.lpfnWndProc = (WNDPROC)WindowProc;
        wc.hInstance = hInstance;
        wc.hCursor = LoadCursor(NULL, IDC_ARROW);
        wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
        wc.lpszClassName = L"WindowClass1";
        // register the window class
        // create the window and use the result as the handle
        hWnd = CreateWindowEx(NULL,
                              L"WindowClass1",    // name of the window class
                              L"Our First Windowed Program",   // title of the window
                              WS_OVERLAPPEDWINDOW,    // window style
                              300,    // x-position of the window
                              300,    // y-position of the window
                              500,    // width of the window
                              400,    // height of the window
                              NULL,    // we have no parent window, NULL
                              NULL,    // we aren't using menus, NULL
                              hInstance,    // application handle
                              NULL);    // used with multiple windows, NULL
        // display the window on the screen
        ShowWindow(hWnd, nCmdShow);
        // enter the main loop:
        // this struct holds Windows event messages
        MSG msg;
        // wait for the next message in the queue, store the result in 'msg'
        while(GetMessage(&msg, NULL, 0, 0))
            // translate keystroke messages into the right format
            // send the message to the WindowProc function
        // return this part of the WM_QUIT message to Windows
        return msg.wParam;
    // this is the main message handler for the program
    LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
        // sort through and find what code to run for the message given
            // this message is read when the window is closed
            case WM_DESTROY:
                    // close the application entirely
                    return 0;
                } break;
        // Handle any messages the switch statement didn't
        return DefWindowProc (hWnd, message, wParam, lParam);
    This code is word-for-word what the tutorial said to type, but the compiler produces these errors:

    MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
    C:\Documents and Settings\Lauren\My Documents\Visual Studio 2008\Projects\windows1\Debug\windows1.exe : fatal error LNK1120: 1 unresolved externals
    What am I doing wrong?

    (Also, I had at first tried the code on Dev-C++, but it gave me a few errors I couldn't figure out. Does Dev not do Windows programming as well as other compilers?)

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice