0

我打算创建一个窗口并初始化 Direct9,但我发现 VS2010 表明DX_Init()函数访问冲突,我很困惑哪里出错了。

#include <Windows.h>
#include <d3dx9.h>
#include <sstream>
#include <string>
#include "D3D9.h"

#define memclear(var) \ memset(&wndClassData, 0x00, sizeof(var));

WNDCLASSEX wndClassData;

LRESULT CALLBACK MainWindowProc(HWND hWnd,UINT uMsg,WPARAM wParam, LPARAM lParam)
{
    switch(uMsg){
        case WM_DESTROY:
            PostQuitMessage(0);
        default:
            return DefWindowProc(hWnd,uMsg,wParam,lParam);
    }

    return 0;
}

struct DXGlobals{
    IDirect3D9  *pD3D;
    IDirect3DDevice9 *pDevice;
};

DXGlobals gDX;

//我在这部分有一些问题

void DX_Init(HWND hWnd)
{
    gDX.pD3D = Direct3DCreate9(D3D_SDK_VERSION);

    D3DPRESENT_PARAMETERS d3dpp;
    memclear(d3dpp);
    d3dpp.Windowed = TRUE;
    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;

    HRESULT hr = gDX.pD3D->CreateDevice(
        D3DADAPTER_DEFAULT,
        D3DDEVTYPE_HAL,
        hWnd,
        D3DCREATE_HARDWARE_VERTEXPROCESSING,
        &d3dpp,
        &gDX.pDevice
        );
}

//问题到此结束

void DX_Update(){
}

void DX_Dispose(){
    gDX.pD3D->Release();
    gDX.pDevice->Release();
}

int CALLBACK WinMain(
    HINSTANCE hInstance,  
    HINSTANCE hPrevInstance,
    LPSTR lpCmdLine, 
    int nCmdShow)
{
    //WNDCLASSEX wndClassData;

    memclear(wndClassData);

    wndClassData.cbSize = sizeof(WNDCLASSEX);
    wndClassData.lpfnWndProc = MainWindowProc;
    wndClassData.hInstance = hInstance;
    wndClassData.hCursor = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW));
    wndClassData.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    wndClassData.lpszClassName="ColourMatchingWindow";
    //memset(&wndClassData, 0x00, sizeof(wndClassData));


    ATOM wndClass = RegisterClassEx(&wndClassData);

    HWND mainWnd = CreateWindow(
        (LPCSTR)wndClass,
        "ColourMatching",
        WS_OVERLAPPEDWINDOW|WS_VISIBLE,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        NULL,
        NULL,
        hInstance,
        NULL);

    DX_Init(mainWnd);
    MSG msg;

    for(;;){
        while(PeekMessage(&msg, NULL,0,0,PM_REMOVE))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }

        if(msg.message==WM_QUIT){
            break;
        }

        DX_Update();

    }

    DX_Dispose();

return 0;
}
}
4

1 回答 1

1

这看起来不对

#define memclear(var) \
    memset(&wndClassData, 0x00, sizeof(var));

D3DPRESENT_PARAMETERS d3dpp;
memclear(d3dpp);

可能你的意思是宏看起来像这样

#define memclear(var) \
    memset(&var, 0x00, sizeof(var));

但实际上你不应该使用无意义的宏。只写简单明了的代码,不要写更复杂晦涩的代码。像这样

D3DPRESENT_PARAMETERS d3dpp;
memset(&d3dpp, 0x00, sizeof d3dpp);
于 2013-08-24T08:42:50.193 回答