c# 调用DLL问题 在线等!!!

toliyuequn126com 2011-02-22 02:55:35
我现在有个开发商提供的动态链接库,SMSDLL.dll,收发短信用的。
里面的函数包括:
#pragma once
typedef struct _sms_report_t_
{
DWORD index; //短消息编号:index,从0开始递增
char Msg[256]; //短信内容
int Success; //是否发送成功 0为失败,非0为成功
char PhoneNo[32]; //目标手机号码
} SMSReportStruct;

typedef struct _sms_msg_t_
{
char Msg[256]; //短信内容
char PhoneNo[32]; //对方手机号码
char ReceTime[32]; //接收时间
} SMSMessageStruct;


//启动服务,打开串口,初始化Modem, 0为失败,非0为成功
//校验位, EvenParity :0,MarkParity:1,NoParity:2,OddParity:3,SpaceParity,4
//停止位 OneStopBit 0,OnePointFiveStopBits:1,TwoStopBits 2
//流控:NoFlowControl:0, CtsRtsFlowControl:1, CtsDtrFlowControl:2, DsrRtsFlowControl:3, DsrDtrFlowControl:4, XonXoffFlowControl:5
int _stdcall SMSStartService(int nPort,DWORD BaudRate = 57600, int Parity=2, int DataBits = 8,int StopBits=0,int FlowControl=0,char* csca="card");


//停止服务,并关闭串口,0为失败,非0为成功
int _stdcall SMSStopSerice();

//发送短消息,返回短消息编号:index,从0开始递增,该函数不会阻塞,立既返回,请用函数SMSQuery(DWORD index)来查询是否发送成功
DWORD _stdcall SMSSendMessage(char* Msg,char* PhoneNo);


//报告短信发送壮态(成功与否)0为有报告,非0为无
int _stdcall SMSReport(SMSReportStruct* rept);



//查询指定序号的短信是否发送成功(该序号由SMSSendMessage返回)
//返回 0 表示发送失败
// 1 表示发送成功
// -1 表示没有查询到该序号的短信,可能仍在发送中。
int _stdcall SMSQuery(DWORD index);


//接收短信,0为有短信,非0为无
int _stdcall SMSGetNextMessage(SMSMessageStruct* Msg);


//返回错误内容的长度
int _stdcall SMSGetLastError(char* err);


这些函数和结构体 我怎么才能在c# winform中使用啊?
...全文
148 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
toliyuequn126com 2011-02-23
  • 打赏
  • 举报
回复
问题解决了 感谢各位了!
toliyuequn126com 2011-02-23
  • 打赏
  • 举报
回复
int _stdcall SMSStartService(int nPort,DWORD BaudRate = 57600, int Parity=2, int DataBits = 8,int StopBits=0,int FlowControl=0,char* csca="card"); 怎么调用啊?



[DllImport("SMSDLL.dll")]
private static extern int SMSStartService(int nPort, long BaudRate, int Parity, int DataBits, int StopBits, int FlowControl, string csca);
大头_衍 2011-02-22
  • 打赏
  • 举报
回复
楼上的说的都不错。
yalan 2011-02-22
  • 打赏
  • 举报
回复
只知道使用[DllImport("要调用的DLL.dll")]来调用DLL,而且你还要知道要调用的DLL文件的接口信息,否则无法使用。
bdmh 2011-02-22
  • 打赏
  • 举报
回复

struct SMSReportStruct
{
uint index; //短消息编号:index,从0开始递增
[MarshalAs(UnmanagedType.ByValArray ,SizeConst=256)]
public char[] Msg; //短信内容
int Success; //是否发送成功 0为失败,非0为成功
[MarshalAs(UnmanagedType.ByValArray ,SizeConst=32)]
public char[] PhoneNo; //目标手机号码
}

struct SMSMessageStruct
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
public char[] Msg; //短信内容
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
public char[] PhoneNo; //对方手机号码
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
public char[] ReceTime; //接收时间
}

[DllImport("c:\\SMSDLL.dll")]
protected static extern uint SMSSendMessage(string Msg,string PhoneNo);

[DllImport("c:\\SMSDLL.dll")]
protected static extern int SMSReport(ref SMSReportStruct rept);

[DllImport("c:\\SMSDLL.dll")]
protected static extern int SMSQuery(uint index);

[DllImport("c:\\SMSDLL.dll")]
protected static extern int SMSGetNextMessage(ref SMSMessageStruct Msg);

[DllImport("c:\\SMSDLL.dll")]
protected static extern int SMSGetLastError(string err);
lvfeng19806001 2011-02-22
  • 打赏
  • 举报
回复
百度一下就能自己解决的
林小白 2011-02-22
  • 打赏
  • 举报
回复
通过DllImport来调用DLL。
如:[DllImport("user32.dll")],导入System.Runtime.InteropServices名称空间。
该名称空间包含了在C#中调用API的一些必要集合。
比如:(注销计算机)
[DllImport("user32.dll")]
private static extern int ExitWindowsEx(int uFlags, int dwReserved);
"DllImport"属性用来从不可控代码中调用一个方法,它指定了DLL的位置,该DLL中包含调用的外部方法
使用DllImport导入的方法必须使用"extern"修饰符。

110,538

社区成员

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

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

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