在C#应用程序中将void *从一个dll发送到另一个dll

时间:2014-05-19 07:50:21

标签: c# .net dll marshalling

我有一个应用程序需要使用c#应用程序将void*参数(从一个dll获取)的值传输到另一个dll。以下是函数定义:

DLL 1功能:     int Init(void** BusHandle);

DLL 2功能:     int AttachHandle(void* BusHandle)

我在c#中创建了以下定义:

[DllImport("1.dll")]
public static extern int Init(ref IntPtr BusHandle); // ref or out seems to to the job in the same way

[DllImport("2.dll")]
public static extern int AttachHandle( IntPtr BusHandle);

在基于ANSI C的应用程序中运行一切正常,但在C#应用程序中它不起作用,似乎无法接受句柄。

有用信息:

  • 我没有dll的源代码。
  • 从Init函数获取的Bushandle在C#中有效(我有使用它的DLL 1中的其他函数并且它有效)
  • 句柄指的是串行端口(COM)
  • 这两个DLL都是在ANSI C编译器下构建的,通过__declspec(dllexport)导出函数
  • 我正在使用带有3.5 Framework的Visual Studio 2012

0 个答案:

没有答案