[英]Importing a C++ dll in C#
I have created a C++ dll ( let say , MyC++Dll.dll) and I have a header file ( MyC++Dll.h ). 我创建了一个C ++ DLL(比方说,MyC ++ Dll.dll),我有一个头文件(MyC ++ Dll.h)。 MyC++Dll.h contains the types definition .
MyC ++ Dll.h包含类型定义。
I want to import this dll in C# application I am creating . 我想在我正在创建的C#应用程序中导入这个dll。
I am able to import the dll using 我可以使用导入dll
[DllImport("MyC++Dll.dll")] static extern func(); [DllImport(“MyC ++ Dll.dll”)] static extern func();
But I am not able to import/include the header file (MyC++Dll.h) in the C# application which contains the types definition . 但是我无法在包含类型定义的C#应用程序中导入/包含头文件(MyC ++ Dll.h)。
Please suggest a way to build this C# application successfully . 请建议一种成功构建此C#应用程序的方法。
You have to convert any non-standard parameter types (ie custom structures, etc.) to C# by hand. 您必须手动将任何非标准参数类型(即自定义结构等)转换为C#。 Look at http://pinvoke.net for examples of how to do this with Win32 structures.
有关如何使用Win32结构执行此操作的示例,请查看http://pinvoke.net 。 You should be able to figure out how to do this for your own structures.
您应该能够弄清楚如何为自己的结构执行此操作。
我知道这样做的唯一方法是手动创建C#中的所有类型定义,确保它们与您的dll兼容。
而且你还需要学习如何编组从C ++到C#的类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.