Bechir Bejaoui
posted
1450 posts
since
Dec 06, 2007
from
|
|
Re: PInvoke Error for FFTW
|
|
|
|
|
|
|
|
|
|
|
Hi
Are you using 3.5 or 4.0, because the 4.0 resolves you problem by using optional parameters
|
|
|
|
|
Every one among us was a beginner once. http://dotnetuniver.blogspot.com/
|
|
|
|
|
|
Chris Foley
posted
19 posts
since
Jul 31, 2010
from
Pearland, TX
|
|
Re: PInvoke Error for FFTW
|
|
|
|
|
|
|
|
|
|
Target Framework: .NET Framework 4 Client Profile.
I have tried reworking the wrapper declaration as uint was well...same issue.
|
|
|
|
|
|
Bechir Bejaoui
posted
1450 posts
since
Dec 06, 2007
from
|
|
Re: PInvoke Error for FFTW
|
|
|
|
|
|
|
|
|
|
|
Please send the detail error or exception that happens when you run the code
|
|
|
|
|
Every one among us was a beginner once. http://dotnetuniver.blogspot.com/
|
|
|
|
|
|
Chris Foley
posted
19 posts
since
Jul 31, 2010
from
Pearland, TX
|
|
Re: PInvoke Error for FFTW
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Bechir Bejaoui
posted
1450 posts
since
Dec 06, 2007
from
|
|
Re: PInvoke Error for FFTW
|
|
|
|
|
|
|
|
|
|
|
Sorry but I didn't see any screenshot, Now I see it OK
|
|
|
|
|
Every one among us was a beginner once. http://dotnetuniver.blogspot.com/
|
|
|
|
|
|
Chris Foley
posted
19 posts
since
Jul 31, 2010
from
Pearland, TX
|
|
Re: PInvoke Error for FFTW
|
|
|
|
|
|
|
|
|
|
|
I had to go back a second time and load the image...the above post should have the unbalanced stack message now. I also went back and verified that I do have the 32-bit version of the dll from FFTW installed.
|
|
|
|
|
|
Bechir Bejaoui
posted
1450 posts
since
Dec 06, 2007
from
|
|
Re: PInvoke Error for FFTW
|
|
|
|
|
|
|
|
|
|
|
The parameter issue couldn't only be the unique raison (Of Corse you verify the parameter number,order and size) It could be also a bug witihin the unmanaged code, I mean the invoked native function unbalances the stack because of a given bug.
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
|
|
|
|
|
Every one among us was a beginner once. http://dotnetuniver.blogspot.com/
|
|
|
|
|
|
Chris Foley
posted
19 posts
since
Jul 31, 2010
from
Pearland, TX
|
|
Re: PInvoke Error for FFTW
|
|
|
|
|
|
|
|
|
|
nope, this is all 32-bit...PC, OS (Windows XP Pro 2002, SP 3) with the 32-bit dll.
I have access to the unmanaged code BUT I do not have the tools to compile and link it....
I have tried the modifying the PInvoke Signature for all of the following...
IntPtr int unit long
All of these give the same stack imbalance error. The original code is based on size_t which can only be a 32-bit or 64-bit integer...right?
|
|
|
|
|
|
Bechir Bejaoui
posted
1450 posts
since
Dec 06, 2007
from
|
|
Re: PInvoke Error for FFTW
|
|
|
|
|
|
|
|
|
|
Try to use this argument staff instead
IntPtr int UIntPtr because size_t is an unsigned and Inptr change its size dynamically to fit the variable size
long Or this one IntPtr int IntPtr long
|
|
|
|
|
Every one among us was a beginner once. http://dotnetuniver.blogspot.com/
|
|
|
|
|
|
Chris Foley
posted
19 posts
since
Jul 31, 2010
from
Pearland, TX
|
|
Re: PInvoke Error for FFTW
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Bechir Bejaoui
posted
1450 posts
since
Dec 06, 2007
from
|
|
Re: PInvoke Error for FFTW
|
|
|
|
|
|
|
|
|
|
|
I m pretty sure that the problem comes from the unmanaged code. Verify if the given unmanaged libray has dependencies on other libraries, you know the function that you call could call anther code source outside the assembly
|
|
|
|
|
Every one among us was a beginner once. http://dotnetuniver.blogspot.com/
|
|
|
|
|
|
Chris Foley
posted
19 posts
since
Jul 31, 2010
from
Pearland, TX
|
|
Re: PInvoke Error for FFTW
|
|
|
|
|
|
|
|
|
|
I think I just solved this...it seems to be in the DllImport arguments. I kept thinking that I have sent every datatype and still have the exact same issue so I tried to understand all the modifiers (still do not understand all of them). However, I found an obscure reference that said something like "if you keep getting this error, try setting the CallingConvention = Cdecl. That did it. However, I have to change the entire wrapper class as this happens on each and every function exported.
[DllImport("libfftw3f-3.dll", EntryPoint = "fftwf_malloc", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr malloc(int length);
|
|
|
|
|
|
Bechir Bejaoui
posted
1450 posts
since
Dec 06, 2007
from
|
|
Re: PInvoke Error for FFTW
|
|
|
|
|
|
|
|
|
|
|
I think is not related with your case, you know this enumeration value specifying that the native function is using a varargs multi dimension variable like params but in your case I dont think so that this is the issue
|
|
|
|
|
Every one among us was a beginner once. http://dotnetuniver.blogspot.com/
|
|
|
|
|
|
krishna v
posted
16 posts
since
Feb 08, 2006
from
|
|
Re: PInvoke Error for FFTW
|
|
|
|
|
|
|
|
|
|
|
try modifying the signature to unit16 / uint32
I remember size_t is typedef for unsinged int
IntPtr malloc(uint16 length);
IntPtr malloc(uint32 length);
|
|
|
|
|
|
Chris Foley
posted
19 posts
since
Jul 31, 2010
from
Pearland, TX
|
|
Re: PInvoke Error for FFTW
|
|
|
|
|
|
|
|
|
|
|
I tried that and got the same error. However, the calling convention change has worked....go figure. As soon as I got the fftwf.malloc() function working, I got the exact same error on the other methods in the FFTWF class. I have updated all of them with the change and they now all function as they should.
|
|
|
|
|
|
Bechir Bejaoui
posted
1450 posts
since
Dec 06, 2007
from
|
|
Re: PInvoke Error for FFTW
|
|
|
|
|
|
|
|
|
|
|
Hi Chris
What do you mean by the calling convention change Chris
|
|
|
|
|
Every one among us was a beginner once. http://dotnetuniver.blogspot.com/
|
|
|
|
|
|
Chris Foley
posted
19 posts
since
Jul 31, 2010
from
Pearland, TX
|
|
Re: PInvoke Error for FFTW
|
|
|
|
|
|
|
|
|
|
|
look up several post and note the DLLImport arguments where I added the CallingConvention statement.
|
|
|
|
|
|
Jim Tallent
posted
5 posts
since
Dec 14, 2010
from
|
|
Re: PInvoke Error for FFTW
|
|
|
|
|
|
|
|
|
|
Hello Chris,
I'm been working down the same path over the past two weeks trying to use the following:
wrapper class is from http://www.sdss.jhu.edu/~tamas/bytes/fftwcsharp.htmlI 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 Foley
posted
19 posts
since
Jul 31, 2010
from
Pearland, TX
|
|
Re: PInvoke Error for FFTW
|
|
|
|
|
|
|
|
|
|
Jim,
I have had to put this project aside for the moment. I did get a clean compile by changing the calling convention in the PInvoke signature. HOWEVER, I have not been able to a clean FFT using the functions yet. I am not sure that my input data is correct and have not had a chance to verify it.
Chris
|
|
|
|
|
|
Jim Tallent
posted
5 posts
since
Dec 14, 2010
from
|
|
Re: PInvoke Error for FFTW
|
|
|
|
|
|
|
|
|
|
|
Hello Chris,
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 Hobbs
posted
5888 posts
since
Sep 07, 2009
from
Los Angeles, California, USA
|
|
Re: PInvoke Error for FFTW
|
|
|
|
|
|
|
|
|
|
Chris: the error message you got about the stack does say very clearly that the cause might be the calling convention. Therefore it makes sense to me that specifying cdecl works.
The malloc function is part of C/C++. You can find the "signature" in the headers; it is:
void * __cdecl malloc(_In_ size_t _Size); 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.
|
|
|
|
|
Thinking is a feeling; pleasant for some and unpleasant for others.
|
|
|
|
|
|
Sam Hobbs
posted
5888 posts
since
Sep 07, 2009
from
Los Angeles, California, USA
|
|
Re: PInvoke Error for FFTW
|
|
|
|
|
|
|
|
|
|
|
James: it appears to me that your problem is totally different. I am concerned that if either of you try to use the other's solutions then one or both of you will get confused. Something that someone suggests for one of you is likely to confuse the ohter. I suggest that you create a new thread for your situation.
|
|
|
|
|
Thinking is a feeling; pleasant for some and unpleasant for others.
|
|
|
|
|
|
Chris Foley
posted
19 posts
since
Jul 31, 2010
from
Pearland, TX
|
|
Re: PInvoke Error for FFTW
|
|
|
|
|
|
|
|
|
|
Sam,
fftw.malloc is not the standard malloc in C. It is a special one that aligns the memory in continuous memory blocks (I think). It is specific to the fftw library and I have to use Interop to use it.
Chris
|
|
|
|
|
|
Sam Hobbs
posted
5888 posts
since
Sep 07, 2009
from
Los Angeles, California, USA
|
|
Re: PInvoke Error for FFTW
|
|
|
|
|
|
|
|
|
|
|
Okay, so I made a mistake. So are you ignoring everything I said? There is a "signature" in a header someplace that specifies the calling convention and the parameters, so you don't have to guess.
|
|
|
|
|
Thinking is a feeling; pleasant for some and unpleasant for others.
|
|
|
|
|
|
Chris Foley
posted
19 posts
since
Jul 31, 2010
from
Pearland, TX
|
|
Re: PInvoke Error for FFTW
|
|
|
|
|
|
|
|
|
|
|
oh lord no. What you have said is accurate and I fully appreciate the input. The problem now is that I cannot get sample data to give me a clean and accurate FFT. I just need to find more time to get into it without interruptions.
|
|
|
|
|
|
Michael Lamming
posted
1 posts
since
Feb 03, 2011
from
|
|
Re: PInvoke Error for FFTW
|
|
|
|
|
|
|
|
|
|
|
Did anybody resolve this finally. I'm struggling to use the dll from C# too. Seems a shame to have to have to change the calling conventions on every signature.
|
|
|
|
|
|
Sam Hobbs
posted
5888 posts
since
Sep 07, 2009
from
Los Angeles, California, USA
|
|
Re: PInvoke Error for FFTW
|
|
|
|
|
|
|
|
|
|
|
If the calling convention has been incorrectly specified on every signature then the mistake must be undone on every signature.
|
|
|
|
|
Thinking is a feeling; pleasant for some and unpleasant for others.
|
|
|
|
|
|