Major Problem....This code consistently generates an unbalanced stack error. I have even tried to change the Wrapper class argument to an IntPtr and that does not work....I am stumped....the "suggestion" is that my parameters do not match the number of arguments expected by the dll. Anyone used this wrapper class before? Any Problems?
dll is from http://www.fftw.org
wrapper class is from http://www.sdss.jhu.edu/~tamas/bytes/fftwcsharp.html
ANSI C base function in the dll is:
void *fftwf_malloc(size_t n);
Wrapper Implementation for PInvoke is:
IntPtr malloc(int length); //in a wrapper class called fftw
My code simply calls:
fftw.malloc(1000); //hardcoded test to see why this is failing...
fftw.malloc(FFTSampleSize*sizeof(float)*2); //where FFTSampleSize is a int

Bechir BejaouiRank #144 · 15.9K reputationPosted Sep 10, 2010, 10:12 AM EDT
Are you using 3.5 or 4.0, because the 4.0 resolves you problem by using optional parameters
Chris Foley34 reputationPosted Sep 13, 2010, 5:26 AM EDT
Bechir BejaouiRank #144 · 15.9K reputationPosted Sep 13, 2010, 5:49 AM EDT
Chris Foley34 reputationPosted Sep 13, 2010, 6:04 AM EDT
Bechir BejaouiRank #144 · 15.9K reputationPosted Sep 13, 2010, 6:20 AM EDT
Chris Foley34 reputationPosted Sep 13, 2010, 6:24 AM EDT
Bechir BejaouiRank #144 · 15.9K reputationPosted Sep 13, 2010, 6:46 AM EDT
I remember I have read a good artile for simila issue, I thing this one
http://msdn.microsoft.com/en-us/magazine/cc163606.aspx
Meanwhile, I give you and alternative solution, if you have the unmanaged library then you could wrap up it and use it, I invite you to take a look on my articles in this context
http://www.c-sharpcorner.com/UploadFile/yougerthen/510262008060749AM/5.aspx?ArticleID=d2da1ab3-b92d-499d-94cd-bf54d91e14c3
Chris Foley34 reputationPosted Sep 13, 2010, 6:58 AM EDT
Bechir BejaouiRank #144 · 15.9K reputationPosted Sep 13, 2010, 7:37 AM EDT
Or this one
Chris Foley34 reputationPosted Sep 13, 2010, 8:00 AM EDT
Bechir BejaouiRank #144 · 15.9K reputationPosted Sep 13, 2010, 8:09 AM EDT
Chris Foley34 reputationPosted Sep 13, 2010, 11:03 AM EDT
Bechir BejaouiRank #144 · 15.9K reputationPosted Sep 13, 2010, 11:16 AM EDT
krishna v30 reputationPosted Sep 13, 2010, 10:11 PM EDT
I remember size_t is typedef for unsinged int
IntPtr malloc(uint16 length);
IntPtr malloc(uint32 length);
Chris Foley34 reputationPosted Sep 15, 2010, 7:47 AM EDT
Bechir BejaouiRank #144 · 15.9K reputationPosted Sep 15, 2010, 8:42 AM EDT
What do you mean by the calling convention change Chris
Chris Foley34 reputationPosted Sep 15, 2010, 8:57 AM EDT
Jim Tallent6 reputationPosted Dec 14, 2010, 6:05 PM EST
I'm been working down the same path over the past two weeks trying to use the following:
I am hopping you can help me with a few issues I'm having in implementing this class/wrapper successfully as there is not much info I can find. If so, I will post my question here.
Thanks
Jim
Chris Foley34 reputationPosted Dec 15, 2010, 3:24 AM EST
Jim Tallent6 reputationPosted Dec 15, 2010, 9:37 AM EST
I was also able to get a clean compile and have been running the FFTs. However my FFT results are questionable. I can send you what I have if you plan to get back on the project. Maybe between the two of us we can resolve issues. One of my questions is regarding the data input and output requirements since I am using the fftw_complexarray.
Maybe you can tell me this:
When I input my real data to the fftw_complexarray, as per my understanding, the data must be formatted as alternating real and imaginary parts. So, if I have an an array of 4 real numbers the input to the fftw_complexarray must be of size 8 and the data copied to the fftw_complexarray needs to look like: real_1,Imag_1, real_2,Imag_2, real_3,Imag_3, real_4,Imag_4. Where all Imaginary data is initially set to "0".
Following the FFT execution I perform addition calculations on the FFT output, and likewise my understanding is that the FFT output data is formatted in the array as: real_1,Imag_1, real_2,Imag_2, real_3,Imag_3, real_4,Imag_4, ...
I am trying to execute a Phase_Correlation on two 1-D real data arrays using the example provided at:
http://nashruddin.com/phase-correlation-function-in-opencv.html
Once successful I'll go for the 2-D array (two images).
Thanks
James
Sam HobbsRank #108 · 20.5K reputationPosted Dec 15, 2010, 6:26 PM EST
The malloc function is part of C/C++. You can find the "signature" in the headers; it is: Using that, it is clear that calling convention is cdecl.
I doubt however that you you need to use malloc; the .Net Interop probably have safer ways to do what you need to do.
Sam HobbsRank #108 · 20.5K reputationPosted Dec 15, 2010, 6:32 PM EST
Chris Foley34 reputationPosted Dec 16, 2010, 4:18 AM EST
Sam HobbsRank #108 · 20.5K reputationPosted Dec 16, 2010, 6:51 AM EST
Chris Foley34 reputationPosted Dec 16, 2010, 7:27 AM EST
Michael Lamming2 reputationPosted Feb 3, 2011, 12:27 PM EST
Sam HobbsRank #108 · 20.5K reputationPosted Feb 3, 2011, 4:00 PM EST