i have following code , once i run my application i get this error
anyone know how i fix this error?
ERROR:
A call to PInvoke function \'testcamera!
When doing a platform invoke (P/Invoke), you have to tell the CLR what the parameters are (which determines how they get marshalled) as well as what the calling convention of the target native method is so that the runtime knows how to generate code to properly push arguments and cleanup the stack after the call. If the signatures do not match, you end up with runtime errors similar to what you're seeing.
The error message explains the issue well:
This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature
Compare the P/Invoke signature for EDSDK.EdsCreateEvfImageRef
against the actual native method signature that implements this.
You can change the calling convention of the P/Invoke by specifying the CallingConvention property on the DllImport
attribute. More than likely, the calling convention for EDSDK.EdsCreateEvfImageRef
should match the calling convention of your other P/Invokes.
Please use Cdecl calling convention for that function. Don't ask me why, it just works.
[DllImport("EDSDK.dll", CallingConvention=CallingConvention.Cdecl)]
public extern static uint EdsCreateEvfImageRef(IntPtr inStreamRef, out IntPtr outEvfImageRef);
[DllImport("EDSDK.dll",CallingConvention=CallingConvention.Cdecl)]
public extern static uint EdsDownloadEvfImage(IntPtr inCameraRef, IntPtr outEvfImageRef);
I had the same issue as the poster, turned out I needed to change my project using the EDSDK library (v2.10) to use .NET 3.5 instead of .NET 4.0.