Translate from C++

G

Guest

Hi all,
I need some help translating a C++ function that returns a pointer to a
Structure.

Here is the original C++ declare:
LPBITMAPINFO IMAPI ImgGetInfo(HANDLE hImage, LPINT lpbFlags)

Here's what I have so far in the VB.NET version:
<Serializable(), StructLayout(LayoutKind.Sequential)> _
Public Structure BITMAPINFOHEADER '40 bytes
Public biSize As Integer
Public biWidth As Integer
Public biHeight As Integer
Public biPlanes As Short
Public biBitCount As Integer
Public biCompression As Integer
Public biSizeImage As Integer
Public biXPelsPerMeter As Integer
Public biYPelsPerMeter As Integer
Public biClrUsed As Short
Public biClrImportant As Integer
End Structure

<Serializable(), StructLayout(LayoutKind.Sequential)> _
Public Structure BITMAPINFO
Public bmiHeader As BITMAPINFOHEADER
Public bmiColors As RGBQUAD
End Structure

<Serializable(), StructLayout(LayoutKind.Sequential)> _
Public Structure RGBQUAD
Public rgbBlue As Byte
Public rgbGreen As Byte
Public rgbRed As Byte
Public rgbReserved As Byte
End Structure

Declare Ansi Function ImgGetInfo Lib "someDLLname.dll" (ByVal img As
Integer, ByRef lFlags As Integer) As BITMAPINFO

Can someone tell me if the VB.net translation is correct, and if not, how to
do the VB.Net declare correctly?

Thanks!
 
I

Imran Koradia

Try this:

Declare Ansi Function ImgGetInfo Lib "someDLLname.dll" (ByVal img As _
Integer, ByRef lFlags As Integer) As IntPtr

Dim StructPtr As IntPtr = ImgGetInfo(img, lFlags)

Dim MyStruct As BITMAPINFO = CType(Marshal.PtrToStructure(StructPtr, _
GetType(BITMAPINFO)), BITMAPINFO)

hope that helps..
Imran.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top