C++动态库的功能是发送和接受短信,SendSmsMessage函数是发送短信。C++动态库结构体:
typedef struct {
char SCA[16]; // 短消息服务中心号码(SMSC地址)
char TPA[16]; // 目标号码或回复号码(TP-DA或TP-RA)
char TP_PID; // 用户信息协议标识(TP-PID) (0,1)
char TP_DCS; // 用户信息编码方式(TP-DCS) (0,4,8)
char TP_SCTS[16]; // 服务时间戳字符串(TP_SCTS), 接收时用到
char TP_UD[160]; // 原始用户信息(编码前或解码后的TP-UD)
short index; // 短消息序号,在读取时用到
} SM_PARAM;C++动态库函数:
int __stdcall SendSmsMessage(SM_PARAM* pSrc);在C#中如下定义结构体:
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi,Pack =1)]
public class SM_PARAM
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
public string SCA; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
public string TPA; public char TP_PID;
public char TP_DCS;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
public string TP_SCTS;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 160)]
public string TP_UD;
public short index;
}C#中引入C++动态库:
[DllImport("SmsDll.dll")]
public static extern int SendSmsMessage(ref SM_PARAM pSrc);C#调用动态库函数:
SM_PARAM sms = new SM_PARAM();
sms.TP_PID = '0';
sms.TP_DCS = '8';
sms.index = 1;
sms.SCA = "8613010163500";
sms.TPA = "86139********";
sms.TP_SCTS = "";
sms.TP_UD = "测试短信,请勿回复";
int ret = SendSmsMessage(ref sms);
问题:调用成功时ret应该返回0,现在的情况是ret返回值不是0,而且短信也发送不出去,请问是哪个地方出现了问题,请高人指点.
typedef struct {
char SCA[16]; // 短消息服务中心号码(SMSC地址)
char TPA[16]; // 目标号码或回复号码(TP-DA或TP-RA)
char TP_PID; // 用户信息协议标识(TP-PID) (0,1)
char TP_DCS; // 用户信息编码方式(TP-DCS) (0,4,8)
char TP_SCTS[16]; // 服务时间戳字符串(TP_SCTS), 接收时用到
char TP_UD[160]; // 原始用户信息(编码前或解码后的TP-UD)
short index; // 短消息序号,在读取时用到
} SM_PARAM;C++动态库函数:
int __stdcall SendSmsMessage(SM_PARAM* pSrc);在C#中如下定义结构体:
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi,Pack =1)]
public class SM_PARAM
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
public string SCA; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
public string TPA; public char TP_PID;
public char TP_DCS;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
public string TP_SCTS;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 160)]
public string TP_UD;
public short index;
}C#中引入C++动态库:
[DllImport("SmsDll.dll")]
public static extern int SendSmsMessage(ref SM_PARAM pSrc);C#调用动态库函数:
SM_PARAM sms = new SM_PARAM();
sms.TP_PID = '0';
sms.TP_DCS = '8';
sms.index = 1;
sms.SCA = "8613010163500";
sms.TPA = "86139********";
sms.TP_SCTS = "";
sms.TP_UD = "测试短信,请勿回复";
int ret = SendSmsMessage(ref sms);
问题:调用成功时ret应该返回0,现在的情况是ret返回值不是0,而且短信也发送不出去,请问是哪个地方出现了问题,请高人指点.
解决方案 »
- 将数据导入到excel 2007的问题
- C# webBrowser 控件 怎么模拟点击网页上的图片
- 请教关于datagridview编辑单元格的问题
- 如何把textbox.text转成StringBuilder类型的呢?
- C#的继承问题
- ◆◆◆◆◆通用问题,为什么用Excel控件导出的Excel工作薄不能用汇总功能?◆◆◆◆◆
- IIS配置问题
- 关于web.config的问题
- 为什么用.Net的Socket写的聊天程序,智能在一台机器上聊?两台机器就连不上了哪?
- 我不用父类的虚方法ttt(),所以在子类tt中,我不对ttt()重载应该是可以的,可是怎么通不过编译!
- C#中获取文本框的值的问题
- 请教:Chart波形图内光标的实现
C#里的char占俩字节.
你把那俩char改为byte试试
改成byte的话,其他的好说,关于短信内容的char TP_UD[160],短信内容是中文,怎么给它赋值?