SendShortMessage(ref char send_number,ref char send_msg,ref SM_PARAM sm_param_temp)
结构体不用变,这样不行吗
如果还有问题,将结构体封装在一个类里用就肯定没有问题了

解决方案 »

  1.   

    我 将 动态库函数封装在类 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:该类型的类型定义没有布局信息。
      

  2.   

    你怎么发两遍呢?[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
      

  3.   

    ms-help://MS.MSDNQTR.2003FEB.2052/cpguide/html/cpconStructsSample.htm
      

  4.   

    ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.2052/cpguide/html/cpconstructssample.htm
    是这个网站吗? 怎么打不开呢!??
      

  5.   

    [StructLayout(LayoutKind.Sequential)]
    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;          
    }
      

  6.   

    你没装msdn么?装了msdn,可以直接在ie浏览器中打开的或者到在线msdn上查http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconstructssample.asp
      

  7.   

    [StructLayout(LayoutKind.Sequential)]
    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;          
    }
      

  8.   


    SM_PARAM sm_para;
    sm_para.SCA = new char[16];
    sm_para.SCA[0] = '1';
    sm_para.SCA[1] = '2';
    ..........