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:
- The function accepts an array of
complex<double>
s, yet to my knowledge no such data str开发者_运维技巧ucture exists in .Net. How can/should I format my data to pass into thefft(...)
function? - 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
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.
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.
精彩评论