Creating a C# Wrapper

Introduction

The E6651_API DLL provided for remote operation of the E6651A is a Windows DLL. A wrapper is required to call the API functions from the .NET environment.  The Platform Invoke (P/Invoke) feature available in the .NET environment is used to achieve this.

Making use of the Header File

Provided with the E6651_API DLL file is a header file which lists all the E6651A remote API functions and their parameter types.  An example of a header file API function wrapped up in the .NET environment using C# is described below:

[DllImport("E6651_API.dll")]

public static extern void E6651_Init(int PortNum);

Creating the C# Wrapper

To create this wrapper, follow the steps below:

  1. Add the DLL import line specifying the name of the DLL [DllImport("E6651_API.dll")]

  2. Add “public static extern” on the next line followed by the return type of the function

  3. Add the function name, identical to that specified in the header file

Add the function parameters and corresponding parameter types for the programming environment:

Header file

C# .NET

BYTE

byte

byte

byte

char*

String or Stringbuilder

int

int

int*

out int or ref int

double

double

double*

out double or ref double

DWORD

int

DWORD*

out int or ref int