convert C struct into C#.net
-
hi, I want to ask how to convert this C struct into C#.net typedef struct _MT_EVENT { #if _WIN32 LARGE_INTEGER TimeStamp; // In FILETIME format #elif LINUX struct timeval TimeStamp; // In gettimeofday() format #endif ULONG UserStatus; // Not used by API ULONG EventCode; // Event Code ULONG SubReason; // Event sub-reason ULONG XtraInfo; // Extra information, e.g. termination ULONG FuncCode; // Function active when this event occurred USHORT Board; // Board ID USHORT Channel; // Global Channel ID (GCI) PVOID ptrBuffer; // Related play/record buffer pointer ULONG DataLength; // Byte length of data accessed (played/recorded) PVOID ptrXtraBuffer; // Pointer to xtra buffer ULONG XtraBufferLength; // Length of buffer pointed by ptrXtraBuffer ULONG XtraDataLength; // Length of data in buffer pointed by ptrXtraBuffer ULONG EventFlag; // Falgs of the following: // bit 0x00000001: 1 - Appl created the event // 0 - NTi DLL created the event // bit 0x00000002: 1 - Appl allocated ptrtraBuffer // 0 - NTi DLL allocated ptrXtraBuffer } MT_EVENT, *PMT_EVENT;
-
hi, I want to ask how to convert this C struct into C#.net typedef struct _MT_EVENT { #if _WIN32 LARGE_INTEGER TimeStamp; // In FILETIME format #elif LINUX struct timeval TimeStamp; // In gettimeofday() format #endif ULONG UserStatus; // Not used by API ULONG EventCode; // Event Code ULONG SubReason; // Event sub-reason ULONG XtraInfo; // Extra information, e.g. termination ULONG FuncCode; // Function active when this event occurred USHORT Board; // Board ID USHORT Channel; // Global Channel ID (GCI) PVOID ptrBuffer; // Related play/record buffer pointer ULONG DataLength; // Byte length of data accessed (played/recorded) PVOID ptrXtraBuffer; // Pointer to xtra buffer ULONG XtraBufferLength; // Length of buffer pointed by ptrXtraBuffer ULONG XtraDataLength; // Length of data in buffer pointed by ptrXtraBuffer ULONG EventFlag; // Falgs of the following: // bit 0x00000001: 1 - Appl created the event // 0 - NTi DLL created the event // bit 0x00000002: 1 - Appl allocated ptrtraBuffer // 0 - NTi DLL allocated ptrXtraBuffer } MT_EVENT, *PMT_EVENT;
Check out the code MS provides for the Windows Mobile Gps, http://msdn.microsoft.com/en-us/library/ms881362.aspx[^] (Sample code comes with the SDK) It contains many C structs written in C#, fairly cool. (Although, the sample like all MS samples doesn't work out of the box)
Need custom software developed? I do C# development and consulting all over the United States. A man said to the universe: "Sir I exist!" "However," replied the universe, "The fact has not created in me A sense of obligation." --Stephen Crane
-
hi, I want to ask how to convert this C struct into C#.net typedef struct _MT_EVENT { #if _WIN32 LARGE_INTEGER TimeStamp; // In FILETIME format #elif LINUX struct timeval TimeStamp; // In gettimeofday() format #endif ULONG UserStatus; // Not used by API ULONG EventCode; // Event Code ULONG SubReason; // Event sub-reason ULONG XtraInfo; // Extra information, e.g. termination ULONG FuncCode; // Function active when this event occurred USHORT Board; // Board ID USHORT Channel; // Global Channel ID (GCI) PVOID ptrBuffer; // Related play/record buffer pointer ULONG DataLength; // Byte length of data accessed (played/recorded) PVOID ptrXtraBuffer; // Pointer to xtra buffer ULONG XtraBufferLength; // Length of buffer pointed by ptrXtraBuffer ULONG XtraDataLength; // Length of data in buffer pointed by ptrXtraBuffer ULONG EventFlag; // Falgs of the following: // bit 0x00000001: 1 - Appl created the event // 0 - NTi DLL created the event // bit 0x00000002: 1 - Appl allocated ptrtraBuffer // 0 - NTi DLL allocated ptrXtraBuffer } MT_EVENT, *PMT_EVENT;
I'm not so hot on all that interop stuff and its a guess, but you could try this:
[StructLayout(LayoutKind.Sequential)]
public struct _MT_EVENT
{
public long TimeStamp;
public ulong UserStatus; // Not used by API
public ulong EventCode; // Event Code
public ulong SubReason; // Event sub-reason
public ulong XtraInfo; // Extra information, e.g. termination
public ulong FuncCode; // Function active when this event occurred
public ushort Board; // Board ID
public ushort Channel; // Global Channel ID (GCI)
public IntPtr ptrBuffer; // Related play/record buffer pointer
public ulong DataLength; // Byte length of data accessed (played/recorded)
public IntPtr ptrXtraBuffer; // Pointer to xtra buffer
public ulong XtraBufferLength; // Length of buffer pointed by ptrXtraBuffer
public ulong XtraDataLength; // Length of data in buffer pointed by ptrXtraBuffer
public ulong EventFlag; // Falgs of the following:
}Regards, Rob Philpott.
-
I'm not so hot on all that interop stuff and its a guess, but you could try this:
[StructLayout(LayoutKind.Sequential)]
public struct _MT_EVENT
{
public long TimeStamp;
public ulong UserStatus; // Not used by API
public ulong EventCode; // Event Code
public ulong SubReason; // Event sub-reason
public ulong XtraInfo; // Extra information, e.g. termination
public ulong FuncCode; // Function active when this event occurred
public ushort Board; // Board ID
public ushort Channel; // Global Channel ID (GCI)
public IntPtr ptrBuffer; // Related play/record buffer pointer
public ulong DataLength; // Byte length of data accessed (played/recorded)
public IntPtr ptrXtraBuffer; // Pointer to xtra buffer
public ulong XtraBufferLength; // Length of buffer pointed by ptrXtraBuffer
public ulong XtraDataLength; // Length of data in buffer pointed by ptrXtraBuffer
public ulong EventFlag; // Falgs of the following:
}Regards, Rob Philpott.
size warning: in.NET long/ulong are 64-bit integers, in most other languages when targettingt a 32-bit CPU they just take 32-bit. http://www.pinvoke.net[^] holds lots of useful interop stuff, however it also contains some mistakes, frequently passing a pointer as int (should be IntPtr). :)
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
-
size warning: in.NET long/ulong are 64-bit integers, in most other languages when targettingt a 32-bit CPU they just take 32-bit. http://www.pinvoke.net[^] holds lots of useful interop stuff, however it also contains some mistakes, frequently passing a pointer as int (should be IntPtr). :)
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
That is the primary reason I encourage (require) programmers on my teams not to use int and long in C# and instead require Int32 and Int64. The same issue comes up a lot in database programming. I am absolutely sick and tired of seeing cast errors in code because a programmer doesn't know what type they are using.
Need custom software developed? I do C# development and consulting all over the United States. A man said to the universe: "Sir I exist!" "However," replied the universe, "The fact has not created in me A sense of obligation." --Stephen Crane
-
That is the primary reason I encourage (require) programmers on my teams not to use int and long in C# and instead require Int32 and Int64. The same issue comes up a lot in database programming. I am absolutely sick and tired of seeing cast errors in code because a programmer doesn't know what type they are using.
Need custom software developed? I do C# development and consulting all over the United States. A man said to the universe: "Sir I exist!" "However," replied the universe, "The fact has not created in me A sense of obligation." --Stephen Crane
thanks alot all...