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

C# 在C应用程序中将void*从一个dll发送到另一个dll,c#,.net,dll,marshalling,C#,.net,Dll,Marshalling,我有一个应用程序,需要使用c应用程序将从一个dll获得的void*参数的值传输到另一个dll。以下是函数定义: DLL 1函数: int Initvoid**BusHandle DLL 2函数: int AttachHandlevoid*BusHandle 我在c中给出了以下定义: [DllImport("1.dll")] public static extern int Init(ref IntPtr BusHandle); // ref or out seems to to the job

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

DLL 1函数: int Initvoid**BusHandle

DLL 2函数: int AttachHandlevoid*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);
在基于ANSIC的应用程序中运行,一切正常,但在C应用程序中它不工作,似乎无法访问句柄

有用信息:

我没有DLL的源代码。 从Init函数获得的Bushandle在C中是有效的。我有来自DLL 1的其他函数使用它,并且它可以工作 句柄引用的是串行端口COM 这两个DLL都是在ANSIC编译器下构建的,通过u declspecdllexport导出函数 我正在使用Visual Studio 2012和3.5框架
int Initvoid**BusHandle使用指向指针的指针,而int AttachHandlevoid*BusHandle仅使用指针-这是否正确?唯一明显不正常的是,您的C声明没有使用CallingConvention属性。如果正确复制/粘贴函数声明,则应为Cdecl。忽略Init的返回值是一个相当标准的错误。函数声明是正确的。我还尝试指定调用约定CDECL或stdcall,但没有成功。我更正了有关返回值的键入错误。只是猜测:请检查您在C项目中使用的平台,以及编译DLL的平台。如果DLL是“x86”,那么你必须在你的C项目中也使用“x86”,而不是“任何CPU”。尝试了x86编译器选项仍然没有改变,我甚至尝试使用不安全的代码用void*替换IntPtr,同样的结果。我不知道我还能尝试什么。。。