Click here to Skip to main content
16,017,726 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, Im trying to convert a C++ struct to a C# struct. By using these struct i will use the parameter from the struct to use it on a function.

C++
typedef unsigned char uint8;
typedef int sint32;
typedef struct BY_BITMAP
{
    sint32 biWidth;      
    sint32 biHeight;     
    sint32 biBitCount;   
    sint32 bfSize;       
    sint32 BytesPerLine; 
    uint8 **ScanLine;    
    uint8 *buffer;       
}BY_BITMAP;


At the main program i would use these to code for the function

public void SavePic()
{
 ByBitmap[] sources = new ByBitmap[2];
            sources[0] = new ByBitmap();
            sources[0].buffer = null;
            sources[0].ScanLine = null;
            sources[1] = new ByBitmap();
            sources[1].buffer = null;
            sources[1].ScanLine = null;
ScannerIDnative.SavePicToStream(ref sources,IDcardMode)
}


The struct that i done dosent work, can anyone help?

What I have tried:

public struct ByBitmap
   {

       public int biWidth;
       public int biHeight;
       public int biBitCount;
       public int bfSize;
       public int BytesPerLine;
       public byte[] ScanLine;
       public byte[] buffer;
   }
Posted
Updated 3-Nov-17 1:31am

1 solution

The int types of your struct should work correctly, but for the byte[] you must allocate buffer in the runtime of CSharp. For that you must know the needed size of these values and make that call before.

The other way is to get the bytes buffers from C++ and make a copy in C#.

Take a look at my article and its code specially at the function buildBuffer and its usage.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900