dll 中返回 void * 类型的函数,如何在C#中声明?

C++中原型是怎样的:

extern "C" _declspec(dllexport) void * creat(const char* password);

整个怎么在C# 中调用啊,void * 正常对应的是 IntPtr,可总是说签名不正确,byte[]也不行

阅读 11k
2 个回答

你应该先贴问题代码。 我觉得可能是没有指定CallingConvention

[DllImport("???.dll", EntryPoint = "creat", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.SysInt)]
public static extern IntPtr Create(...);

签名不正确?你确定不是因为你的dll是32位而你的系统是64位导致的?

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题