[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")]

publicstaticexternshort 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)]

      publicstruct RECT

      {

            publicint left;

            publicint top;

            publicint right;

            publicint bottom;

      }

 

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

      publicstruct POINT

      {

            publicint x;

            publicint y;

      }

 

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

      publicstruct DISPLAYSTRUCT

      {

            public RECT rOrigo;

            publicint wDisplayFormat;

            public RECT rcScrollRange;

            public POINT pScrollPos;

            public RECT rcScale;

            public POINT pOffset;

            public POINT pBitmapSize;

            publicshort biBitCount;

            public RECT rcClient;

            public POINT ptOrg;

            public POINT pDPIDC;

            public POINT pDPIBitmap;

            public IntPtr hPal;

            public IntPtr hDIBBitmap;

            public IntPtr hBitmap;

            publicint wInternal;

            public IntPtr StretchFunc;

            publicint StretchData;

      }

 

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

 

[DllImport("BiDisp.dll")]

      publicstaticexternint 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.