简体   繁体   English

C#DLLImport'复杂'数组的返回和参数

[英]C# DLLImport 'Complex' array in return and parameters

I'm just writing a small test integration between a native C++ DLL called 'fft.dll' and a C# console application. 我只是在一个名为'fft.dll'的本机C ++ DLL和一个C#控制台应用程序之间编写一个小的测试集成。

fft.dll contains a single class called Fourier which contains a single static method: fft.dll包含一个名为Fourier类,它包含一个静态方法:

#include <complex>
using namespace std;
class Fourier
{
public:
    static complex<double>* fft(complex<double>*);
};

The static method fft(...) simply computes an FFT of the complex<double> array, and returns the computed FFT as a complex<double> array. 静态方法fft(...)只是计算complex<double>数组的FFT,并将计算出的FFT作为complex<double>数组返回。

I have two questions: 我有两个问题:

  1. The function accepts an array of complex<double> s, yet to my knowledge no such data structure exists in .Net. 该函数接受一个complex<double>数组,但据我所知,.Net中不存在这样的数据结构。 How can/should I format my data to pass into the fft(...) function? 我怎样才能/我应该格式化我的数据以传递到fft(...)函数?
  2. Since the static member is inside a class, what syntax should I use in my .Net console application when using [DllImport("fft.dll")] ? 由于静态成员位于类中,因此在使用[DllImport("fft.dll")]时,我应该在.Net控制台应用程序中使用什么语法?

Thanks 谢谢

Edit: Follow-up question: here 编辑:后续问题: 这里

AFAIK, you must export function at c/c++ world for .NET to consume it (using dll-import). AFAIK,您必须在c / c ++世界中导出函数以便.NET使用它(使用dll-import)。 I am not certain how you can map a C++ templated class in .NET world - so I would suggest that you can write a c-style wrapper function within your dll, add it to export list. 我不确定如何在.NET世界中映射C ++模板化类 - 所以我建议您可以在dll中编写一个c风格的包装函数,将其添加到导出列表中。 The function should accept and return array of helper structure (similar to Complex<double> ) so that you can map the structure in .NET world. 该函数应该接受并返回辅助结构数组(类似于Complex<double> ),以便您可以在.NET世界中映射结构。 Your function would convert from this struct to complex class and invoke the static function. 您的函数将从此结构转换为复杂类并调用静态函数。

P/Invoke does not support calling static class functions, nor does it support and understand C++ templates. P / Invoke不支持调用静态类函数,也不支持和理解C ++模板。

As VinayC suggested, write another wrapper method in your C++ dll which is global and which marshals data from simple double array to/from the templated arrays that your C++ static function is using. 正如VinayC建议的那样,在C ++ dll中编写另一个包装器方法,它是全局的,它将来自简单双数组的数据封送到C ++静态函数正在使用的模板化数组中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM