Notes of Using Visual C#

Function specifications

A class library is provided as an interface for C#.
The driver functions are called from the methods of the class library.
The methods in the class library are defined as the original functions without the prefix.
Please call the method with the name of the original function without the prefix.

For example, when using CanInit function

Ret = can.Init();

* Not compatible with Universal Windows Platform (UWP)

Function parameters and return value

The contents of the parameters and the return value of functions are common regardless of the development language.
Please refer to the function reference for details.

Note of using callback function

In Visual C#, when notifying an interrupt using a callback function, it is required to add processing to fix the memory address of the callback function.

As an example of the code necessary for these processes, we will use interrupt processing as an example.
For details, please refer to the sample programs.

■Declaring as global variables.

GCHandle gCh;

PINTCALLBACK pdelegate_func;

IntPtr pfunc;

■In the Load method, initialize the interrupt handler delegate, and add a reference to it so it will not be destroyed by garbage collection.

pdelegate_func= new PINTCALLBACK(CallBackProc);

gCh= GCHandle.Alloc(pdelegate_func);

■In the Closed method, release the handle.

gCh.Free();

■Retrieving the fixed function pointer.

pfunc = Marshal.GetFunctionPointerForDelegate(pdelegate_func);

■In NotifyEvent, specify the retrieved fixed pointer.

Ret = can.NotifyEvent(Id, pfunc, Temp);