c++ - 如何为调用 DirectX 函数的 C# 窗体制作 C++ Dll?
问题描述
我想制作一个使用 C# Forms 进行窗口处理的 DirectX 应用程序,因为这是我最熟悉的。我制作了一个 C++ Dll 项目并添加了这些依赖项以在 Linker -> Input -> Additional Dependencies 下获取 DirectX。
d3d11.lib
dxgi.lib
dxguid.lib
uuid.lib
kernel32.lib
user32.lib
comdlg32.lib
advapi32.lib
shell32.lib
ole32.lib
oleaut32.lib
我将 System 下的 SubSystem 设置为 Windows。并将输出文件夹设置为 C# Forms 项目的 bin 文件夹,这样我就不必每次构建 C++ 项目时都复制粘贴。然后我添加两个文件,一个头文件和一个 cpp 文件。
测试导出.h
#pragma once
#include "pch.h"
#include <d3dcompiler.h>
#include <d3d11_1.h>
#include <directxcolors.h>
#include <wrl/client.h>
using namespace DirectX;
extern "C"
{
__declspec(dllexport) void __cdecl Test();
}
测试导出.cpp
#include "pch.h"
#include "TestExport.h"
void Test()
{
ID3DBlob *pBlob;
D3D10CreateBlob(12, &pBlob);
delete pBlob;
}
我知道 TestExport.cpp 中的函数目前没有做任何事情,但是当问题得到解决时,它将被一些真正的方法替换。问题是我一LNK2001 unresolved external symbol _D3D10CreateBlob@8
调用该D3D10CreateBlob
方法就会出错。我对 Dll 的了解不多,也不知道要搜索什么才能找到 awnser 或潜在客户
解决方案
Thanks for helping me in finding or explain my problem :)
To link to DirectX i added the include path in Configuration Properties -> C/C++ -> General -> Additional Include Directories. visual studio thankfully has a macro for the include folder called $(WindowsSDK_IncludePath).
Then I went to Configuration Properties -> Linker -> General -> Additional Library Directories and set the x64 platform to $(WindowsSDK_LibraryPath_x64) and the x86 to $(WindowsSDK_LibraryPath_x86).
I also changed the Configuration Properties -> Linker -> Input -> Additional Dependencies to include
dxgi.lib
d3d11.lib
d3d12.lib
d3d10.lib
d3dcompiler.lib
which I think is the acctuall problem I had. That I didn't include d3d10.lib
* facepalms *
推荐阅读
- spring-boot - Springboot反序列化“>”符号为>和“<”为<
- youtube - Youtube-dl 仅选择主要发行艺术家和年份并添加自定义元数据
- javascript - Vue 3 - “无法解析组件”警告
- c++ - 为什么这个 C++ 程序会导致一些未知测试用例的错误输出,我无法调试?
- azure-functions - Function App(高级)访问限制和 NSG 出站规则
- javascript - 如何创建可用于不同文件的通用搜索功能
- javascript - 尽管采取了非常相似的方法,为什么我会得到一个无限循环?
- javascript - 以最有效的方式从给定字符串中删除单词数组
- mysql - Mysql命令无法连接到远程主机
- r - 如何将变量设置为全局环境中的因子