在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;
}
结构如下:(有的说写成类更好,我现在是不知道在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;
}
解决方案 »
- C# 2010中Chart應該問題
- 求助:C# 多线程操作队列的问题
- 关于gridview的内容中包含换行符\r\n不换行的问题
- 求一复杂动态报表?高手都进来呀!
- c# 对字符串的遍历
- datarow操作,有点难
- 急,高分求技术架构总体设计、应用软件设计的技术方案,用于标书,最好是网站方面
- ------------MDI窗体问题 急----------
- 【求助】datagridview 操作后更新问题
- C#中怎么只取字符串的前n个字符,大虾请赐教,在线等待,急用
- 水晶报表的问题,请大家一定帮助,我已经郁闷了好几天了。(请版主帮帮忙!!!)
- 概率问题:1-25之中随机产生5个数(5个数不相同)100次,找出一种方法,使5个号同时不出的次数为最多
IntPtr p = (IntPtr)Marshal.PtrToStructure(TPParaBuf, typeof(IntPtr));怎么去指向上面结构的指针 作为IntPtr类型参数 传给函数请各位大虾赐教~
[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
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。这个以前解决过 又忘了 有经验的帮忙说下 是哪方面错误
检查路径和拼写>>> 如果是传出,可以用[Out]ref TPParaBuf
这么写是可以运行的但是显然你应该用out关键字