错误调用函数,[A调用PInvoke的功能失衡堆栈] [英] error calling function ,[A call to PInvoke function unbalanced the stack]

查看:551
本文介绍了错误调用函数,[A调用PInvoke的功能失衡堆栈]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下code,有一次,我跑我的应用程序,我得到这个错误

任何人都知道我是如何解决这个问题?

ERROR:

要PInvoke的函数调用testcamera!EDSDKLib.EDSDK :: EdsDownloadEvfImage有不平衡的堆栈。这可能是因为管理的PInvoke签名也非托管的目标签名不匹配。检查调用约定和的PInvoke签名的参数匹配目标非托管签名

  IntPtr的cameraDev;
            布尔LVrunning = FALSE;
            UINT ERR = EDSDK.EDS_ERR_OK;
            UINT装置= 0;
            IntPtr的MemStreamRef =新的IntPtr(0);

            IntPtr的EvfImageRef =新的IntPtr(0);
            图片框pbLV;

            公众的LiveView(IntPtr的C,图片框P)
            {
                cameraDev = C;
                pbLV = P;
            }

            内部空隙StartLiveView()
            {
                // LVrunning = TRUE;
                // INT I = 0;

                //获取输出设备进行实时显示图像
                ERR = EDSDK.EdsGetPropertyData(cameraDev,EDSDK.PropID_Evf_OutputDevice,0,出设备);
                Debug.WriteLineIf(!ERR = EDSDK.EDS_ERR_OK,的String.Format(获取属性数据失败:{0:X},ERR));
                Debug.WriteLineIf(ERR == EDSDK.EDS_ERR_OK,的String.Format(实时查看输出为:{0:X},设备));

                Thread.sleep代码(1000);

                //设置计算机实时取景目的地
                如果(ERR == EDSDK.EDS_ERR_OK)
                {
                    ERR = EDSDK.EdsSetPropertyData(cameraDev,EDSDK.PropID_Evf_OutputDevice,0,
                        Marshal.SizeOf(EDSDK.EvfOutputDevice_PC),EDSDK.EvfOutputDevice_PC);
                    的Debug.WriteLine(的String.Format(实时查看输出到电脑:{0:X},ERR));
                }

                //创建画面内存流
                如果(ERR == EDSDK.EDS_ERR_OK)
                {
                    ERR = EDSDK.EdsCreateMemoryStream(0,出MemStreamRef);
                    的Debug.WriteLine(的String.Format(创建内存流:{0:X},ERR));
                }

                //获取一个引用EvfImage

                如果(ERR == EDSDK.EDS_ERR_OK)
                {

** //我这里得到错误**
                     ** ERR = EDSDK.EdsCreateEvfImageRef(MemStreamRef,出EvfImageRef)**

                    的Debug.WriteLine(的String.Format(创建EVF Imaage编号:{0:X},ERR));
                }

                Thread.sleep代码(2000);
            }
 

解决方案

请使用CDECL为该函数的调用约定。不要问我为什么,它只是工作。

  [的DllImport(EDSDK.dll,CallingConvention = CallingConvention.Cdecl)
公众的extern静态UINT EdsCreateEvfImageRef(IntPtr的inStreamRef,出来的IntPtr outEvfImageRef);

[的DllImport(EDSDK.dll,CallingConvention = CallingConvention.Cdecl)
公众的extern静态UINT EdsDownloadEvfImage(IntPtr的inCameraRef,IntPtr的outEvfImageRef);
 

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!EDSDKLib.EDSDK::EdsDownloadEvfImage' 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

 IntPtr cameraDev;
            bool LVrunning = false;
            uint err = EDSDK.EDS_ERR_OK;
            uint device = 0;
            IntPtr MemStreamRef = new IntPtr(0);

            IntPtr EvfImageRef = new IntPtr(0);
            PictureBox pbLV;

            public LiveView(IntPtr c, PictureBox p)
            {
                cameraDev = c;
                pbLV = p;
            }

            internal void StartLiveView()
            {
                //LVrunning = true;
                //int i = 0;

                // Get the output device for the live view image
                err = EDSDK.EdsGetPropertyData(cameraDev, EDSDK.PropID_Evf_OutputDevice, 0, out device);
                Debug.WriteLineIf(err != EDSDK.EDS_ERR_OK, String.Format("Get Property Data failed: {0:X}", err));
                Debug.WriteLineIf(err == EDSDK.EDS_ERR_OK, String.Format("Liveview output is: {0:x}", device));

                Thread.Sleep(1000);

                // Set the computer as live view destination
                if (err == EDSDK.EDS_ERR_OK)
                {
                    err = EDSDK.EdsSetPropertyData(cameraDev, EDSDK.PropID_Evf_OutputDevice, 0,
                        Marshal.SizeOf(EDSDK.EvfOutputDevice_PC), EDSDK.EvfOutputDevice_PC);
                    Debug.WriteLine(String.Format("Liveview output to computer: {0:X}", err));
                }

                // Create a memory stream for the picture
                if (err == EDSDK.EDS_ERR_OK)
                {
                    err = EDSDK.EdsCreateMemoryStream(0, out MemStreamRef);
                    Debug.WriteLine(String.Format("Create Memory Stream: {0:X}", err));
                }

                // Get a reference to a EvfImage

                if (err == EDSDK.EDS_ERR_OK)
                {

**//i get error here**
                     **err = EDSDK.EdsCreateEvfImageRef(MemStreamRef, out EvfImageRef);** 

                    Debug.WriteLine(String.Format("Create Evf Imaage Ref: {0:X}", err));
                }

                Thread.Sleep(2000);
            }

解决方案

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);   

这篇关于错误调用函数,[A调用PInvoke的功能失衡堆栈]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆