Solved

C# translation of data structure

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Build JSON from table records 17 40
Throws error on Decrypting String c# code 3 26
String manipulation 15 49
Round up to 100% in .NET 10 44
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now