小弟手头有一活,底层都是vc开发的,现在用c#来调用
未曾研究过vc,初次调用出错,在线急等解决方案
vc方法签名如下LPRENGINE_API LPRRESULT __stdcall InitLPREngineParamHelper( LPREngineParam* pParam, int maxPlate, int minPlateW, int maxPlateW,
int chnRegion, LPRRatioRect recogRegion, int speed, bool bCapture, bool bAdaptiveFP, bool bEnableLowConfid );其中包含结构体struct LPREngineParam
{
int size;
LPRParam lprParam;
LPRRatioRect recogRegion; LPRRatioLine line1;
LPRRatioLine line2; int maxSkip;
float minValid;
float minConfid; int framePercent;
bool bAdaptiveFP;
int  motionDetectionMode;
bool bCapture;
         int minCaptureDiff;
LPRRatioRect    preferCapRegion;
};
我在C#下是这样实现的
定了一结构体如下public struct LPREngineParam
    {
        public int size;
        public LPRParam lprPrarm;
        public LPRRatioRect recogRegion;
        public LPRRatioLine line1;
        public LPRRatioLine line2;
        public int maxSkip;
        public float minValid;
        public float minConfid;
        public int framePercent;
        public bool bAdapticeFP;
        public int motionDetectionMode;
        public bool bCapture;
        public int minCaptureDiff;
        public LPRRatioRect preferCapRegion;
    }
创建方法申明为        [DllImport("LPREngine.dll", CharSet = CharSet.Auto)]
        public static extern long InitLPREngineParamHelper(LPREngineParam pParam, 
            int maxplate, int minPlateW, int maxPlateW, int chnRegion, LPRRatioRect recogRegion, 
            int speed, bool bCapture, bool bAdaptiveFP, bool bEnableLowConfid);
出现异常为对 PInvoke 函数“PCDLLTest!PCDLLTest.Form1::InitLPREngineParamHelper”的调用导致堆栈不对称。原因可能是托管的 PInvoke 签名与非托管的目标签名不匹配。请检查 PInvoke 签名的调用约定和参数与非托管的目标签名是否匹配。不好意思没分送大家了

解决方案 »

  1.   

    1, In general, LP... is used to describe a pointer, so be careful not to mix them:    public struct LPREngineParam
        {
            public int size;
            public LPRParam lprPrarm;               // a pointer or a struct?
            public LPRRatioRect recogRegion;        // a pointer or a struct?
            public LPRRatioLine line1;
            public LPRRatioLine line2;
            public int maxSkip;
            public float minValid;
            public float minConfid;
            public int framePercent;
            public bool bAdapticeFP;
            public int motionDetectionMode;
            public bool bCapture;
            public int minCaptureDiff;
            public LPRRatioRect preferCapRegion;
        }2, another easy change you may try:
    [DllImport("LPREngine.dll", CharSet = CharSet.Auto)]
    public static extern long InitLPREngineParamHelper(ref LPREngineParam pParam, ...)According to C++ prototype, the first parameter must be a pointer, but LPREngineParam is a struct value.
      

  2.   

    不好意思
    忘记注明了LPRParam   //structLPRRatioRect    //struct