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

多啦A孟 2012-07-05 11:09:58

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



//机构体定义
[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;
}

}

...全文
105 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
多啦A孟 2012-07-27
  • 打赏
  • 举报
回复
我用别的办法实现了,不想试了,o(︶︿︶)o 唉,谢谢
vinjent 2012-07-06
  • 打赏
  • 举报
回复
unsigned char*在C#中宣告
[MarshalAs(UnmanagedType.LPTStr)]byte[]
or
ref byte[]

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧