将指针传递给通用结构
我必须与 C# 中的 C 函数交互 该函数通过网络发送消息。
这是我在 C# 中的工作定义:
delegate void SendNetMessageDelegate(uint messageCode, ref MessageData messageData, uint messageSize);
MessageData 的定义如下:
[StructLayout(LayoutKind.Sequential)]
internal struct MessageData { ... }
到目前为止,这些定义工作良好。
问题是有时我需要使用另一个有效负载调用相同的函数。 这意味着我必须创建另一个采用“OtherMessageData”结构而不是“MessageData”的委托
,因此我必须添加另一个采用另一个结构作为参考的 SendNetMessageDelegate。
有更简单的方法吗? 所以我可以调用 SendNetMessage(messageCode, ref AnyStructHere messageData, messageSize)
我尝试将参数类型更改为“对象”,然后将我的结构转换为对象,但这不起作用......
I have to interface with a C function from C#
The function sends a message over the network.
Here is my working definition in C#:
delegate void SendNetMessageDelegate(uint messageCode, ref MessageData messageData, uint messageSize);
and the MessageData is defined like that:
[StructLayout(LayoutKind.Sequential)]
internal struct MessageData { ... }
those definitions work good so far.
The problem is that sometimes I need to call the same function with another payload.
That means I would have to make another delegate that takes "OtherMessageData" struct instead of "MessageData"
So I would have to add another SendNetMessageDelegate that takes another struct as reference.
Is there an easier way?
So I can call SendNetMessage(messageCode, ref AnyStructHere messageData, messageSize)
I tried changing the parameter type to "object" and then casting my structs to object, but that didn't work...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
泛型怎么样
How about generics