I am trying to display a SGI format image (.rgb) into a picturebox using SetDIBitsToDevice API.

The image file does not have header information.

But calling this function raises a argument exception, that parameter is incorrect. But I am not able to identify the incorrect parameter.
//API declaration
        public static extern int SetDIBitsToDevice(IntPtr hDC, int DestX, int DestY, uint wDestWidth, uint wDestHeight, int SrcX, int SrcY, uint uStartScan, uint uScanLines, byte[] lpBits, ref BITMAPINFO BitsInfo, uint uColorUse);

        public static extern IntPtr CreateCompatibleDC(IntPtr hDC);

public struct PALETTEENTRY
            public byte peRed;
            public byte peGreen;
            public byte peBlue;
            //public byte peFlags;

        public struct BITMAPINFOHEADER
            public uint biSize;
            public int biWidth;
            public int biHeight;
            public ushort biPlanes;
            public ushort biBitCount;
            public uint biCompression;
            public uint biSizeImage;
            public int biXPelsPerMeter;
            public int biYPelsPerMeter;
            public uint biClrUsed;
            public uint biClrImportant;
        public struct BITMAPINFO
            public BITMAPINFO(BITMAPINFOHEADER bmiHeader)
                this.bmiHeader = bmiHeader;
                bmiColors = new PALETTEENTRY[256];
            public BITMAPINFOHEADER bmiHeader;
            public PALETTEENTRY[] bmiColors;

        public const int BI_RGB = 0;
        public const int DIB_RGB_COLORS = 0;
Calling this API
byte[] data = System.IO.File.ReadAllBytes("test.rgb");

//arranging bits to display RGB file correctly
byte[] data3 = (new ReadImage(ref data)).ReadChannels();

                PrintImage.BITMAPINFOHEADER bmiHeader = new PrintImage.BITMAPINFOHEADER();
                bmiHeader.biSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(bmiHeader);
                bmiHeader.biWidth = 400;
                bmiHeader.biHeight = -400;
                //bmiHeader.biPlanes = 1;
                bmiHeader.biBitCount = 24;
                //bmiHeader.biClrUsed = 0;
                //bmiHeader.biClrImportant = 0;
                bmiHeader.biCompression = PrintImage.BI_RGB;
                bmiHeader.biSizeImage = 400 * 400;

                PrintImage.BITMAPINFO bmi = new PrintImage.BITMAPINFO(bmiHeader);

                IntPtr lhDC = PrintImage.CreateCompatibleDC(PrintImage.GetWindowDC(pictureBox1.Handle));

                int test = PrintImage.SetDIBitsToDevice(lhDC, 0, 0, 400, 400, 0, 0, 0, 400, data3, ref bmi, PrintImage.DIB_RGB_COLORS);
I know I have hardcoded few things like width, height etc., but for this example, it has been fixed.

Where could be the problem? I tried same API in VC++ (VS 2008), and it si displaying the image correctly.

What other options are available? I am ready/willing to learn this stuff.

Thank you