No need to write a wrapper in C ++ / CLI. You can directly use Platform Invoke from C #:
http://msdn.microsoft.com/en-us/library/aa288468%28VS.71%29.aspx
EDIT: if you do this using the C ++ / CLI, you will need to make LoadLibrary calls and create function pointers. This is greatly simplified in C #. This is from the MSDN tutorial linked above, but with my own added comments:
class PlatformInvokeTest { [DllImport("msvcrt.dll")]
EDIT: Complex types can also be marshaled, although structures need to be defined. This example is taken from my own code that calls GDI +. I cut it off a bit.
private static int SRCCOPY = 0x00CC0020; private static uint BI_RGB = 0; private static uint DIB_RGB_COLORS = 0; [DllImport("gdi32.dll")] private static extern bool DeleteObject(IntPtr hObject); [StructLayout(LayoutKind.Sequential)] private struct BITMAPINFO { public uint biSize; public int biWidth; public int biHeight; public short biPlanes; public short biBitCount; public uint biCompression; public uint biSizeImage; public int biXPelsPerMeter; public int biYPelsPerMeter; public uint biClrUsed; public uint biClrImportant; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)] public uint[] cols; } public static Bitmap Downsample(Bitmap input, int bpp) { Bitmap retval = null;
Amy
source share