1

This is the error I am getting while referencing the CDSDK.dll:

    A call to PInvoke function 'Canon_Camera_Control!RDC.CameraSDK.cdAPI::CDStartSDK' has unbalanced the stack. 
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.

The erorr is on a file called CAMERA.cs it's a part of my project to control my canon camera through the pc.

I was missing this dll file so i downloaded it twice from two places. At the first time the dll file was 300kb and gave an error but the program didn't stop i used my logger to log out the error:

5/2/2013--11:02 PM ==> Error! CDStartSDK C000060
5/2/2013--11:02 PM ==> Error! CDEnumDeviceReset C0000F1
5/2/2013--11:02 PM ==> Error! CDFinishSDK C0000F1

Then i downloaded the second file which is 298kb and he gave me this error now.

The exception is on CAMERS.cs on line number 929:

err = (UInt32)cdAPI.CDStartSDK(ref Version, 0);

This is a link to my solution/project on my SkyDrive updated including two directores:

CDSDK1 and CDSDK2 in each there is the cdsdk.dll file one is 928kb or so and other 300kb or so.

Each one give a different error.

https://skydrive.live.com/redir?resid=EB1C71C44C3976D5!202&authkey=!AAe7QvxIzBMne1Q

The project name to download is: Canon_Camera_Control

This is the complete exception message for the secon CDSDK.dll file :

PInvokeStackImbalance was detected Message: A call to PInvoke function 'Canon_Camera_Control!RDC.CameraSDK.cdAPI::CDStartSDK' has unbalanced the stack. 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.

I googled so deep now and didn't find any clue/s about this error/s.

Santosh Panda
  • 7,235
  • 8
  • 43
  • 56
Yaron Cohen Minz
  • 127
  • 3
  • 15
  • Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature. Show us your declaration. – SLaks May 02 '13 at 21:05
  • 1
    I'm not an expert in pinvoking, but googling "pinvoke has unbalanced the stack", the three top hits were all here. Do any of these help? http://stackoverflow.com/questions/2941960/a-call-to-pinvoke-function-has-unbalanced-the-stack http://stackoverflow.com/questions/9855438/a-call-to-a-pinvoke-function-has-unbalanced-the-stack http://stackoverflow.com/questions/15255474/a-call-to-pinvoke-has-unbalanced-the-stack-dll-import-fails-even-with-cdecl – neminem May 02 '13 at 21:06
  • Here is a link to the CAMERA.cs code i'm not sure where is the declaration. http://pastebin.com/m9MvpfbE – Yaron Cohen Minz May 02 '13 at 21:09
  • I would suspect the calling convention to be the issue. – IAbstract May 02 '13 at 21:31

1 Answers1

0

You have the wrong p/invoke signature. Try unsing the P/Invoke Interop Assistant utility (http://clrinterop.codeplex.com/releases/view/14120) to automatically generate the correct marshalling attributes.

Scott Jones
  • 2,880
  • 13
  • 19