各位牛人,求救啊!! 调用 vc的dll结构体指针?????

xiaozhigood 2008-07-04 09:44:04
1. int _stdcall TA_InqAcc(AccountMsg * pAccMsg, short TimeOut = 10);

入口参数: pAccMsg->AccountNo

pAccMsg->CardNo

pAccMsg-> StudentCode

pAccMsg->IDCard

pAccMsg-> StudentCode

TimeOut – 交易超时时间,缺省为10秒

出口参数: pAccMsg-从数据库中读出的帐户信息,包括Name、、SexNo、DeptCode、


备 注:pAccMsg->AccountNo、pAccMsg->CardNo、pAccMsg-> StudentCode、pAccMsg->IDCard这四个参数是选择查询条件,必须输入一个



typedef struct

{

char Name[21];

char SexNo[2];

char DeptCode[19];

unsigned int CardNo;

unsigned int AccountNo;



}pAccMsg


我在c#中定义如下:

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]
public struct AccountMsg
{

[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 21)]
public string Name;


[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 2)]
public string SexNo;


[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 19)]
public string DeptCode;

public uint CardNo;

public uint AccountNo;

}


[System.Runtime.InteropServices.DllImport("C:\\dll\\AIO_API.dll")]
public static extern int TA_InqAcc(ref pAccMsg, Int16 TimeOut);

我现在调用成功,
1、如果传一个不存在的AccountNo进去,返回不存在,
2、如果是存在的AccountNo但是提示错误是:无法为//分配的缓冲区太小,不能拷贝,

请问传地址怎么传??或者在c#要怎么实现”TA_InqAcc(AccountMsg * pAccMsg, short TimeOut = 10);“

...全文
73 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiaozhigood 2008-07-04
  • 打赏
  • 举报
回复
输入和输出都是通过 AccountMsg * pAccMsg
jeason1914 2008-07-04
  • 打赏
  • 举报
回复
指针,输入的用Ref,输出的Out
也可用[In]或者[Out]的Attribute

110,552

社区成员

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

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

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