首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

C#调用C++的DL报未知错误

2012-09-01 
C#调用C++的DL报未知异常C/C++ code//DLL中的函数声明//app传入//buffer 传出ISO8583DLL_API int Pack_Ex

C#调用C++的DL报未知异常

C/C++ code
//DLL中的函数声明//app传入//buffer 传出ISO8583DLL_API int Pack_Ex (application*  app,unsigned char * buffer );


C# code
//机构体定义        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]        internal struct Application_Ex        {            public static Application_Ex InitShuZu()            {                Application_Ex obj = new Application_Ex();                obj.process_code = new byte[5];                obj.trans_type = new byte[3];                obj.park_id = new byte[PARK_ID_LENGTH + 1];                obj.terminal_id = new byte[TERMINAL_ID_LENGTH + 1];             //.............               //内容太多,没有贴完            }            //     package               public byte[] source_tpdu ;                     public byte[] target_tpdu ;                    public byte itrans_type;                    public byte[] trans_type ;                 //.............               //内容太多,没有贴完        }//DLL函数导出        [DllImport("ISO8583Dll.dll", EntryPoint = "Pack_Ex")]        private static extern int Pack_Ex(Application_Ex app_ex, byte[] buff);//函数调用        unsafe public static void jgtdy()        {            Application_Ex m_txd = new Application_Ex();            m_txd = Application_Ex.InitShuZu();             try            {                //赋值                m_txd.process_code[0] = (byte)'0';                m_txd.process_code[1] = (byte)'0';                m_txd.process_code[2] = (byte)'0';                m_txd.process_code[3] = (byte)'6';                m_txd.trans_type[0] = (byte)'8';                m_txd.trans_type[1] = (byte)'1';                //010101009001                m_txd.park_id[0] = (byte)'0';                m_txd.park_id[1] = (byte)'1';                m_txd.park_id[2] = (byte)'0';                m_txd.park_id[3] = (byte)'1';                m_txd.park_id[4] = (byte)'0';                m_txd.park_id[5] = (byte)'1';                m_txd.park_id[6] = (byte)'0';                m_txd.park_id[7] = (byte)'0';                m_txd.park_id[8] = (byte)'9';                m_txd.park_id[9] = (byte)'0';                m_txd.park_id[10] = (byte)'0';                m_txd.park_id[11] = (byte)'1';                //02010001                m_txd.terminal_id[0] = (byte)'0';                m_txd.terminal_id[1] = (byte)'2';                m_txd.terminal_id[2] = (byte)'0';                m_txd.terminal_id[3] = (byte)'1';                m_txd.terminal_id[4] = (byte)'0';                m_txd.terminal_id[5] = (byte)'0';                m_txd.terminal_id[6] = (byte)'0';                m_txd.terminal_id[7] = (byte)'1';                //20120420                m_txd.trans_date[0] = (byte)'2';                m_txd.trans_date[1] = (byte)'0';                m_txd.trans_date[2] = (byte)'1';                m_txd.trans_date[3] = (byte)'2';                m_txd.trans_date[4] = (byte)'0';                m_txd.trans_date[5] = (byte)'4';                m_txd.trans_date[6] = (byte)'2';                m_txd.trans_date[7] = (byte)'0';                //005006                m_txd.trans_time[0] = (byte)'0';                m_txd.trans_time[1] = (byte)'0';                m_txd.trans_time[2] = (byte)'5';                m_txd.trans_time[3] = (byte)'0';                m_txd.trans_time[4] = (byte)'0';                m_txd.trans_time[5] = (byte)'6';                //000100                m_txd.lsh = 000100;                m_txd.host_lsh = 000000000000;                //000101                m_txd.batch_no = 000101;                m_txd.amount = 000000000000;                //0033                m_txd.para_ver = 0033;                //2012040400                m_txd.fee_id[0] = (byte)'2';                m_txd.fee_id[1] = (byte)'0';                m_txd.fee_id[2] = (byte)'1';                m_txd.fee_id[3] = (byte)'2';                m_txd.fee_id[4] = (byte)'0';                m_txd.fee_id[5] = (byte)'4';                m_txd.fee_id[6] = (byte)'0';                m_txd.fee_id[7] = (byte)'4';                m_txd.fee_id[8] = (byte)'4';                m_txd.fee_id[9] = (byte)'0';                m_txd.fee_id[10] = (byte)'0';                m_txd.prog_ver = 0000;                //01080001                m_txd.oper_id[0] = (byte)'0';                m_txd.oper_id[1] = (byte)'1';                m_txd.oper_id[2] = (byte)'0';                m_txd.oper_id[3] = (byte)'8';                m_txd.oper_id[4] = (byte)'0';                m_txd.oper_id[5] = (byte)'0';                m_txd.oper_id[6] = (byte)'0';                m_txd.oper_id[7] = (byte)'1';                //0101                m_txd.oper_pwd[0] = (byte)'0';                m_txd.oper_pwd[1] = (byte)'1';                m_txd.oper_pwd[2] = (byte)'0';                m_txd.oper_pwd[3] = (byte)'1';                //0001                //m_txd.mac[0]=0x20;                for (int i = 0; i < 8; i++)                {                    m_txd.mac[i] = 0x20;                }                m_txd.park_ver[0] = (byte)'0';                m_txd.park_ver[1] = (byte)'0';                m_txd.park_ver[2] = (byte)'0';                m_txd.park_ver[3] = (byte)'1';                //0102                m_txd.oper_ver[0] = (byte)'0';                m_txd.oper_ver[1] = (byte)'1';                m_txd.oper_ver[2] = (byte)'0';                m_txd.oper_ver[3] = (byte)'2';                byte[] buf = new byte[100];                int nlen = Pack_Ex(m_txd, buf);//执行到这里报异常NotSupportedException            }            catch (System.Exception ex)            {                string exstr = ex.Message;            }        } 




[解决办法]
unsigned char*在C#中宣告
[MarshalAs(UnmanagedType.LPTStr)]byte[]
or
ref byte[]

热点排行