Home > Net >  The size, in bytes for structure Marshal. SizeOf returns!
The size, in bytes for structure Marshal. SizeOf returns!

Time:10-18

C # code on face recognition, change to vb.net,
Public struct FaceInfo
{
Public FaceInfo (float iWidth, float iAngle, float iCenter_x, float iCenter_y, float iConf)
{
MWidth=iWidth;
The mAngle=iAngle;
MCenter_x=iCenter_x;
MCenter_y=iCenter_y;
MConf=iConf;
}
Public float mWidth;//a rectangle width
Public float the mAngle;//; F=0.0;//a rectangle tilt Angle [45] - 45 degrees in
Public float mCenter_y;//=0.0 F;//a rectangle center y
Public float mCenter_x;//=0.0 F;//a rectangle center x
Public float mConf;//=0.0 F;
};

[StructLayout (LayoutKind. Sequential, Pack=1)]
Public struct TrackFaceInfo
{
[MarshalAs (UnmanagedType. Struct)]
Public FaceInfo box;
[MarshalAs (UnmanagedType ByValArray, SizeConst=144)]
Public int [] the landmarks.//=new int [144].
[MarshalAs (UnmanagedType ByValArray, SizeConst=3)]
Public float [] headPose;//=new float [3].
Public float score;//=0.0 F;
Public UInt32 face_id;//=0;
}



TrackFaceInfo [] track_info=new TrackFaceInfo [ilen];
For (int I=0; I & lt; Ilen; I++)
{
Track_info [I]=new TrackFaceInfo ();
Track_info [I] the landmarks=new int [144].
Track_info [I] headPose=new float [3].
Track_info [I] face_id=0;
Track_info [I]. Score=0;
}
int sizeTrack=Marshal. SizeOf (typeof (TrackFaceInfo));


change the above code to VB.NET:



Public Structure FaceInfo
Public Sub New (ByVal iWidth As Single, ByVal iAngle As Single, ByVal iCenter_x As Single, ByVal iCenter_y As Single, ByVal iConf As Single)
MWidth=iWidth
The mAngle=iAngle
MCenter_x=iCenter_x
MCenter_y=iCenter_y
MConf=iConf
End Sub
Public mWidth As Single 'rectangle width () As mWidth
Public mAngle As Single
Public mCenter_y As Single
Public mCenter_x As Single
Public mConf As Single


End Structure

Public Structure TrackFaceInfo
Public box As FaceInfo
Public the landmarks As Integer () '=New int [144]. (a) As an Integer
Public headPose As Single () '=new float [3]. (a) As single
Public score As Single '=0.0 F; As single
Public face_id As UInt32 '=0; As UInt32
End Structure

Dim ilen As Integer=2 ';//number of incoming face
Dim track_info As TrackFaceInfo ()=New TrackFaceInfo (ilen) {}
For I=0 To ilen - 1
Track_info (I)=New TrackFaceInfo ()
Track_info (I). The landmarks=New Integer (144) {}
Track_info (I). HeadPose=New Single (3) {}
Track_info (I). The face_id=0
Track_info (I). The score=0
Next
Marshal. SizeOf (track_info. GetType)



Error the last sentence: "System. ArgumentException" type of untreated abnormalities in mscorlib.
in the DLL
Other information: type "WindowsApplication1 Module1 + TrackFaceInfo []" cannot be marshaling as unmanaged structure; Can't calculate the size of the meaningful or offset,

The last sentence I do not know how to write?

CodePudding user response:

Seemed to find out why
Dim sizeTrack As Integer=Marshal. SizeOf (track_info. GetType) changed to:
Dim sizeTrack As Integer=Marshal. SizeOf (track_info (0). GetType)

CodePudding user response:

CodePudding user response:

Marshal. SizeOf can only be used for excluding references is full of value type class (structure)
Array is certainly not enough, so out of the fault