无法使用 Visual Studio 启动 DirectX 11 可执行文件,生成工作正常



以下是 Directx 11 代码,它显示一个窗口并使其保持打开状态等待消息:

#include "stdafx.h"
#include <iostream>
LRESULT CALLBACK WindowProc(_In_ HWND   hwnd, _In_ UINT   uMsg,
_In_ WPARAM wParam, _In_ LPARAM lParam)
{
if (uMsg == WM_DESTROY) {
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
// Directx main
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE prevInstance, LPWSTR cmd, int nCmdShow)
{
WNDCLASSEX window;
ZeroMemory(&window, sizeof(WNDCLASSEX));
window.cbSize = sizeof(WNDCLASSEX);
window.hbrBackground = (HBRUSH) COLOR_WINDOW;
window.hInstance = hInstance;
window.lpfnWndProc = WindowProc;
window.lpszClassName = (LPCWSTR)"MainWindow";   // class name
window.style = CS_HREDRAW | CS_VREDRAW;
RegisterClassEx(&window);
HWND windowHandle = CreateWindow((LPCWSTR)"Main Window", (LPCWSTR)"DirectX Tut!", WS_OVERLAPPEDWINDOW,
100, 100, 600, 800, NULL, NULL, hInstance, 0);
if (!windowHandle) 
return -1;
ShowWindow(windowHandle, nCmdShow);
MSG message;
while (GetMessage(&message, NULL, 0, 0))    // continuously loop for messages
{
DispatchMessage(&message);
}
return 0;
}

stdafx.h是一个预编译的头文件,我在其中包含了所有 DirectX 包含的内容。即在C:Program Files (x86)Windows Kits8.1Includeshared;C:Program Files (x86)Windows Kits8.1Includeum;

我还包括位于C:Program Files (x86)Windows Kits8.1Libwinv6.3umx64C:Program Files (x86)Windows Kits8.1Includeshared;C:Program Files (x86)Windows Kits8.1Includeum;图书馆

我使用的是Visual Studio 2015,Windows 8.1 64位。我按照本教程创建了 Directx 应用程序。简单地制作了一个 Win32 项目,在 include 和 libs 中完成了这些修改,粘贴了代码并正确构建了它。但是,运行不会输出任何内容。它只是说构建成功。VS适用于我所有其他项目。我已经尝试了x64模式下的所有配置。如果我不得不猜测,我会说它没有找到dll..我找不到罪魁祸首。

您在注册窗口类时指定了"MainWindow"作为类名,但在创建窗口时指定了"主窗口",因此Windows找不到该类。 将"MainWindow"作为类名传递给CreateWindow将解决此问题:

window.lpszClassName = L"MainWindow";   // class name
window.style = CS_HREDRAW | CS_VREDRAW;
RegisterClassEx(&window);
HWND windowHandle = CreateWindow(L"MainWindow", L"DirectX Tut!", WS_OVERLAPPEDWINDOW,
100, 100, 600, 800, NULL, NULL, hInstance, 0);

如上所示,应使用 L 作为宽字符串文本的前缀

相关内容

最新更新