在C#里 如何封送一个指向结构的指针作为参数 传给调用的函数~在线等~`~谢谢
结构如下:(有的说写成类更好,我现在是不知道在C#里怎么写一个指向结构的指针)
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi )]
public struct TPParaBuf 
{    
   public System.Int32 ComNo;
            public System.Int32 Baud;
   [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 3)] public int[] Sys_Sec;
   [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 3)] public int[] User_Sec;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 6)] public string AuthorNo;
}

解决方案 »

  1.   

    查了些资料 如下写 提示PtrToStructure的第一个参数应为变量 不能为“类”
    IntPtr p = (IntPtr)Marshal.PtrToStructure(TPParaBuf, typeof(IntPtr));怎么去指向上面结构的指针 作为IntPtr类型参数 传给函数请各位大虾赐教~
      

  2.   

    Have a try!
    [StructLayout(LayoutKind.Sequential)]
    public struct TPParaBuf 
    {    
    public System.Int32 ComNo;
            public System.Int32 Baud;
    [MarshalAs(UnmanagedType.LPArray , SizeConst = 3)] 
    public int[] Sys_Sec;
    [MarshalAs(UnmanagedType.LPArray , SizeConst = 3)] 
    public int[] User_Sec;
            [MarshalAs(UnmanagedType.LPTStr)] 
    public string AuthorNo;
    }至于传递给函数,如果是传进,可以用
    ref TPParaBuf 如果是传出,可以用
    [Out]ref TPParaBuf
      

  3.   

    无法加载 DLL (pcsCardDll.dll)。 
    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。这个以前解决过 又忘了  有经验的帮忙说下  是哪方面错误
      

  4.   

    >>> 无法加载 DLL (pcsCardDll.dll)。 
    检查路径和拼写>>> 如果是传出,可以用[Out]ref TPParaBuf
    这么写是可以运行的但是显然你应该用out关键字