问题描述
嗨我有一个用C ++编写的dll,想在C#中使用(一个常见问题).
我正在尝试进行测试以了解如何使用dll.
因此,我用以下几行简单的代码在C ++中创建了一个新的标准dll:
HiI have a dll written in C++ that I want to use in C# (a common problem).
I am trying to make a test to understand how to use the dll.
So I created a new standard dll in C++ with these simple lines:
extern "C" __declspec (dllexport) short __stdcall TestFunction(short i){
return i+123;
}
然后,我尝试使用以下代码在C#应用程序中使用此测试功能:
Then I am trying to use this test function in an C# application using the code:
[DllImport("Dll.dll")]
static extern short TestFunction(short i);
然后
and then
short x=3;
x=TestFunction(x);
已编译!
但是我得到了这个错误运行时:
发生了类型为"System.BadImageFormatException"的未处理的异常
我认为问题在于该dll无法托管,但我必须将其用作标准C ++且未托管.对吧?
有人知道能达到我的目标吗?
谢谢您的帮助.
Compiled!
But I got this error runtime:
An unhandled exception of type ''System.BadImageFormatException'' occurred
I think the problem is that the dll is not managed, but I have to use it as standard C++ and unmanaged. Right?
Anyone knows hot to reach my target?
Thank you for any help
推荐答案
这篇关于在C#应用程序中使用标准C ++ dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!