Solved

C# translation of data structure

Posted on 2004-04-06
3
1,271 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

735 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