您好,我目前正在尝试在Visual Studio 2015中设置Direct X项目。
我已经下载了正确的SDK并将项目链接到正确的目录,这是我在uni上所教的内容。 (整个项目只是简单地复制了提供的Word文档中的代码)
我发现这是导致错误的唯一代码行。
if (FAILED(InitialiseWindow(hInstance, nCmdShow)))
{
DXTRACE_MSG("Failed to create Window");
return 0;
}
如果我注释掉DXTRACE_MSG,那么程序就会正确符合。
确切的错误是LNK2019未解析的外部符号__vsnprintf在函数&#34中引用; long __stdcall StringVPrintfWorkerA(char *,unsigned int,unsigned int *,char const *,char *)" (?StringVPrintfWorkerA @@ YGJPADIPAIPBD0 @ Z)教程01练习01 C:\ Users \ Tony \ Desktop \ AGP \ Tutorial 1练习01 \ dxerr.lib(dxerra.obj)。
总的来说,我只是需要帮助来理解错误,它为什么会发生以及我可以做些什么来纠正错误,这样我就可以继续按照我的工作需要继续前进。
非常感谢任何帮助。
#include <windows.h>
#include <D3D11.h>
#include <d3d11.h>
#include <D3DX11.h>
#include <d3dx11.h>
#include <DxErr.h>
//int (WINAPIV * __vsprintf)(char*, size_t, const char*, va_list) = __vsprintf;
// Global Variables
HINSTANCE g_hInst = NULL;
HWND g_hWnd = NULL;
// Rename for each tutorial
char g_TutorialName[100] = "Tutorial 01 Exercise 01\0";
// Forward declarations
HRESULT InitialiseWindow(HINSTANCE hInstance, int nCmdShow);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
// Entry point to the program. Initializes everything and goes into a message processing
// loop. Idle time is used to render the scene.
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
if (FAILED(InitialiseWindow(hInstance, nCmdShow)))
{
DXTRACE_MSG("Failed to create Window");
return 0;
}
// Main message loop
MSG msg = { 0 };
while (msg.message != WM_QUIT)
{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
//do somthing
}
}
return (int)msg.wParam;
}
// Register class and create window
HRESULT InitialiseWindow(HINSTANCE hInstance, int nCmdShow)
{
// Give your app window your own name
char Name[100] = "Hello World\0";
// Register class
WNDCLASSEX wcex = { 0 };
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.hInstance = hInstance;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
// wcex.hbrBackground = (HBRUSH )( COLOR_WINDOW + 1); // Needed for non-D3D apps
wcex.lpszClassName = Name;
if (!RegisterClassEx(&wcex)) return E_FAIL;
// Create window
g_hInst = hInstance;
RECT rc = { 0, 0, 640, 480 };
AdjustWindowRect(&rc, WS_OVERLAPPEDWINDOW, FALSE);
g_hWnd = CreateWindow(Name, g_TutorialName, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, rc.right - rc.left,
rc.bottom - rc.top, NULL, NULL, hInstance, NULL);
if (!g_hWnd)
return E_FAIL;
ShowWindow(g_hWnd, nCmdShow);
return S_OK;
}
// Called every time the application receives a message
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
switch (message)
{
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_KEYDOWN:
if (wParam == VK_ESCAPE)
DestroyWindow(g_hWnd);
return 0;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}