简体   繁体   中英

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 contains a single class called Fourier which contains a single static method:

#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.

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. How can/should I format my data to pass into the fft(...) function?
  2. Since the static member is inside a class, what syntax should I use in my .Net console application when using [DllImport("fft.dll")] ?

Thanks

Edit: Follow-up question: here

AFAIK, you must export function at c/c++ world for .NET to consume it (using 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. The function should accept and return array of helper structure (similar to Complex<double> ) so that you can map the structure in .NET world. 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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