C# - getting binary data from .lib



I posted this question a few days ago, but it hasn't been resolved so I'm
trying again (with better info).
I'm trying to access a C++ .lib from C#. I can get an int back fine, the
problem I'm having is returning an array of binary data. any ideas?
thanks in advance...

..lib contains this function:

/-Call create() to create a bitmap of (10*scale) x (*10*scale) bytes
//create() will fill an unsigned char array with 100*scale*scale bytes
//
//create ID=567, 5 pixels/bit, total image will be 50x50 pixels
//this function will malloc room if image is NULL
//returns -1 if problem, 0 otherwise

int create(int id, int scale, unsigned char *image);


wrapper DLL:

WIN32DLL_API int create_wrapped(int id, int scale, unsigned char *image)
{
return create(id, scale, image);
}


[DllImport("Wrapper.dll", EntryPoint="create_wrapped")]
public static extern int create_wrapped(int id, int scale, byte[] image);

byte[] bArray = new byte[500];
create_wrapped(0,5,bArray); //bArray = array of zeros



notes:
I've also tried...

public static extern int create_wrapped(int id, int scale,
[Out][MarshalAs(UnmanagedType.LPArray, SizeConst=500)]byte[] image);
//bArray = array of zeros

public static extern int create_wrapped(int id, int scale,
[MarshalAs(UnmanagedType.LPArray)]byte[] image); //bArray = array of zeros


public static extern int create_wrapped(int id, int scale,[Out] IntPtr
image); //returns -1 failure



.



Relevant Pages

  • Re: C# - getting binary data from .lib
    ... I suggest that you debug the wrapper first to see what you get if you pass a ... either way you get a pointer to allocate ... WIN32DLL_API int create_wrapped(int id, int scale, unsigned char ...
    (microsoft.public.dotnet.framework.interop)
  • Re: C# - getting binary data from .lib
    ... Remember the wrapper is returning an unmanaged pointer to an array of bytes. ... WIN32DLL_API int create_wrapped(int id, int scale, unsigned char ... public static extern int create_wrapped(int id, int scale, byte ...
    (microsoft.public.dotnet.framework.interop)
  • Re: C# - getting binary data from .lib
    ... Use (unsigned char*) rather than. ... The library should return the pointer to this allocated memory. ... WIN32DLL_API int create_wrapped(int id, int scale, unsigned char *image) ...
    (microsoft.public.dotnet.framework.interop)
  • Re: C# - getting binary data from .lib
    ... I'm reluctant to try and deal with the unmanaged pointer since ... WIN32DLL_API int create_wrapped(int id, int scale, unsigned char *image) ... public static extern int create_wrapped(int id, int scale, byte ...
    (microsoft.public.dotnet.framework.interop)
  • Re: C# - getting binary data from .lib
    ... WIN32DLL_API int create_wrapped(int id, int scale, unsigned char *image) ... IntPtr ptrImage = IntPtr.Zero; ... public static extern int create_wrapped(int id, int scale, byte ...
    (microsoft.public.dotnet.framework.interop)

Quantcast