?
Solved

C# translation of data structure

Posted on 2004-04-06
3
Medium Priority
?
1,299 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1000 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 1000 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
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
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month14 days, 10 hours left to enroll

771 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