0

我看到另一个帖子解决了这个问题,但是提问者显然包括winnt.h而不是windows.h(据说包括winnt.h

我正在使用windows.h但仍然遇到这个问题。

我试过使用 Visual Studio 2010 Express 和 Ultimate 并且都产生这个错误。

有没有人遇到过这个?

这是代码:

#include<Windows.h>
#include<d3d9.h>
#include<time.h>
#include<d3dx.h>

#define APPTITLE "Create Surface"

#define KEY_DOWN(vk_code)((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
#define KEY_UP(vk_code)((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)

#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 480

LRESULT WINAPI WinProc(HWND, UINT, WPARAM, LPARAM);
ATOM MyRegisterClass(HINSTANCE);
int Game_Init(HWND);
void Game_Run(HWND);
void Game_End(HWND);

LPDIRECT3D9 d3d = NULL;
LPDIRECT3DDEVICE9 d3ddev = NULL;

LPDIRECT3DSURFACE9 backbuffer = NULL, surface = NULL;

LRESULT WINAPI WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam){
    switch(msg){
    case WM_DESTROY:
        Game_End(hWnd);
        PostQuitMessage(0);
        return 0;
    }
    return DefWindowProc(hWnd, msg, wParam, lParam);
}

ATOM MyRegisterClass(HINSTANCE hInstance){
    WNDCLASSEX wc;
    wc.cbSize = sizeof(WNDCLASSEX);

    wc.style = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc = (WNDPROC)WinProc;
    wc.cbWndExtra = 0;
    wc.cbClsExtra = 0;
    wc.hInstance = hInstance;
    wc.hIcon = NULL;
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
    wc.lpszMenuName = NULL;
    wc.lpszClassName = APPTITLE;
    wc.hIconSm = NULL;

    return RegisterClassEx(&wc);
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){
    MSG msg;

    MyRegisterClass(hInstance);

    HWND hWnd;

    hWnd = CreateWindow(
        APPTITLE,
        APPTITLE,
        WS_EX_TOPMOST | WS_VISIBLE | WS_POPUP,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        SCREEN_WIDTH,
        SCREEN_HEIGHT,
        NULL,
        NULL,
        hInstance,
        NULL);

    if(!hWnd)
        return FALSE;

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

    if(!Game_Init(hWnd))
        return 0;

    int done = 0;
    while(!done){
        if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)){
            if(msg.message == WM_QUIT)
                done = 1;
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
        else
            Game_Run(hWnd);
    }
    return msg.wParam;
}

int Game_Init(HWND hWnd){
    HRESULT result;

    d3d = Direct3DCreate9(D3D_SDK_VERSION);
    if(d3d == NULL){
        MessageBox(hWnd, "Failed to initialise d3d", "Error", MB_OK);
        return 0;
    }

    D3DPRESENT_PARAMETERS d3dpp;
    ZeroMemory(&d3dpp, sizeof(d3dpp));

    d3dpp.Windowed = FALSE;
    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
    d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
    d3dpp.BackBufferCount = 1;
    d3dpp.BackBufferHeight = SCREEN_HEIGHT;
    d3dpp.BackBufferWidth = SCREEN_WIDTH;
    d3dpp.hDeviceWindow = hWnd;

    d3d->CreateDevice(
        D3DADAPTER_DEFAULT,
        D3DDEVTYPE_HAL,
        hWnd,
        D3DCREATE_SOFTWARE_VERTEXPROCESSING,
        &d3dpp,
        &d3ddev);

    if(d3ddev == NULL){
        MessageBox(hWnd, "Failed to initialise Direct3D device", "Error", MB_OK);
        return 0;
    }

    srand(time(NULL));

    d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);

    d3ddev->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);

    result = d3ddev->CreateOffscreenPlainSurface(
        100,
        100,
        D3DFMT_X8R8G8B8,
        D3DPOOL_DEFAULT,
        &surface,
        NULL);

    if(!result)
        return 1;

    return 1;
}

void Game_Run(HWND hWnd){
    RECT rect;
    int r,g,b;

    if(d3ddev == NULL)
        return;

    if(d3ddev->BeginScene()){
        r = rand() % 255;
        g = rand() % 255;
        b = rand() % 255;
        d3ddev->ColorFill(surface, NULL, D3DCOLOR_XRGB(r,g,b));

        rect.left = rand() % SCREEN_WIDTH / 2;
        rect.right = rect.left + rand() % SCREEN_WIDTH / 2;
        rect.top = rand() % SCREEN_HEIGHT;
        rect.bottom = rect.top + rand() % SCREEN_HEIGHT / 2;

        d3ddev->StretchRect(surface, NULL, backbuffer, &rect, D3DTEXF_NONE);

        d3ddev->EndScene();
    }

    d3ddev->Present(NULL, NULL, NULL, NULL);

    if(KEY_DOWN(VK_ESCAPE))
        PostMessage(hWnd, WM_DESTROY, 0, 0);
}

void Game_End(HWND hWnd){
    surface->Release();

    if(d3ddev != NULL)
        d3ddev->Release();

    if(d3d != NULL)
        d3d->Release();
}

还有我上面提到的帖子的链接: 语法错误:缺少';' 编译 winnt.h 时在标识符“PVOID64”之前

4

2 回答 2

2

这是因为VC++包含目录的顺序,尽量把windows SDK的路径放在DirectX SDK之前,如下图。

在此处输入图像描述

于 2012-10-15T11:31:30.113 回答
1

所以我想我在尝试在另一台笔记本电脑上进行排序时偶然发现了一个解决方案。

Windows SDK 似乎安装了一些东西,称为 Windows SDK 配置工具。运行它会检测您安装了哪些版本的 SDK,然后允许您选择要使用的版本。然后,它会配置您必须使用所选版本的所有 Visual Studio 版本。

我认为这解决了这个问题 - 还没有适当的机会进行全面检查 - 我还卸载了所有相关组件的 Visual Studio 版本,并仅重新安装了我需要的那个(暂时 - 以后可能会安装其他版本看看这是否可能导致各种冲突)。

无论如何,只是想我会在这里为发生在这个线程中的任何人留下一个可能的解决方案。

\,,/[>.<]\,,/

于 2012-10-13T08:53:47.870 回答