c# - 使用 DLLImport 从 C# 调用 c++,找不到对象引用错误
问题描述
我正在尝试使用 DLLImport 从 C# 调用 c++ dll,并且遇到“找不到对象引用”错误。
我以前做过这个,所以我肯定错过了一些东西,但是什么?
在 C# 中,我有:
[DllImport("Test.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern void Tester();
和功能:
public void ConnectionGo()
{
Tester();
}
在 dll 中,我有:
extern "C"
{
_declspec(dllexport) void Tester()
{
std::cout << "Okay" << std::endl;
}
};
该 dll 与 C# exe 位于同一目录中(它是一个 WPF 应用程序)。它们都被构建为“Release”。
然而我得到了这个错误:
'Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.'
这可能是什么原因造成的?
解决方案
推荐阅读
- bazel - 如何将 `config_setting()` 加载到我的 `.bzl` 文件中?
- dask - df.loc[df.index.intesection(mylabels)] 的 dask 等价物
- service - 每个由 ejabberd 管理的 MUC 频道机器人
- google-cloud-trace - 在 UI 中查看 stackTrace?
- wordpress - 在 WP 中打开带有密码保护的 Pdf
- c - 我应该为哈希表中的存储桶使用什么数据结构?
- c# - 如何删除或隐藏枢轴的页面选择
- python - 来自 scikit-learn 随机森林的令人困惑的概率
- awk - 在 awk 中使用标准输出作为输入
- asp.net - 使用 IAuthenticationFilter 时 HttpContext.Current 为空