从托管代码初始化非管理结构 (C#)
我有一个 C++ 结构,我想在 C# 代码中反映它(检查所有字段并以特定顺序启动),我想将结构内存作为二进制数据转储到文件中。 如果我声明 int dummy_4[10] ,我在 struct 中的数组减速中遇到问题,编译器会引发无法混合托管 & 的错误。非托管类型。如果我将其定义为数组等...并在构造函数中初始化该数组,则该数组不会位于内存中的 dummy_3 之后,并且我无法将其转储到文件中。
需要一些如何解决它的想法。 谢谢
public ref struct Dummy_t
{
int dummy_1;
int dummy_2;
int dummy_3;
//int dummy_4[2]; X compile error mix managed and unmanaged types
array<int>^ dummy_4;
int dummy_5;
Dummy_t()
{
dummy_4 = gcnew array<uint8_t>(2);
}
};
I have a structure in C++ that I want to reflect in C# code (goover all field and initiate with specific order) that I want to dump the structure memeory as binary data into a file.
I have a problem in array decleration in the sturct if I declare int dummy_4[10] the compiler raise error that can't mix managed & unmanaged types. if I delare as array etc... and initialize the array in the constructor, the array doesn't locate after dummy_3 in the memory and I can't dump it to the file.
Neeed some ideas how to solve it.
Thanks
public ref struct Dummy_t
{
int dummy_1;
int dummy_2;
int dummy_3;
//int dummy_4[2]; X compile error mix managed and unmanaged types
array<int>^ dummy_4;
int dummy_5;
Dummy_t()
{
dummy_4 = gcnew array<uint8_t>(2);
}
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在
Dummy_t
中编写自定义转储方法,该方法负责处理dummy_4
,并输出指向的数组中的值。You can write a custom dump method in
Dummy_t
, which takes care aboutdummy_4
, and outputs the values from the array pointed to.