Re: C# - getting binary data from .lib

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



I thought that you might be on to something, but sadly it didn't work.
thanks for the help though.

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

IntPtr ptrImage = new IntPtr();
label1.Text = create_wrapped(0,5,ref ptrImage).ToString(); //this crashes
the debugger with no exception returned, I tried to catch it but that didn't
help


"Michael Phillips, Jr." <mphillips53@xxxxxxxxxxxxxxx> wrote in message
news:uJyWUbyhGHA.4044@xxxxxxxxxxxxxxxxxxxxxxx
You could try the same argument semantics used by the "Gdi32" function
CreateDIBSection which returns an array of bytes as a pointer argument.

The c# function uses [In][Out] ref IntPtr to represent the array of bytes
returned for the pointer argument passed to CreateDIBSection.
see example:

[DllImport("gdi32.dll")]
static extern IntPtr CreateDIBSection(IntPtr hdc, [In] ref BITMAPINFO
pbmi,
uint iUsage, [In][Out] ref IntPtr ppvBits, IntPtr hSection, uint
dwOffset);


"Stephen Cawood" <cawood@xxxxxxxxxx> wrote in message
news:3y7gg.16349$JX1.2431@xxxxxxxxxxx
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: 8 bit image
    ... public int biHeight; ... public static extern IntPtr SelectObject ... ref BITMAPINFO ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: Problems using ordinary GDI operations on 32bit Bitmap
    ... public const int transparent = 1; ... public static extern bool AlphaBlend( ... public static extern IntPtr SelectObject ... private void InitializeComponent() ...
    (microsoft.public.win32.programmer.gdi)
  • Re: 8 bit image
    ... > public static extern IntPtr SelectObject ... > public static extern bool BitBlt(IntPtr hdcDest, int nXDest, int nYDest, ... > public static extern IntPtr CreateCompatibleDC(IntPtr hdc); ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: Getting the NAME (not path) of a special folder.
    ... IntPtr pOleStr; ... public int left; ... [PreserveSig] ... ref IntPtr ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: QASetWindowsJournalHook by managed code
    ... public static GCHandle gc2 = GCHandle.Alloc(MouseHookProcedure, ... I tried pass MouseHookProcedure directly, ... You need to understand that an IntPtr and int and a GCHandle are all actually very closely related items. ...
    (microsoft.public.dotnet.framework.compactframework)