D3D10CreateDeviceAndSwapChain()总是因DXGI_ERROR_INVALID_CALL而失败

时间:2012-01-31 14:10:54

标签: c++ winapi directx

我正在创建一个隐藏窗口,我正在寻找指向IDXGISwapChain::Present()的指针。问题是我无法获得有效的Direct3D10设备,也无法获得有效的交换链。

HWND hwnd = CreateWindow(TEXT("flhiSTATIC"), TEXT("flh DXGI Window"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 640, 480, 0, NULL, NULL, 0);
DXGI_SWAP_CHAIN_DESC scd;
ZeroMemory(&scd, sizeof(scd));

scd.BufferCount = 2;
RECT rcWnd;
GetClientRect(hwnd, &rcWnd);

scd.BufferDesc.Width = rcWnd.right - rcWnd.left;
scd.BufferDesc.Height = rcWnd.bottom - rcWnd.top;
scd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; // also tried DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
scd.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
scd.BufferDesc.Scaling = DXGI_MODE_SCALING_CENTERED;
scd.BufferDesc.RefreshRate.Numerator = 60;
scd.BufferDesc.RefreshRate.Denominator = 1;
scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
scd.OutputWindow = hwnd;
scd.SampleDesc.Count = 1;
scd.SampleDesc.Quality = 0;
scd.Windowed = TRUE;
scd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;

pD3D10CreateDeviceAndSwapChain = reinterpret_cast<D3D10CREATEDEVICEANDSWAPCHAIN_PROC *>(GetProcAddress(d3d10, "D3D10CreateDeviceAndSwapChain"));

HRESULT hr = pD3D10CreateDeviceAndSwapChain(NULL /*pAdapter*/, D3D10_DRIVER_TYPE_HARDWARE, NULL, D3D10_CREATE_DEVICE_DEBUG, D3D10_SDK_VERSION, &scd, &pSwapChain, &pDev);
// this guy always fails with 0 in both pSwapChain and pDev...

知道上面的代码可能有什么问题吗?

1 个答案:

答案 0 :(得分:-1)

我完全忘记了创建或分配预先存在的窗口类的需要:(

那是问题所在;经验教训 - 始终检查所有通话的返回代码。

修改

我完全忘了使用有效窗口类调用CreateWindow,该窗口类是我之前注册的窗口类,或者是当前模块中某人注册的窗口类