我正在尝试使用 DirectX 10 为我的交换链获取渲染目标。出于某种原因,当我添加 GetBuffer 行时,它会吐出错误。这是我的文件:
#include <Windows.h>
#include <stdlib.h>
#include <string.h>
#include <tchar.h>
#include <d3d10.h>
#include <D3DX10.h>
#pragma comment (lib, "d3d10")
//WINDOWS MAIN FUNCTION
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow);
//WINDOW PROCEDURE FUNCTION
//RESPONDS TO EVENTS
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
//Global variables
//The main window class name.
static TCHAR szWindowClass[] = _T("virhackapp");
// The string that appears in the application's title bar.
static TCHAR szTitle[] = _T("VirHack");
HINSTANCE hInst;
//DirectX Vars
DXGI_SWAP_CHAIN_DESC *SwapChain;
IDXGISwapChain **ppSwapChain;
ID3D10Device **device;
void **ppSurface;
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
//LAST THREE ARE OUTPUTS, SEE VARS ABOVE
D3D10CreateDeviceAndSwapChain(NULL,D3D10_DRIVER_TYPE_HARDWARE, NULL, D3D10_SDK_VERSION, D3D10_SDK_VERSION, SwapChain, ppSwapChain, device);
(*ppSwapChain)->GetBuffer(0, __uuidof(ID3D10Texture2D), ppSurface);
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
if(!RegisterClassEx(&wcex))
{
MessageBox(NULL, _T("Call to RegisterClassEx failed!"), _T("virhackapp"), NULL);
return 1;
}
hInst = hInstance;
//The parameters to CreateWindow explained:
//szWindowClass: The name of the app
//szTitle: the text taht appears in the title bar
//WS_OVERLAPPEDWINDOW: the type of the window to create
//CW_USEDEFAULT, CW_USEDEFAULT: initial position(x,y)
//500,100: initial size(width, length)
//NULL: the parent of this window
//NULL: this application does not have a menu bar
//hInstance: thie first parameter from WinMain
//NULL: not used in this application
HWND hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 500, 100, NULL, NULL, hInstance, NULL);
if(!hWnd)
{
MessageBox(NULL, _T("Call to CreateWindow failed!"), _T("virhackapp"), NULL);
return 1;
}
//DISPLAYS WINDOW
//The parameters to ShowWindow explained:
//hWnd: the value returned from CreateWindow
//nCmdShow: the fourth parameter from WinMain
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
//MESSAGE LOOP THAT SENDS TO WndProc
MSG msg;
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
//WM_PAINT: app recieves this message when part of its displayed window must be updated. (When the window is first displayed, all of it must be updated)
//To handle WM_PAINT, first call BeginPaint, then handle all logic to lay out text, buttons, and other controls
//Then call EndPaint
//Use TextOut to display a string
PAINTSTRUCT ps;
HDC hdc;
TCHAR greeting[] = _T("Hello, World!");
switch(message)
{
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
//Here the application is laid out.
//For right now, displays "Hello, World!"
//in the top left corner.
//Graphics are done here
TextOut(hdc, 5, 5, greeting, _tcslen(greeting));
//End application specific layout section
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
break;
}
return 0;
}
错误的行在这里:
(*ppSwapChain)->GetBuffer(0, __uuidof(ID3D10Texture2D), ppSurface);
我怀疑这是因为我的 CreateDeviceAndSwapChain 没有成功完成,但我不知道为什么。这是实际的错误报告:
'VirHack.exe': Loaded 'C:\Users\Will\Documents\Visual Studio 2010\Projects\VirHack\Debug\VirHack.exe', Symbols loaded.
'VirHack.exe': Loaded 'C:\Windows\SysWOW64\ntdll.dll', Cannot find or open the PDB file
'VirHack.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll', Cannot find or open the PDB file
'VirHack.exe': Loaded 'C:\Windows\SysWOW64\KernelBase.dll', Cannot find or open the PDB file
'VirHack.exe': Loaded 'C:\ProgramData\Norton\{0C55C096-0F1D-4F28-AAA2-85EF591126E7}\NAV_20.2.0.19\Definitions\BASHDefs\20130620.001\UMEngx86.dll', Cannot find or open the PDB file
'VirHack.exe': Loaded 'C:\Windows\SysWOW64\user32.dll', Cannot find or open the PDB file
'VirHack.exe': Loaded 'C:\Windows\SysWOW64\gdi32.dll', Cannot find or open the PDB file
'VirHack.exe': Loaded 'C:\Windows\SysWOW64\lpk.dll', Cannot find or open the PDB file
'VirHack.exe': Loaded 'C:\Windows\SysWOW64\usp10.dll', Cannot find or open the PDB file
'VirHack.exe': Loaded 'C:\Windows\SysWOW64\msvcrt.dll', Cannot find or open the PDB file
'VirHack.exe': Loaded 'C:\Windows\SysWOW64\advapi32.dll', Cannot find or open the PDB file
'VirHack.exe': Loaded 'C:\Windows\SysWOW64\sechost.dll', Cannot find or open the PDB file
'VirHack.exe': Loaded 'C:\Windows\SysWOW64\rpcrt4.dll', Cannot find or open the PDB file
'VirHack.exe': Loaded 'C:\Windows\SysWOW64\sspicli.dll', Cannot find or open the PDB file
'VirHack.exe': Loaded 'C:\Windows\SysWOW64\cryptbase.dll', Cannot find or open the PDB file
'VirHack.exe': Loaded 'C:\Windows\SysWOW64\d3d10.dll', Cannot find or open the PDB file
'VirHack.exe': Loaded 'C:\Windows\SysWOW64\d3d10core.dll', Cannot find or open the PDB file
'VirHack.exe': Loaded 'C:\Windows\SysWOW64\dxgi.dll', Cannot find or open the PDB file
'VirHack.exe': Loaded 'C:\Windows\SysWOW64\version.dll', Cannot find or open the PDB file
'VirHack.exe': Loaded 'C:\Windows\SysWOW64\dwmapi.dll', Cannot find or open the PDB file
'VirHack.exe': Loaded 'C:\Windows\SysWOW64\d3d11.dll', Cannot find or open the PDB file
'VirHack.exe': Loaded 'C:\Windows\SysWOW64\msvcr100d.dll', Symbols loaded.
'VirHack.exe': Loaded 'C:\Windows\SysWOW64\imm32.dll', Cannot find or open the PDB file
'VirHack.exe': Loaded 'C:\Windows\SysWOW64\msctf.dll', Cannot find or open the PDB file
'VirHack.exe': Loaded 'C:\Windows\SysWOW64\nvinit.dll', Cannot find or open the PDB file
'VirHack.exe': Loaded 'C:\Program Files (x86)\NVIDIA Corporation\coprocmanager\detoured.dll', Cannot find or open the PDB file
'VirHack.exe': Loaded 'C:\Program Files (x86)\NVIDIA Corporation\coprocmanager\Nvd3d9wrap.dll', Cannot find or open the PDB file
'VirHack.exe': Loaded 'C:\Windows\SysWOW64\setupapi.dll', Cannot find or open the PDB file
'VirHack.exe': Loaded 'C:\Windows\SysWOW64\cfgmgr32.dll', Cannot find or open the PDB file
'VirHack.exe': Loaded 'C:\Windows\SysWOW64\oleaut32.dll', Cannot find or open the PDB file
'VirHack.exe': Loaded 'C:\Windows\SysWOW64\ole32.dll', Cannot find or open the PDB file
'VirHack.exe': Loaded 'C:\Windows\SysWOW64\devobj.dll', Cannot find or open the PDB file
'VirHack.exe': Loaded 'C:\Program Files (x86)\NVIDIA Corporation\coprocmanager\nvdxgiwrap.dll', Cannot find or open the PDB file
First-chance exception at 0x00831056 in VirHack.exe: 0xC0000005: Access violation reading location 0x00000000.
Unhandled exception at 0x778e15de in VirHack.exe: 0xC0000005: Access violation reading location 0x00000000.
The program '[10756] VirHack.exe: Native' has exited with code -1073741819 (0xc0000005).
关于为什么会发生这种情况的任何想法?