Solved

C# translation of data structure

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASP.NET Web API or ASP.NET Core MVC? 3 52
What is Thread.Sleep? 5 46
Need to pass stored proc parameters in list 13 33
Remove greater than sign 3 46
Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

867 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

22 Experts available now in Live!

Get 1:1 Help Now