Converting C# to VB.net question. what is [StructLayout(LayoutKind.Sequential)]?

G

Guest

H
I am try to convert C# to vb.net I don’t know what would be an equivalent statements in VB.net any help will be appreciated.

[StructLayout(LayoutKind.Sequential)
public class BITMAPINFOHEADER
public int biSize = Marshal.SizeOf(typeof(BITMAPINFOHEADER)
public int biWidt
public int biHeigh
public short biPlane
public short biBitCoun
public int biCompressio
public int biSizeImag
public int biXPelsPerMete
public int biYPelsPerMete
public int biClrUse
public int biClrImportan


' <summary
' Holds all bitmap informatio
' </summary
[StructLayout(LayoutKind.Sequential)
public class BITMAPINFO
public BITMAPINFOHEADER bmiHeader = new BITMAPINFOHEADER(

[MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst=BITMAPINFO_MAX_COLORSIZE*4)
public byte[] bmiColors ' RGBQUAD structs... Blue-Green-Red-Reserved, repeat..


' <summary
' Palette entry structur
' </summary
[StructLayout(LayoutKind.Sequential)
public struct PALETTEENTRY
public byte peRe
public byte peGree
public byte peBlu
public byte peFlag


' <summary
' Holds all bitmap information in a flat structure (contains no other classes or structs
' </summary
[StructLayout(LayoutKind.Sequential)
public struct BITMAPINFO_FLAT
public int bmiHeader_biSize' = Marshal.SizeOf(typeof(BITMAPINFOHEADER)
public int bmiHeader_biWidt
public int bmiHeader_biHeigh
public short bmiHeader_biPlane
public short bmiHeader_biBitCoun
public int bmiHeader_biCompressio
public int bmiHeader_biSizeImag
public int bmiHeader_biXPelsPerMete
public int bmiHeader_biYPelsPerMete
public int bmiHeader_biClrUse
public int bmiHeader_biClrImportan

[MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst=BITMAPINFO_MAX_COLORSIZE*4)
public byte[] bmiColors ' RGBQUAD structs... Blue-Green-Red-Reserved, repeat..


' Native method
[DllImport("gdi32")
public static extern int GetPaletteEntries(int hpal, int iStartIndex, int nEntries, byte[] lppe
[DllImport("gdi32")
public static extern int GetSystemPaletteEntries(int hdc, int iStartIndex, int nEntries, byte[] lppe
[DllImport("gdi32")
public static extern int CreateDIBSection(int hdc, ref NativeMethods.BITMAPINFO_FLAT bmi, int iUsage, ref int ppvBits, int hSection, int dwOffset
[DllImport("gdi32")
public static extern int GetObjectType(int hobject
[DllImport("gdi32")
public static extern int CreateCompatibleDC(int hDC
[DllImport("gdi32")
public static extern int CreateCompatibleBitmap(int hDC, int width, int height
[DllImport("gdi32")
public static extern int GetDIBits(int hdc, int hbm, int arg1, int arg2, int arg3, NativeMethods.BITMAPINFOHEADER bmi, int arg5
[DllImport("gdi32")
public static extern int GetDIBits(int hdc, int hbm, int arg1, int arg2, int arg3, ref NativeMethods.BITMAPINFO_FLAT bmi, int arg5
[DllImport("gdi32")
public static extern int SelectObject(int hdc, int obj
[DllImport("gdi32")
public static extern bool DeleteObject(int hObject
[DllImport("gdi32")]
public static extern bool DeleteDC(int hDC)
[DllImport("gdi32")]
public static extern bool BitBlt(int hDC, int x, int y, int nWidth, int nHeight,
int hSrcDC, int xSrc, int ySrc, int dwRop)
[DllImport("gdi32")]
public static extern int GetDeviceCaps(int hDC, int nIndex)
}
 
G

Guest

Are you simply asking about the declaration? The attribute would be declared the same way in VB.NET as in C#, except with pointy brackets instead of square brackets

<StructLayout(LayoutKind.Sequential)

By specifiying the struct layout, you are telling the CLR specifically how to arrange the fields of your struct in memory. Normally, this is handled by the CLR and you could care less about its in-memory layout, but when dealing with unmanaged code, there are many cases where the code being called expects a certain layout, so the StructLayout attribute allows you to specify it explicitly.
 
A

arjang

Why are you going from C# to VB?

VB shouldnt even be called a programming language.

Regards
 

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