Click here to Skip to main content
15,888,610 members
Home / Discussions / C#
   

C#

 
QuestionCPU serial number Pin
Dr_C#5-Sep-05 20:37
Dr_C#5-Sep-05 20:37 
AnswerRe: CPU serial number Pin
Stanciu Vlad5-Sep-05 21:38
Stanciu Vlad5-Sep-05 21:38 
QuestionHow can i make polar graph in .NET? Pin
parvinder sehrawat5-Sep-05 20:29
parvinder sehrawat5-Sep-05 20:29 
QuestionKey Chord Sequences Pin
Vasudevan Deepak Kumar5-Sep-05 20:08
Vasudevan Deepak Kumar5-Sep-05 20:08 
Question"For" bucle doesn't work in c#? Pin
Heinz_5-Sep-05 20:03
Heinz_5-Sep-05 20:03 
AnswerRe: "For" bucle doesn't work in c#? Pin
Stefan Troschuetz5-Sep-05 20:22
Stefan Troschuetz5-Sep-05 20:22 
QuestionResizing Pin
dhanunjay5-Sep-05 19:08
dhanunjay5-Sep-05 19:08 
QuestionC# Nested Structure Marshalling Pin
RobVai5-Sep-05 18:59
RobVai5-Sep-05 18:59 
I would like to declare the following structures in C# and be able to utilize the Marshal.StructureToPtr() and Marshal.PtrToStructure() on these structures and pointers later on. The reason being that I need structures that can be used for UDP packets that can be filled, sent, received, and later unpacked in the correct order.
In C++, these structures can be somewhat complex due to nested structures.

However, the example below is a very simple C++ nested structure with an attempted C# conversion. In the C#, I have only one query and that can be seen at the very end when transposing the last structure ie IDENTIFIER_T id[12];

Does anyone know a simple way to convert these simple structures to C#????

C++

typedef struct {
int source;
int destination;
int message;
}HEADER_T;

typedef struct {
double X;
double Y;
double Z;
}VECTOR_T;

typedef struct {
int id;
char[32] IdName;
int nameHashId;
}IDENTIFIER_T;

typedef struct {
int id;
char[64] dataName;
HEADER_T header;
VECTOR_T position;
IDENTIFIER_T id[12];
char[128] spare;
}DATA_T;



Attempted C# Equivalent

[ StructureLayout ( LayoutKind.Sequential ) ]
public struct HEADER_T {
int source;
int destination;
int message;
};

[ StructureLayout ( LayoutKind.Sequential ) ]
public struct VECTOR_T {
double X;
double Y;
double Z;
};

[ StructureLayout ( LayoutKind.Sequential ) ]
public class IDENTIFIER_T {
int id;
[ MarshalAs(UnmanagedType.ByValTStr, SizeConst=32 ]
string IdName;
int nameHashId;
};

public class DATA_T {
int id;
[ MarshalAs(UnmanagedType.ByValTStr, SizeConst=64 ]
string dataName;
HEADER_T header;
VECTOR_T position;

// ????? What happens here???? Confused | :confused:
IDENTIFIER_T id[12];

[ MarshalAs(UnmanagedType.ByValTStr, SizeConst=128 ]
string spare;
};



Rob

-- modified at 1:04 Tuesday 6th September, 2005
AnswerRe: C# Nested Structure Marshalling Pin
leppie6-Sep-05 3:51
leppie6-Sep-05 3:51 
GeneralRe: C# Nested Structure Marshalling Pin
RobVai7-Sep-05 13:46
RobVai7-Sep-05 13:46 
GeneralRe: C# Nested Structure Marshalling Pin
leppie7-Sep-05 14:16
leppie7-Sep-05 14:16 
QuestionSave a pictureBox object as JPEG or BMP? Pin
boraxx5-Sep-05 18:25
boraxx5-Sep-05 18:25 
AnswerRe: Save a pictureBox object as JPEG or BMP? Pin
Andrew Kirillov5-Sep-05 19:09
Andrew Kirillov5-Sep-05 19:09 
GeneralRe: Save a pictureBox object as JPEG or BMP? Pin
boraxx6-Sep-05 14:31
boraxx6-Sep-05 14:31 
GeneralRe: Save a pictureBox object as JPEG or BMP? Pin
Andrew Kirillov6-Sep-05 18:57
Andrew Kirillov6-Sep-05 18:57 
GeneralRe: Save a pictureBox object as JPEG or BMP? Pin
boraxx6-Sep-05 20:35
boraxx6-Sep-05 20:35 
QuestionHow to make ScrollBar attached to Panel automatically? Pin
radic.feng5-Sep-05 17:16
radic.feng5-Sep-05 17:16 
Question?Word object Pin
mitsemaj5-Sep-05 16:20
mitsemaj5-Sep-05 16:20 
QuestionNUnit tests Pin
savage_5-Sep-05 11:25
savage_5-Sep-05 11:25 
AnswerRe: NUnit tests Pin
Andy Brummer5-Sep-05 17:00
sitebuilderAndy Brummer5-Sep-05 17:00 
GeneralRe: NUnit tests Pin
savage_5-Sep-05 17:30
savage_5-Sep-05 17:30 
GeneralRe: NUnit tests Pin
savage_5-Sep-05 18:07
savage_5-Sep-05 18:07 
QuestionProblems using C++ SDK Pin
Christian Graus5-Sep-05 11:20
protectorChristian Graus5-Sep-05 11:20 
AnswerRe: Problems using C++ SDK Pin
leppie5-Sep-05 13:12
leppie5-Sep-05 13:12 
GeneralRe: Problems using C++ SDK Pin
Christian Graus5-Sep-05 13:16
protectorChristian Graus5-Sep-05 13:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.