C#调用VC编写的DLL出现的问题

independently 2005-09-16 05:31:04
各位
我在C#.NET中调用VC编的DLL动态链接库,其中DLL中有一个含结构体的函数,我在C#中如何调用?以下我是这样做的,
C#声明:
[DllImport("gprsdll.dll",EntryPoint="DSGetModemByPosition"]
public static extern int DSGetModemByPosition(int pos,ref modem_information infor);//返回为1成功,其中modem_information为结构体,其类型为
public struct modem_information
{public uint modem_id; //modem ID号
public byte[] phone_num; / 号码
public UInt32 connect_time;//登陆时间
public UInt32 refresh_time;//刷新时间
public byte[] dynamic_ip;//动态地址
}
我在调用时先定义了一个结构体对象,并对其初始化
modem_information modem=new modem_information();
modem.dynamic_ip=new byte[4];
modem.phone_num=new byte[12];
int success=my.DSGetModemByPosition(i,ref modem);
my为DSGetModemByPosition所在的一个类的对象
dll中DSGetModemByPosition是这样定义的:
struct __POSITION { };
typedef __POSITION* POSITION;
int DSGetModemByPosition(int pos,ModemInfoStruct * modeminfor)//ModemInfoStruct为结构体,其定义类型与上述C#定义一样的
int DSGetModemByPosition(int modempos, ModemInfoStruct *pModemInfo)
{
//这个操作应当是互斥的
//todo_edw
int inx=0;

POSITION pos;
if (modempos<glstPtrModemInfoStructs.GetCount())
{
ModemInfoStruct*pMi;
// pMi=glstPtrModemInfoStructs.GetAt(pos);
POSITION pos;
pos=glstPtrModemInfoStructs.GetHeadPosition();
while(pos!=NULL)
{
pMi=glstPtrModemInfoStructs.GetAt(pos);
if (inx==modempos)
{
break;
}

inx++;
glstPtrModemInfoStructs.GetNext(pos);
}

memcpy(pModemInfo,pMi,sizeof(*pModemInfo));
return 1;
}
else
{
guiLastError=ERR_MODEMNOTFOUND;
return 0;
}
}
到最后编译时DSGetModemByPosition总是通不过
那位大侠指点下,我错在哪里 ???
...全文
102 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
JasonHeung 2005-09-16
  • 打赏
  • 举报
回复
public static extern int DSGetModemByPosition(int pos,ref byte[] modem_information infor);//
independently 2005-09-16
  • 打赏
  • 举报
回复
dll中结构体ModemInfoStruct定义如下:
typedef struct _modem_info_t_
{
long m_modemId; //Modem模块的ID号
int m_phoneno[12]; //Modem的11位电话号码,必须以'\0'字符结尾
char m_dynip[4]; //Modem的4位动态ip地址
long m_conn_time; //Modem模块最后一次建立TCP连接的时间
long m_refresh_time; //Modem模块最后一次收发数据的时间
} ModemInfoStruct;

110,534

社区成员

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

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

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