' CallbackOnCollectedDelegate'已经在委托摄像头中检测到互动

时间:2015-03-27 16:01:49

标签: c# callback delegates

我正在使用应用程序与扫描仪交互,我的应用程序出了问题:

托管调试助手'CallbackOnCollectedDelegate'检测到'Program.exe'中存在问题。 附加信息:对“Program!Plustek_Camera.PFNCK_EVENT :: Invoke”类型的垃圾收集委托进行了回调。这可能会导致应用程序崩溃,损坏和数据丢失。将委托传递给非托管代码时,托管应用程序必须将它们保持活动状态,直到确保它们永远不会被调用为止。

这是我的代码:

使用System; 使用System.Runtime.InteropServices;

命名空间Plustek_Camera {     public enum CAMERA_CONST     {         MAX_PATH = 260     }

public enum CAMERA_EVENT
{
    CAMERA_EVENT_CAPTURE = 0,
    CAMERA_EVENT_STATUS
}

public enum CAMERA_TYPE
{
    CAMERA_TYPE_PASSPORT = 0,
    CAMERA_TYPE_IDCARD
}

public enum CAMERA_STATUS
{
    CAMERA_STATUS_START = 0,
    CAMERA_STATUS_STOP,
    CAMERA_STATUS_IDBACK_START,
    CAMERA_STATUS_IDBACK_STOP,
    CAMERA_STATUS_DEVICE_PLUG,
    CAMERA_STATUS_DEVICE_UNPLUG
}

public enum CAMERA_CAPTUREMODE
{
    CAMERA_CAPTUREMODE_GIU = 0,
    CAMERA_CAPTUREMODE_GI,
    CAMERA_CAPTUREMODE_GU,
    CAMERA_CAPTUREMODE_G
}

public enum CAMERA_DPI
{
    CAMERA_DPI_300 = 0,
    CAMERA_DPI_600
}

public enum CAMERA_FORMAT
{
    CAMERA_FORMAT_JPG = 0,
    CAMERA_FORMAT_BMP
}

public enum CAMERA_ALIGN
{
    CAMERA_ALIGN_LEFT = 0,
    CAMERA_ALIGN_RIGHT
}

[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct CAPTURE_NAME
{
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = (int)CAMERA_CONST.MAX_PATH)]
    public char[] szGeneral;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = (int)CAMERA_CONST.MAX_PATH)]
    public char[] szIR;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = (int)CAMERA_CONST.MAX_PATH)]
    public char[] szUV;
}

[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct CAPTURE_PARAM
{
    public Boolean bLeft;
    public UInt16 wCaptureMode;
    public UInt16 wDpi;
    public UInt16 wFormat;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = (int)CAMERA_CONST.MAX_PATH)]
    public char[] szSaveFolder;
}

[StructLayout(LayoutKind.Sequential, Pack = 1)]
public class CAMERA_INFO
{
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 60)]
    public Char[] Name;
    public UInt16 wIndex;
}

[StructLayout(LayoutKind.Sequential, Pack = 1)]
public class CAMERA_LIST
{
    public UInt16 wCount;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)]
    //      public  CAMERA_INFO[]   Caps;
    public IntPtr[] Caps;
}

public delegate Boolean PFNCK_EVENT(int iEvent, int iParam, IntPtr pUserData);

public delegate Boolean pfnRegister();
public delegate Boolean pfnUnregister();
public delegate Boolean pfnGetCameraList(ref CAMERA_LIST ppList);
public delegate Boolean pfnSetCamera(String lpName, PFNCK_EVENT pfn, IntPtr pUserData);
public delegate Boolean pfnCloseCamera();
public delegate Boolean pfnSetCaptureComplete(Boolean bFlag);
public delegate Boolean pfnSetIDBack(Boolean bFlag);
public delegate Boolean pfnSetParam(CAPTURE_PARAM Param);

[StructLayout(LayoutKind.Sequential)]
public class CAMERA_FUNCTION_TABLE
{
    [MarshalAs(UnmanagedType.FunctionPtr)]
    public pfnRegister Register;
    [MarshalAs(UnmanagedType.FunctionPtr)]
    public pfnUnregister Unregister;
    [MarshalAs(UnmanagedType.FunctionPtr)]
    public pfnGetCameraList GetCameraList;
    [MarshalAs(UnmanagedType.FunctionPtr)]
    public pfnSetCamera SetCamera;
    [MarshalAs(UnmanagedType.FunctionPtr)]
    public pfnCloseCamera CloseCamera;
    [MarshalAs(UnmanagedType.FunctionPtr)]
    public pfnSetCaptureComplete SetCaptureComplete;
    [MarshalAs(UnmanagedType.FunctionPtr)]
    public pfnSetIDBack SetIDBack;
    [MarshalAs(UnmanagedType.FunctionPtr)]
    public pfnSetParam SetParam;
}

public delegate CAMERA_FUNCTION_TABLE CAMERA_FN_GET_FUNCTION_TABLE();

public class CAMERA_API
{
    public string CAMERA_NAME_LIBRARY = "Camera.dll";
    public string CAMERA_NAME_LIBRARY_ENTRY = "CAMERA_GetFunctionTable";
}

}

当我打电话给其他人时:

var startCam = m_pfnCamera.SetCamera(“X100”,fnCamera,IntPtr.Zero); //从这里得到错误

fnCamera是回调函数

0 个答案:

没有答案