Question

OK so here is my source code this is from a tutorial i found online in creating your first DX window. so i copied it by typing it out to try and remember better. Anyways the problem i am having is that I cannot get the program to build in VS, I have tried changing the Linker subsystem to windows, didnt work.

ERROR Recieved

1>MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup
1>e:\documents\visual studio 2013\Projects\Project1\Debug\Project1.exe : fatal error LNK1120: 1 unresolved externals

Heres external link to code https://gist.github.com/bANNji/24ebedaf5a72f2003d29

//include the basic windows header files and the Direct3dD Header file
#include <windows.h>
#include <windowsx.h>
#include <d3d9.h>

// Include the DIrect3D library file
#pragma comment (lib, "d3d9.lib")

// global declarations
LPDIRECT3D9 d3d;    // The pointer to our Direct3D Interface
LPDIRECT3DDEVICE9 d3ddev;   // the pointer to the device class

// functiuon prototypes
void initD3D(HWND hWnd);    // Sets up and initializes Direct3D
void render_frame(void);    // Renders a single frame
void cleanD3D(void);        // Closes Direct3D and releases memory

// The window proc function prototype
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);

// this function initializes and prepares direct3d for use
void initD3D(HWND hWnd)
{
    d3d = Direct3DCreate9(D3D_SDK_VERSION);     // Create the Direct3D Interface
    D3DPRESENT_PARAMETERS d3dpp;    // create a stuct to hold verious device information
    ZeroMemory(&d3dpp, sizeof(d3dpp));      //Clear out the stuct for usee
    d3dpp.Windowed = TRUE;      // Program windowed not full screen
    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;   // Discard old frames
    d3dpp.hDeviceWindow = hWnd;     // Set the window to be used by Direct3D

    // Create a deviced calss using this information and information from the d3dpp stuct
    d3d->CreateDevice(D3DADAPTER_DEFAULT,
        D3DDEVTYPE_HAL,
        hWnd,
        D3DCREATE_SOFTWARE_VERTEXPROCESSING,
        &d3dpp,
        &d3ddev);
}

// THE FUN STUFF

// this is the function used to render a single frame
void render_frame(void)
{
    // clear the window to a deep blue
    d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 40, 100), 1.0f, 0);

    d3ddev->BeginScene();       // this begins the 3D Scene

    // do  3D Rendering on the back buffer here...

    d3ddev->EndScene();         // ends the 3D Scene

    d3ddev->Present(NULL, NULL, NULL, NULL);        // This displays the created frame
}

// THis is the function that cleans up Direct3D and COM
void cleanD3D(void)
{
    d3ddev->Release();      // close and release the 3D Device
    d3d->Release();     //Close and release Direct3D
}
Was it helpful?

Solution

The error means exactly what it says: You don't have a WinMain. I would strongly suggest you first learn how to wield the Win32 API to create and manipulate windows by themselves before you try to use them with Direct3D. It is heavily documented on MSDN and pretty easy to grasp. Here's a quick jumble of sample code (incomplete, obviously) to help give you a reference point to get started:

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    HRESULT hr = CoInitializeEx(NULL,COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);

    WNDCLASSEX wndClass;
    ZeroMemory(&wndClass,sizeof(wndClass));
    wndClass.cbSize         = sizeof(wndClass);
    wndClass.cbClsExtra     = 0;
    wndClass.cbWndExtra     = 0;
    wndClass.hbrBackground  = NULL;
    wndClass.hCursor        = LoadCursor(hInstance,LoadCursor(NULL,IDC_ARROW);
    wndClass.hIcon          = LoadIcon(hInstance,LoadIcon(NULL,IDI_APPLICATION);
    wndClass.hIconSm        = LoadIcon(hInstance,LoadIcon(NULL,IDI_APPLICATION);
    wndClass.hInstance      = hInstance;
    wndClass.lpszMenuName   = NULL;
    wndClass.lpfnWndProc    = winProc;
    wndClass.lpszClassName  = "derp";
    wndClass.style          = CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
    RegisterClassEx(&wndClass);

    RECT win = {0,0,width,height};
    AdjustWindowRectEx(&win,flags,FALSE,WS_EX_APPWINDOW);
    int winWidth = win.right - win.left;
    int winHeight = win.bottom - win.top;

    hWnd = CreateWindowEx(  WS_EX_APPWINDOW,
        "derp",
        "derpderp",
        flags | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
        GetSystemMetrics(SM_CXSCREEN)/2 - width/2,
        GetSystemMetrics(SM_CYSCREEN)/2 - height/2,
        winWidth,
        winHeight,
        HWND_DESKTOP,
        NULL,
        hInstance,
        NULL
        );

    SetWindowPos(   hWnd,
        HWND_NOTOPMOST,
        (GetSystemMetrics(SM_CXSCREEN)/2) - (winWidth/2),
        (GetSystemMetrics(SM_CYSCREEN)/2) - (winHeight/2),
        winWidth,
        winHeight,
        SWP_SHOWWINDOW
        );

    ShowWindow(hWnd,nCmdShow);
    UpdateWindow(hWnd);

/* Do your other stuff here */

    return 0;
}

And the winproc definition:

LRESULT CALLBACK App::WinProc( HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam )
{
    switch(uMsg)
    {
// NOTE: Obviously you'd need only those that matter to you, and you'd need to fill them in
    case WM_KEYUP:
    case WM_KEYDOWN:
    case WM_CHAR:
    case WM_LBUTTONDOWN:
    case WM_LBUTTONUP:
    case WM_LBUTTONDBLCLK:
    case WM_RBUTTONDOWN:
    case WM_RBUTTONDBLCLK:
    case WM_RBUTTONUP:
    case WM_MOUSEMOVE:
    case WM_SYSKEYDOWN:
    case WM_MOUSEWHEEL:
    case WM_ACTIVATE:
    case WM_SYSKEYUP:
    case WM_SYSCOMMAND:
    case WM_CREATE:
    case WM_CLOSE:
    case WM_DESTROY:
        App::GetInstance()->Shutdown();
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hWnd,uMsg,wParam,lParam);
    }

    return 0;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top