日期:2014-05-17  浏览次数:21247 次

C# 调用C++ 回调函数成功后 卡死
public enum MPRDeviceEvent
{
    PLUGED_IN,           //设备插入
    PLUGED_OUT,          //设备设备拔出
    MPR_CODE_CAPTURED,   //点读了一个MPR码
    POWER_KEY_PRESSED,   //POWER键被按下
    UP_KEY_PRESSED,      //音量+键被按下
    DOWN_KEY_PRESSED     //音量-键被按下
}

private static void ProcessMPRDeviceEvent(MPRDeviceEvent mrpevent, IntPtr p_data, int data_len)
{
    switch (mrpevent)
    {
        case MPRDeviceEvent.MPR_CODE_CAPTURED:
            {
                byte[] byteCode = new byte[data_len];
                Marshal.Copy(p_data, byteCode, 0, data_len);
                Marshal.Release(p_data);
                string strCode = string.Empty;
                for (int i = 0; i < data_len; i++)
                {
                    strCode += byteCode[i].ToString("X");
                }
                _Lable.Text = strCode;
                break;
            }
    }
}

public delegate void DelegateMPRCallBack(MPRDeviceEvent mrpevent, IntPtr p_data, int data_len);

public static System.Windows.Forms.Label _Lable;

static DelegateMPRCallBack _CallBack;

[DllImport("MPRDeviceAPI.dll")]
public static extern int MPRDevice_InitLib(DelegateMPRCallBack callBack);

public static bool Start(System.Windows.Forms.Label lable)