none
C#调用C++DLL出现NotSupportedException问题 RRS feed

  • 问题

  • C++源码:

    typedef DWORD (*pfnIsaIoByteR) (DWORD dwIoAddress,PUCHAR pucData);
    typedef DWORD (*pfnIsaIoByteW) (DWORD dwIoAddress,UCHAR ucData);
    typedef DWORD (*pfnIsaIoWordR) (DWORD dwIoAddress,PUINT16 pusData);
    typedef DWORD (*pfnIsaIoWordW) (DWORD dwIoAddress,UINT16 usData);
    typedef DWORD (*pfnIsaInitSysIrq) (DWORD dwIRQNumber,
    						          HANDLE hIntrEvent,
    							  PDWORD pdwSysIntr);
    typedef DWORD (*pfnIsaDisableSysIrq) (DWORD dwSysIntrNumber);
    typedef DWORD (*pfnIsaReEnableSysIrq) (DWORD dwSysIntrNumber);
    
    /*********************************************************************************************************
    ** PCM-8208BT和PCM-8208BS 设备信息结构体
    *********************************************************************************************************/	
    typedef struct _tagZWADEVINFO {
    	DWORD dwDevType;/*  设备型号*/
    	DWORD dwDevAddr;/*  设备基地址*/
    	DWORD dwIrqNo;/*  IRQ中断号*/
    } ZWADEVINFO,*LPZWADEVINFO;
    
    typedef struct _tagZWAPFN { 
    pfnIsaIoByteR   lpfnIsaIoByteR;        /*  I/O空间读一字节函数   */ 
    pfnIsaIoByteW   lpfnIsaIoByteW;        /*  I/O空间写一字节函数   */ 
    pfnIsaIoWordR   lpfnIsaIoWordR;        /*  I/O空间读一半字函数   */ 
    pfnIsaIoWordW   lpfnIsaIoWordW;        /*  I/O空间写一半字函数   */ 
    pfnIsaInitSysIrq  lpfnIsaInitSysIrq;       /*  初始化系统中断    */ 
    pfnIsaDisableSysIrq  lpfnIsaDisableSysIrq;      /*  禁止系统中断    */ 
    pfnIsaReEnableSysIrq lpfnIsaReEnableSysIrq;      /*  重新使能系统中断   */} ZWAPFN,*LPZWAPFN;
    
    
    ZWAPCM8208BTBSDRV_API DWORD ZWA_DeviceOpen(LPZWADEVINFO pstDevInfo,LPZWAPFN pstIsaFn,HANDLE *phDevHandle);

    C#中的结构:

      

    public delegate uint pfnIsaIobyteR(uint dwIoAddress, out  byte pucData);
    public delegate uint pfnIsaIobyteW(uint dwIoAddress, byte ucData);
    public delegate uint pfnIsaIoWordR(uint dwIoAddress, out  ushort pusData);
    public delegate uint pfnIsaIoWordW(uint dwIoAddress, ushort usData);
    public delegate uint pfnIsaInitSysIrq(uint dwIRQNumber,
                                           System.IntPtr hIntrEvent,
                                           ref uint pdwSysIntr);
    public delegate uint pfnIsaDisableSysIrq(uint dwSysIntrNumber);
    public delegate uint pfnIsaReEnableSysIrq(uint dwSysIntrNumber);

    /********************************************************************************************************* ** PC/104总线操作接口函数指针 *********************************************************************************************************/ [StructLayout(LayoutKind.Sequential)] public struct ZWAPFN { public pfnIsaIobyteR lpfnIsaIoByteR; /* I/O空间读一字节函数指针 */ public pfnIsaIobyteW lpfnIsaIoByteW; /* I/O空间写一字节函数指针 */ public pfnIsaIoWordR lpfnIsaIoWordR; /* I/O空间读一半字函数指针 */ public pfnIsaIoWordW lpfnIsaIoWordW; /* I/O空间写一半字函数指针 */ public pfnIsaInitSysIrq lpfnIsaInitSysIrq; /* 初始化系统中断函数指针 */ public pfnIsaDisableSysIrq lpfnIsaDisableSysIrq; /* 禁止系统中断函数指针 */ public pfnIsaReEnableSysIrq lpfnIsaReEnableSysIrq; /* 重新使能系统中断函数指针 */ } ; /********************************************************************************************************* ** PCM-8032A 设备信息结构体 *********************************************************************************************************/ [StructLayout(LayoutKind.Sequential)] public struct ZWADEVINFO { public uint dwDevType; /* 设备型号 */ public uint dwDevAddr; /* 设备基地址 */ public uint dwIrqNo; /* IRQ中断号 */ } ; [System.Runtime.InteropServices.DllImport("ZwaPCM8208BTBSDrv")] public static extern uint ZWA_DeviceOpen(ref ZWADEVINFO pstDevInfo, ref ZWAPFN pstIsaFn, out System.IntPtr phDevHandle);


    主程序调用:

           private void deviceOpenButton_Click(object sender, EventArgs e)
            {
                uint dwRet = 0;
                ZWADEVINFO stDevInfo = new ZWADEVINFO();/* 设备信息结构体变量 */
                ZWAPFN stpFnTmp = new ZWAPFN();/* PC/104总线操作函数指针结构体 */
                IntPtr m_hPCM8208BT;/* 接收设备操作句柄 */
    
                stDevInfo.dwDevType = (uint)DeviceType.PCM8208BTBS; /* 设备类型号 */
                stDevInfo.dwDevAddr = (uint)0x300; /* 设备基地址 */
                stDevInfo.dwIrqNo = (uint)DeviceIRQ.IRQ3; /* 设备使用的IRQ 物理中断号 */
    
                stpFnTmp.lpfnIsaIoByteR = new pfnIsaIobyteR(epcIsaLib.epcIsaIoByteR); /* 初始化PC/104 总线操作 */
                stpFnTmp.lpfnIsaIoByteW = new pfnIsaIobyteW(epcIsaLib.epcIsaIoByteW); /* 接口函数指针 */
                stpFnTmp.lpfnIsaIoWordR = new pfnIsaIoWordR(epcIsaLib.epcIsaIoWordR);
                stpFnTmp.lpfnIsaIoWordW = new pfnIsaIoWordW(epcIsaLib.epcIsaIoWordW);
                stpFnTmp.lpfnIsaInitSysIrq = new pfnIsaInitSysIrq(epcIsaLib.epcIsaInitIntrrupt);
                stpFnTmp.lpfnIsaDisableSysIrq = new pfnIsaDisableSysIrq(epcIsaLib.epcIsaIntrruptDisable);
                stpFnTmp.lpfnIsaReEnableSysIrq = new pfnIsaReEnableSysIrq(epcIsaLib.epcIsaIntrruptDone);
    
                dwRet = ZwaPCM8208BTBSDrvLib.ZWA_DeviceOpen(ref stDevInfo, ref stpFnTmp, out m_hPCM8208BT);
    
                if (dwRet != (uint)DeviceErrorCode.ERR_SUCCESS)
                {
                    MessageBox.Show("打开设备失败!");
                }
            }

    点击按钮时,调用DeviceOpen函数时就出现NotSupportedException错误,查不出来,求指教,急死我了

    任何杀不死我的困难只会让我更强大!!



    • 已编辑 杰心 2012年4月2日 8:53
    2012年4月2日 8:39

答案