Solved

C# translation of data structure

Posted on 2004-04-06
3
1,261 Views
Last Modified: 2007-12-19
What would the C# equivalent of this structure be?


typedef struct videohdr_tag {
    LPBYTE      lpData;
    DWORD       dwBufferLength;
    DWORD       dwBytesUsed;
    DWORD       dwTimeCaptured;
    DWORD       dwUser;
    DWORD       dwFlags;
    DWORD_PTR   dwReserved[4];
} VIDEOHDR, NEAR *PVIDEOHDR, FAR * LPVIDEOHDR;
0
Comment
Question by:rossryan
  • 2
3 Comments
 
LVL 10

Expert Comment

by:Duy Pham
ID: 10767099
You should try this :

struct VIDEOHDR
{
    byte[]    lpData;
    uint       dwBufferLength;
    uint       dwByteUsed;
    uint       dwTimeCaptured;
    uint       dwUser;
    uint       dwFlags;
    IntPtr    dwReserveds;
}
0
 
LVL 10

Assisted Solution

by:Duy Pham
Duy Pham earned 250 total points
ID: 10767298
Sorry, i forgot to tell you about IntPtr.
Because you exactly the length of dwReserveds is 4*sizeof(Int32) = 16 bytes.
You can easily convert it to uint[] or byte[] array. But dwReserveds will always never be used, so it doesn't matter. You only need to remember that IntPtr can represent to all the Handles, Pointers, or something that is diffucult to declare.

You can also declare lpData as IntPtr object. And use Marshal class to convert it to byte[] like this :

IntPtr lp_IntPtr_Data;

byte[] lp_byteData = Marshal.Copy(lp_IntPtr_Data, lp_byteData, 0, dwBufferLength);

or

byte[] lp_byteData = Marshal.Copy(lp_IntPtr_Data, lp_byteData, 0, dwByteUsed);

depends on what you want to take.
0
 
LVL 48

Accepted Solution

by:
AlexFM earned 250 total points
ID: 10768904
   struct VIDEOHDR
    {
        IntPtr    lpData;
        uint       dwBufferLength;
        uint       dwByteUsed;
        uint       dwTimeCaptured;
        uint       dwUser;
        uint       dwFlags;
        [MarshalAs (UnmanagedType.ByValArray,SizeConst=4)]
        uint[]       dwReserveds;
    }

lpData - Pointer to locked data buffer. I hope you have it from some other function.
DWORD_PTR is Win32 unsigned long, which is the same as unsigned int.
I am not sure for 100% about dwReserveds array, but you can replace it with 4 uint values like:

uint dwReserveds1;
uint dwReserveds2;
uint dwReserveds3;
uint dwReserveds4;
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question