无法使用 Visual Studio 启动 DirectX 11 可执行文件,生成工作正常
Cannot start DirectX 11 executable with Visual Studio, Build works properly
以下是 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.3umx64
的C: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 作为宽字符串文本的前缀
相关文章:
- 如何将不同的可执行文件合并到一个窗口框架中进行编码?像浏览器一样
- 如何使 windows 命令提示符在C++可执行文件上显示返回值?
- CMake:如何将库 A 链接到库 B,然后将可执行文件链接到库 A
- 如何使字符串出现在编译的二进制可执行文件的开头?
- 程序在使用 system() 启动另一个可执行文件时停止
- 如何更改使用 CPack 安装的可执行文件的名称?
- 在Linux上使用Clang / OLLVM交叉编译helloworld Windows可执行文件时的问题
- CMake:我们可以为一组不形成可执行文件或库的特定文件指定包含目录吗?
- 如何将图像传入C++可执行文件并将输出图像存储在新目录中?
- 共享库 (.so) 没有扩展名的 Linux 可执行文件之间的区别?
- 如何在 linux 可执行文件中使用静态库
- 错误:当我从"WinDbg"打开可执行文件时,找不到符号文件。默认导出 ntdll 的符号.dll
- 无法使用 Visual Studio 启动 DirectX 11 可执行文件,生成工作正常
- 为什么将可执行文件重命名为临时文件的此代码段不能按预期工作?
- C 可执行文件不从文件夹工作,而是在Mac上从控制台上工作
- 创建不需要任何进一步安装即可在其他计算机上工作的可执行文件?
- 可执行文件无法正常工作 [Linux]
- VIsual C++可执行文件不工作
- 如何从节点在Heroku上运行可执行文件,在本地工作
- JNI共享库中未定义的符号,可执行文件正在工作