结构中的数组 [英] Array in Structure

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

问题描述

大家好,


我有一些结构被定义为


//////

< StructLayout(LayoutKind.Sequential)公共结构GM_LayerInfo_t

Public mDescription As String

Public mNativeRect As GM_Rectangle_t

Public mGlobalRect As GM_Rectangle_t

公共mPixelWidth为Int32

公共mPixelHeight为Int32

公共mControlPoints为IntPtr

Public mNumGCPs As Int32

Public mMinElevation As Single

Public mMaxElevation As Single

Public mNumAreas As Int32

Public mNumLines As Int32

Public mNumPoints As Int32

Public mPixelSizeX As Double

Public mPixelSizeY As Double

Public mHasRasterData As Byte

Public mEnabled As Byte

Public mHasVectorData As Byte

Public mUsedDefaultPos As Byte

Public mFilename As String

Public mArchiveFilename As String

Public mTypeName As String

End Structure


< StructLayout(LayoutKind.Sequential )公共结构GM_ProjAttrValue_t

Public mAttr作为PROJATTR

公共mValue双倍

结束结构


< StructLayout(LayoutKind.Sequential)公共结构GM_Projection_t

公共mProjSys作为PROJSYS

公共mDatum作为DATUM

公共mUnit作为UNIT

Public mNumAttrs As Int32

< VBFixedArray(15)Public mAttrList()As GM_ProjAttrValue_t

结束结构

/// ////


类型PROJATTR,PROJSYS,DATUM和UNIT是定义的枚举,而GM_Rectangle_t是

另一种结构,但这些不是问题的一部分(至少我非常积极

他们不是)。它是GM_Projection_t结构中的数组似乎是

问题。这里已经修复了,但是我也试图让它保持动态并且同样发生问题。


数组*应该*差不多在填充

结构后,它总是包含至少1个元素(但它可能是空的,或者它最多可以包含16个)。无论如何,当我在上面编码时填充结构时,mAttrList

总是没什么关系。 (代码填写

在此消息的botom)。结构中的每个其他成员都被填写得很好。

但是,如果我没有让mAttrList成为一个数组 - 只是在结构中定义为


/////

Public mAttrList As GM_ProjAttrValue_t

/////


然后用mAttr正确填充mAttrList和
GM_ProjAttrValue_t结构的mValue成员(请记住,* *几乎总是*至少有一个属性为

填充mAttrList)。

以下是调用填充结构的代码


/////

''将指针转换为我们的结构

Dim theLayerInfo为GM_LayerInfo_t

theLayerInfo = CType(Marshal.PtrToStructure(theLayerInfoPtr,GetType(GM_LayerInfo_t)),

GM_LayerInfo_t)

/////

Hi all,

I''ve got a some structures defined as

//////
<StructLayout(LayoutKind.Sequential)Public Structure GM_LayerInfo_t
Public mDescription As String
Public mNativeRect As GM_Rectangle_t
Public mGlobalRect As GM_Rectangle_t
Public mPixelWidth As Int32
Public mPixelHeight As Int32
Public mNativeProj As GM_Projection_t
Public mControlPoints As IntPtr
Public mNumGCPs As Int32
Public mMinElevation As Single
Public mMaxElevation As Single
Public mNumAreas As Int32
Public mNumLines As Int32
Public mNumPoints As Int32
Public mPixelSizeX As Double
Public mPixelSizeY As Double
Public mHasRasterData As Byte
Public mEnabled As Byte
Public mHasVectorData As Byte
Public mUsedDefaultPos As Byte
Public mFilename As String
Public mArchiveFilename As String
Public mTypeName As String
End Structure

<StructLayout(LayoutKind.Sequential)Public Structure GM_ProjAttrValue_t
Public mAttr As PROJATTR
Public mValue As Double
End Structure

<StructLayout(LayoutKind.Sequential)Public Structure GM_Projection_t
Public mProjSys As PROJSYS
Public mDatum As DATUM
Public mUnit As UNIT
Public mNumAttrs As Int32
<VBFixedArray(15)Public mAttrList() As GM_ProjAttrValue_t
End Structure
///////

The Types PROJATTR, PROJSYS, DATUM, and UNIT are defined enums while GM_Rectangle_t is
another structure but these are not part of the problem (at lease I''m farily positive
they''re not). It''s the array in the GM_Projection_t structure that seems to be the
problem. Here it''s fixed, but I''ve also attempted just leaving it dynamic and the same
problem occurs.

The array *should* almost always contains at least 1 element in it after fill the
structure (but it could be empty or it could contain up to 16 at max). Anyway, mAttrList
is always NOTHING when ever I fill the structure as it''s coded above. (the code to fill
it at the botom of this message). Every other member of the structure is filled in fine.
However, if I don''t make mAttrList an array - just defined within the structure as

/////
Public mAttrList As GM_ProjAttrValue_t
/////

then mAttrList is properly filled with the mAttr and mValue members of the
GM_ProjAttrValue_t structure (remember, there''s *almost always* at least one attribute to
fill the mAttrList).
Here is the code making the call to fill the strucure

/////
'' Convert the pointer to our structure
Dim theLayerInfo As GM_LayerInfo_t
theLayerInfo = CType(Marshal.PtrToStructure(theLayerInfoPtr, GetType(GM_LayerInfo_t)),
GM_LayerInfo_t)
/////

推荐答案

" Lance" < nu *** @ business.comha scritto nel messaggio

新闻:%2 *************** @ TK2MSFTNGP05.phx.gbl ...

"Lance" <nu***@business.comha scritto nel messaggio
news:%2***************@TK2MSFTNGP05.phx.gbl...


>

这是拨打电话填写结构的代码


/////

''将指针转换为我们的结构

将theLayerInfo调暗为GM_LayerInfo_t

theLayerInfo = CType(Marshal.PtrToStructure (theLayerInfoPtr,

GetType(GM_LayerInfo_t)),GM_LayerInfo_t)

/////
>
Here is the code making the call to fill the strucure

/////
'' Convert the pointer to our structure
Dim theLayerInfo As GM_LayerInfo_t
theLayerInfo = CType(Marshal.PtrToStructure(theLayerInfoPtr,
GetType(GM_LayerInfo_t)), GM_LayerInfo_t)
/////



First of所有我认为你需要阅读namimng类型指南和

变量。


关于你的问题我想知道你为什么要通过编组和我/>
不明白你的阵列是否是一个固定阵列。


还要记住,如果你真的不需要,你应该使用class

而不是大型结构。


-


免费.Net报告工具 - http://www.neodatatype.net


just关于所有这些代码都是从SDK剪切并粘贴的,因此变量名称也不会是我的首选。 SDK示例也通过编组传递。


我唯一从SDK改变的是结构。它最初是


/////< StructLayout(LayoutKind.Sequential)公共结构GM_Projection_t

公共mProjSys作为PROJSYS''投影系统
Public mDatum As DATUM''Horizo​​ntal datum

Public mUnit As UNIT''Ground units

Public mNumAttrs As Int32''属性列表中的属性数

Public mAttrVal1 As GM_ProjAttrValue_t''第一个属性值

Public mAttrVal2 As GM_ProjAttrValue_t''第一个属性值

Public mAttrVal3 As GM_ProjAttrValue_t''第一个属性值

Public mAttrVal4 As GM_ProjAttrValue_t''First attribute value

Public mAttrVal5 As GM_ProjAttrValue_t''First attribute value

Public mAttrVal6 As GM_ProjAttrValue_t''First attribute值

Public mAttrVal7 As GM_ProjAttrValue_t''第一属性值

Public mAttrVal8 As GM_ProjAttrValue_t''First attribute value

Public mAttrVal9 As GM_ProjAttrValue_t''First attribute value

Public mAttrVal10 As GM_ProjAttrValue_t''First attribute value

Public mAttrVal11 As GM_ProjAttrValue_t''First attribute value

Public mAttrVal12 As GM_ProjAttrValue_t''First attribute value

Public mAttrVal13 As GM_ProjAttrValue_t''First attribute value

Public mAttrVal14 As GM_ProjAttrValue_t''First attribute value

Public mAttrVal15 As GM_ProjAttrValue_t''First attribute value

Public mAttrVal16 As GM_ProjAttrValue_t''First attribute价值

结束结构

/////


我试图改变结构以更好地反映和表现得更像原始的C

头文件定义

/////

typedef struct

{

PROJSYS mPro JSYS; //投影系统

DATUM mDatum; //水平数据

UNIT mUnit; //地面单位

uint32 mNumAttrs; //属性列表中的属性数

GM_ProjAttrValue_t mAttrList [16]; //属性列表

} GM_Projection_t;

/////

" Fabio" < zn ******* @ virgilio.itwrote in message

news:%2 **************** @ TK2MSFTNGP03.phx.gbl ...
just about all of this code was cut and pasted from an SDK, so the variable names wouldn''t
be my first choice either. the SDK example also passes by marshalling.

the only thing i''ve changed from the SDK is the structure. it was originally

///// <StructLayout(LayoutKind.Sequential)Public Structure GM_Projection_t
Public mProjSys As PROJSYS '' Projection system
Public mDatum As DATUM '' Horizontal datum
Public mUnit As UNIT '' Ground units
Public mNumAttrs As Int32 '' Number of attributes in attribute list
Public mAttrVal1 As GM_ProjAttrValue_t '' First attribute value
Public mAttrVal2 As GM_ProjAttrValue_t '' First attribute value
Public mAttrVal3 As GM_ProjAttrValue_t '' First attribute value
Public mAttrVal4 As GM_ProjAttrValue_t '' First attribute value
Public mAttrVal5 As GM_ProjAttrValue_t '' First attribute value
Public mAttrVal6 As GM_ProjAttrValue_t '' First attribute value
Public mAttrVal7 As GM_ProjAttrValue_t '' First attribute value
Public mAttrVal8 As GM_ProjAttrValue_t '' First attribute value
Public mAttrVal9 As GM_ProjAttrValue_t '' First attribute value
Public mAttrVal10 As GM_ProjAttrValue_t '' First attribute value
Public mAttrVal11 As GM_ProjAttrValue_t '' First attribute value
Public mAttrVal12 As GM_ProjAttrValue_t '' First attribute value
Public mAttrVal13 As GM_ProjAttrValue_t '' First attribute value
Public mAttrVal14 As GM_ProjAttrValue_t '' First attribute value
Public mAttrVal15 As GM_ProjAttrValue_t '' First attribute value
Public mAttrVal16 As GM_ProjAttrValue_t '' First attribute value
End Structure
/////

I was trying to change the structure to better reflect and behave more like the original C
Header file definition of
/////
typedef struct
{
PROJSYS mProjSys; // Projection system
DATUM mDatum; // Horizontal datum
UNIT mUnit; // Ground units
uint32 mNumAttrs; // Number of attributes in attribute list
GM_ProjAttrValue_t mAttrList[ 16 ]; // Attribute list
} GM_Projection_t;
/////
"Fabio" <zn*******@virgilio.itwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...

" Lance" < nu *** @ business.comha scritto nel messaggio

新闻:%2 *************** @ TK2MSFTNGP05.phx.gbl ...

"Lance" <nu***@business.comha scritto nel messaggio
news:%2***************@TK2MSFTNGP05.phx.gbl...


>>
以下是拨打电话填写结构的代码

/
''将指针转换为我们的结构
将theLayerInfo变为GM_LayerInfo_t
theLayerInfo = CType(Marshal.PtrToStructure(theLayerInfoPtr,GetType(GM_LayerInfo_t)),
GM_LayerInfo_t) /////
>>
Here is the code making the call to fill the strucure

/////
'' Convert the pointer to our structure
Dim theLayerInfo As GM_LayerInfo_t
theLayerInfo = CType(Marshal.PtrToStructure(theLayerInfoPtr, GetType(GM_LayerInfo_t)),
GM_LayerInfo_t)
/////




首先,我认为您需要读取类型和变量的namimng指南。

关于你的问题,我想知道你为什么要通过编组,我不知道你的阵列是否是一个固定的阵列。


还要记住,如果你真的不需要,你应该使用一个班级而不是一个

的大型结构。


-


免费.Net报告工具 - http://www.neodatatype.net



顺便说一下,Dim''ing数组为15是下面代码段中的拼写错误。它应该是16.


Lance < nu *** @ business.comwrote in message

news:%2 *************** @ TK2MSFTNGP05.phx.gbl ...
by the way, Dim''ing the array as 15 is a typo in the snippet below. it should be 16.

"Lance" <nu***@business.comwrote in message
news:%2***************@TK2MSFTNGP05.phx.gbl...

大家好,


我有一些结构被定义为


//////

< StructLayout(LayoutKind.Sequential)公共结构GM_LayerInfo_t

Public mDescription As String

Public mNativeRect As GM_Rectangle_t

公共mGlobalRect为GM_Rectangle_t

公共mPixelWidth为Int32

公共mPixelHeight为Int32

公共mNativeProj为GM_Projection_t

Public mControlPoints As IntPtr

Public mNumGCPs As Int32

Public mMinElevation As Single

Public mMaxElevation As Single

Public mNumAreas As Int32

Public mNumLines As Int32

Public mNumPoints As Int32

Public mPixelSizeX As Double

Public mPixelSizeY As Double

Public mHasRasterData As Byte

Public mEnabled As Byte

Public mHasVectorData As Byte

Public mUsedDefaultPos As Byte

Public mFilename As String

Public mArchiveFilename As String

Public mTypeName As String

结束结构


< StructLayout(LayoutKind.Sequential)Public Structure GM_ProjAttrValue_t

Public mAttr As PROJATTR

Public mValue As Double

结束结构


< StructLayout(LayoutKind.Sequential)公共结构GM_Projection_t

公共mProjSys作为PROJSYS

Public mDatum As DATUM

Public mUnit As UNIT

Public mNumAttrs As Int32

< VBFixedArray(15)Public mAttrList ()作为GM_ProjAttrValue_t

结束结构

///////


类型PROJATTR,PROJSYS,DATUM和单元定义枚举,而GM_Rectangle_t是

另一种结构,但这些不是问题的一部分(至少我是非常积极的

他们不是)。它是GM_Projection_t结构中的数组似乎是

问题。这里已经修复了,但是我也试图让它保持动态并且同样发生问题。


数组*应该*差不多在填充

结构后,它总是包含至少1个元素(但它可能是空的,或者它最多可以包含16个)。无论如何,

当我在上面编码时填充结构时,mAttrList始终没有任何意义。 (

代码填写此消息的botom)。该结构的每个其他成员都是

。但是,如果我没有让mAttrList成为一个数组 - 只需在

结构中定义为


/////

Public mAttrList As GM_ProjAttrValue_t

/////


然后mAttrList正确地填充了
$ b的mAttr和mValue成员$ b GM_ProjAttrValue_t结构(请记住,*几乎总是*至少有一个属性

来填充mAttrList)。


这是代码制作填写结构的电话


/////

''将指针转换为我们的结构

Dim theLayerInfo As GM_LayerInfo_t

theLayerInfo = CType(Marshal.PtrToStructure(theLayerInfoPtr,GetType(GM_LayerInfo_t)),

GM_LayerInfo_t)

/////
Hi all,

I''ve got a some structures defined as

//////
<StructLayout(LayoutKind.Sequential)Public Structure GM_LayerInfo_t
Public mDescription As String
Public mNativeRect As GM_Rectangle_t
Public mGlobalRect As GM_Rectangle_t
Public mPixelWidth As Int32
Public mPixelHeight As Int32
Public mNativeProj As GM_Projection_t
Public mControlPoints As IntPtr
Public mNumGCPs As Int32
Public mMinElevation As Single
Public mMaxElevation As Single
Public mNumAreas As Int32
Public mNumLines As Int32
Public mNumPoints As Int32
Public mPixelSizeX As Double
Public mPixelSizeY As Double
Public mHasRasterData As Byte
Public mEnabled As Byte
Public mHasVectorData As Byte
Public mUsedDefaultPos As Byte
Public mFilename As String
Public mArchiveFilename As String
Public mTypeName As String
End Structure

<StructLayout(LayoutKind.Sequential)Public Structure GM_ProjAttrValue_t
Public mAttr As PROJATTR
Public mValue As Double
End Structure

<StructLayout(LayoutKind.Sequential)Public Structure GM_Projection_t
Public mProjSys As PROJSYS
Public mDatum As DATUM
Public mUnit As UNIT
Public mNumAttrs As Int32
<VBFixedArray(15)Public mAttrList() As GM_ProjAttrValue_t
End Structure
///////

The Types PROJATTR, PROJSYS, DATUM, and UNIT are defined enums while GM_Rectangle_t is
another structure but these are not part of the problem (at lease I''m farily positive
they''re not). It''s the array in the GM_Projection_t structure that seems to be the
problem. Here it''s fixed, but I''ve also attempted just leaving it dynamic and the same
problem occurs.

The array *should* almost always contains at least 1 element in it after fill the
structure (but it could be empty or it could contain up to 16 at max). Anyway,
mAttrList is always NOTHING when ever I fill the structure as it''s coded above. (the
code to fill it at the botom of this message). Every other member of the structure is
filled in fine. However, if I don''t make mAttrList an array - just defined within the
structure as

/////
Public mAttrList As GM_ProjAttrValue_t
/////

then mAttrList is properly filled with the mAttr and mValue members of the
GM_ProjAttrValue_t structure (remember, there''s *almost always* at least one attribute
to fill the mAttrList).
Here is the code making the call to fill the strucure

/////
'' Convert the pointer to our structure
Dim theLayerInfo As GM_LayerInfo_t
theLayerInfo = CType(Marshal.PtrToStructure(theLayerInfoPtr, GetType(GM_LayerInfo_t)),
GM_LayerInfo_t)
/////



这篇关于结构中的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆