struct问题

Lxyer 2004-09-06 10:36:37
我用C#调用一dll,dll会向C#应用程序发送一个自定义消息,
LParam指向结构体如下,

struct LineItem
{
int nCard;
int nPort;
char msg[32];
};
请问在C#中如何转换出来使用.
...全文
132 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
jedliu 2004-09-06
  • 打赏
  • 举报
回复
同意yellowhwb(KaDoO)说的
The123 2004-09-06
  • 打赏
  • 举报
回复
Message.GetLParam()


haiwangstar 2004-09-06
  • 打赏
  • 举报
回复
[StructLayout(LayoutKind.Sequential)]
public struct LineItem
{
[MarshalAs(UnmanagedType.LPTStr)]
string msg;
int nCard;
int nPort;

}
haiwangstar 2004-09-06
  • 打赏
  • 举报
回复
[StructLayout(LayoutKind.Sequential)]
public struct LineItem
{
[MarshalAs(LPStr)]
string msg;
int nCard;
int nPort;

}
yellowhwb 2004-09-06
  • 打赏
  • 举报
回复
是的,struct和类一样用,struct可以不要new。强类型转换就可以了!
Eddie005 2004-09-06
  • 打赏
  • 举报
回复
LineItem tmp = new LineItem();
tmp.nCard = 1;
tmp.nPort = 2;
..
thinkingforever 2004-09-06
  • 打赏
  • 举报
回复
LineItem肯定是在dll已经定义了的,所以在引用dll后,添加所在的命名空间,和基本的类型一样使用啊
penning 2004-09-06
  • 打赏
  • 举报
回复
LineItem *item;?c#没有这种写法

LineItem item;

item = (LineItem ) m.LParam;

Lxyer 2004-09-06
  • 打赏
  • 举报
回复
怎么转换呢

LineItem *item;
item = (LineItem *) m.LParam;
不行
item = m.LParam.ToPointer();
也不成功

110,566

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧