我无法让我的d3d窗口在VS 2013中构建

时间:2014-05-08 00:04:58

标签: visual-c++ visual-studio-2013 directx build-error

好的,所以这是我的源代码,这是我在线创建你的第一个DX窗口的教程。所以我通过输入来复制它,试着更好地记住。无论如何我遇到的问题是我无法在VS中构建程序,我已经尝试将链接器子系统更改为Windows,没有用。

收到错误

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

代表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
}

1 个答案:

答案 0 :(得分:1)

错误意味着它的内容:你没有WinMain。我强烈建议您首先学习如何在尝试将它们与Direct3D一起使用之前,使用Win32 API自行创建和操作Windows。它在MSDN上有大量文档,非常容易掌握。这是一个快速混乱的示例代码(显然不完整),以帮助您提供入门参考点:

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;
}

winproc定义:

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;
}