gpt4 book ai didi

c# - PInvoke 和 double*

转载 作者:太空宇宙 更新时间:2023-11-03 21:58:33 25 4
gpt4 key购买 nike

如果这是重复的,我深表歉意。我正在编写一个需要与旧的 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);

关于c# - PInvoke 和 double*,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11196310/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com