本文介绍了如何在C#结构中定义动态数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在c ++中有一个结构,指针作为该结构的成员,用于指向另一种结构的数组。我不知道该数组的大小,因为它是由第三方dll动态分配的,而且是读取文件的。请帮我这个



我尝试过:



你好我是c#的新手并且遇到了问题。

i必须将应用程序从c ++移植到c#,而在c ++中有一种格式结构如图所示

struct框架

{

int frameID;

dirData * arr_dirdata;

}



struct dirData

{

int nFiles;

filesData * arr_fileData;

这些结构用于从文件中读取数据,而这些数据实际上是一些dirData结构数组和filesData结构数组。该结构实际​​上是由第三方dll分配的。我没有dll的c#版本,所以我使用的是c ++版本并将其包裹起来。



当我将相同的结构转换为c#i时定义如下

[StructLayout(LayoutKind.Sequential)]

struct frame

{

int frameID;

[MarshalAs(UnmanagedType.LPArray,SizeConst = 1)]

dirData [] arrdirData;

}

如何定义在我的情况下阵列。





在此先感谢

AK

解决方案

I have a structure in c++ with pointers as the member of that structure which is used to point to an array of another type of structures. I dont know the size of that array as that is dynamically allocated by a thirdparty dll and that to reading a file. Please help me with this

What I have tried:

Hi i am very new to c# and have encountered a problem.
i have to port an application from c++ to c# and in c++ there is a structure of the format as shown
struct Frame
{
int frameID;
dirData* arr_dirdata;
}

struct dirData
{
int nFiles;
filesData* arr_fileData;
}

These structures are used to read data from a file and that data is actually a number of dirData structure array and filesData structure array. The structure is actually allocated by a third party dll. i dont have the c# version of the dll so i am using the c++ version and wrapping around that.

when i am converting the same structure to c# i defined as following
[StructLayout(LayoutKind.Sequential)]
struct Frame
{
int frameID;
[MarshalAs(UnmanagedType.LPArray, SizeConst = 1)]
dirData[] arrdirData;
}
How to define an array in my case.


Thanks in Advance
AK

解决方案


这篇关于如何在C#结构中定义动态数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 11:15