[C#]

You can use Black Ice dlls in a .NET application easily using the DllImport attribute.

If you want to use a method in C# as having an implementation from a DLL export, do the following:

-          use System.Runtime.InteropServices namespace

-          declare the method with the static and extern C# keywords

-          Attach the DllImport attribute to the method. The DllImport attribute allows you to specify the name of the DLL that contains the method. The common practice is to name the C# method the same as the exported method, but you can also use a different name for the C# method

-          Optionally, specify custom marshaling information for the method's parameters and return value, which will override the .NET Framework default marshaling

 

Example 1:

[DllImport("BiTiff.dll")]

public static extern short GetNumberOfImagesInTiffFile(string FileName);

 

In this case you can use the GetNumberOfImagesInTiffFile method from the BiTiff.dll.

 

If the method uses a structure as a parameter you have to specify custom marshaling attributes for the structure:

 

Example 2:

Consider the following structure form the BiDisp.h:

 

typedef struct tagDISPLAYSTRUCT

{

    RECT     rOrigo;        

    UINT     wDisplayFormat;

    RECT     rcScrollRange;

    POINT    pScrollPos;

    RECT     rcScale;

    POINT    pOffset; 

    POINT    pBitmapSize;

    int      biBitCount;

    RECT     rcClient;  

    POINT    ptOrg;     

    POINT    pDPIDC;    

    POINT    pDPIBitmap;

    HPALETTE hPal;      

    HDIB     hDIBBitmap;

    HBITMAP  hBitmap;   

    WORD     wInternal; 

    void     *StretchFunc;

    long     StretchData;

} DISPLAYSTRUCT, FAR *LPDISPLAYSTRUCT;

 

In C#, you can describe the preceding struct by using StructLayout:

 

[StructLayout(LayoutKind.Sequential, Size=16, CharSet=CharSet.Ansi)]

      public struct RECT

      {

            public int left;

            public int top;

            public int right;

            public int bottom;

      }

 

[StructLayout(LayoutKind.Sequential, Size=8, CharSet=CharSet.Ansi)]

      public struct POINT

      {

            public int x;

            public int y;

      }

 

[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]

      public struct DISPLAYSTRUCT

      {

            public RECT rOrigo;

            public int wDisplayFormat;

            public RECT rcScrollRange;

            public POINT pScrollPos;

            public RECT rcScale;

            public POINT pOffset;

            public POINT pBitmapSize;

            public short biBitCount;

            public RECT rcClient;

            public POINT ptOrg;

            public POINT pDPIDC;

            public POINT pDPIBitmap;

            public IntPtr hPal;

            public IntPtr hDIBBitmap;

            public IntPtr hBitmap;

            public int wInternal;

            public IntPtr StretchFunc;

            public int StretchData;

      }

 

From now on you can declare the following method from BiDisp.dll:

 

[DllImport("BiDisp.dll")]

      public static extern int DisplayWmCreate(IntPtr hWnd, int wParam, int lParam, ref DISPLAYSTRUCT cb);

 

For more information visit: http://msdn.microsoft.com/library/en-us/csref/html/vcwlkPlatformInvokeTutorial.asp?frame=true#pinvoke_callingdllexport.