Skip to main content
 首页 » 编程设计

c#之PInvoke 和 double*

2024年02月20日11jackei

如果这是重复的,我深表歉意。我正在编写一个需要与旧的 C++ 非托管 dll 交互的类。有一种方法我很难映射到托管代码:

long DoSomething(int id, double* points, long numberOfPoints, bool useShaping) 

到目前为止,我一直无法将其映射到不会抛出堆栈不平衡异常的外部方法。问题出在双指针上。方法签名在托管代码中寻找什么?以下是我尝试过但无法作为示例的内容。

[DllImport("Something.Dll", EntryPoint = "DoSomething")] 
public static extern long DoSomething(int id, double[] points, long numberOfPoints, bool useShaping) 

请您参考如下方法:

可能有两个问题——

  1. 这很可能需要指定调用约定。
  2. C++ 中的“long”映射到 C# 中的“int”

尝试以下操作:

[DllImport("Something.Dll", EntryPoint = "DoSomething", CallingConvention=CallingConvention.Cdecl)] 
public static extern int DoSomething(int id, double[] points, int numberOfPoints, bool useShaping);