我 将 动态库函数封装在类 mysms中,其声明如下: [DllImport("smspdu.dll")] public static extern int SendShortMessage( ref string send_number, ref string send_msg, ref class_SM_PARAM sm_param_temp) ; 结构体SM_PARAM 声明为 类的形式如下: public class class_SM_PARAM { char[] SCA = new char[16]; char[] TPA = new char[16]; char TP_PID; char TP_DCS; char[] TP_SCTS = new char[16]; char[] TP_UD = new char[161]; char index; } ; 实参调用如下: class_SM_PARAM sm_param_temp = new class_SM_PARAM() ; string hand="13911501865"; string content="this is a test"; int nResult=mysms.SendShortMessage( ref hand , ref content ,ref sm_param_temp);进入 调试 后 运行到SendShortMessage()该函数时,报错 无法封送 parameter #3:该类型的类型定义没有布局信息。
你怎么发两遍呢?[StructLayout(LayoutKind.Sequential)] struct SM_PARAM { [MarshalAs(UnmanagedType.ByValArray,SizeConst=16)] public char[] SCA; [MarshalAs(UnmanagedType.ByValArray,SizeConst=16)] public char[] TPA; public char TP_PID; public char TP_DCS; [MarshalAs(UnmanagedType.ByValArray,SizeConst=16)] public char[] TP_SCTS; [MarshalAs(UnmanagedType.ByValArray,SizeConst=161)] public char[] TP_UD; public char index; }如何调用见 ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.2052/cpguide/html/cpconstructssample.htm
[DllImport("smspdu.dll")] public static extern int SendShortMessage( ref string send_number, ref string send_msg, ref class_SM_PARAM sm_param_temp) ;
结构体SM_PARAM 声明为 类的形式如下:
public class class_SM_PARAM
{
char[] SCA = new char[16];
char[] TPA = new char[16];
char TP_PID;
char TP_DCS;
char[] TP_SCTS = new char[16];
char[] TP_UD = new char[161];
char index;
} ;
实参调用如下:
class_SM_PARAM sm_param_temp = new class_SM_PARAM() ;
string hand="13911501865";
string content="this is a test";
int nResult=mysms.SendShortMessage( ref hand , ref content ,ref sm_param_temp);进入 调试 后 运行到SendShortMessage()该函数时,报错
无法封送 parameter #3:该类型的类型定义没有布局信息。
struct SM_PARAM
{
[MarshalAs(UnmanagedType.ByValArray,SizeConst=16)]
public char[] SCA;
[MarshalAs(UnmanagedType.ByValArray,SizeConst=16)]
public char[] TPA;
public char TP_PID;
public char TP_DCS;
[MarshalAs(UnmanagedType.ByValArray,SizeConst=16)]
public char[] TP_SCTS;
[MarshalAs(UnmanagedType.ByValArray,SizeConst=161)]
public char[] TP_UD;
public char index;
}如何调用见
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.2052/cpguide/html/cpconstructssample.htm
是这个网站吗? 怎么打不开呢!??
public class class_SM_PARAM
{
char[] SCA = new char[16];
char[] TPA = new char[16];
char TP_PID;
char TP_DCS;
char[] TP_SCTS = new char[16];
char[] TP_UD = new char[161];
char index;
}
public class class_SM_PARAM
{
char[] SCA = new char[16];
char[] TPA = new char[16];
char TP_PID;
char TP_DCS;
char[] TP_SCTS = new char[16];
char[] TP_UD = new char[161];
char index;
}
SM_PARAM sm_para;
sm_para.SCA = new char[16];
sm_para.SCA[0] = '1';
sm_para.SCA[1] = '2';
..........