Visual C# .NET
Function specifications
The class library is being offered 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 in the form of removing the prefix of original functions. Please call the method with the name that does not contain the prefix of original function.
For example, when you want to call the TimInit function
Ret = tim.Init();
Function parameters and return value
The contents of the parameters and the return value of a function are independent of the development language, and are common. Please refer to the function reference for details.
Sample programs
Please use the following samples.
\Program Files\CONTEC\API-PAC(W32)\XXX\Samples\VCSNET
(XXX is DIO, AIO and CNT etc.)
Creating a project
Startup Visual Studio .NET, choose File-New-Project. In the New Project dialog box, choose Visual C# Projects from Project Types, and then choose Windows Application from Templates.
Enter the name of the project you want to create in the Name field, and in the Location field, enter the sub directory if it is necessary for the new project.
A new project will be created by clicking the [OK] button.
Including the class library
The Class library cs file is necessary to use driver functions in Visual C# .NET.
Add the cs file by choosing Project-Add Existing Item.
Add the namespace.
Add the namespace to use methods in the class library. Please add a line of code shown below into the beginning of C# source code (.cs file).
Take TIMER for example
using CtimewrCs;
Creating the class instance
To use the class library, create an instance of the class.
Please add a line of code shown below into the form class of C# source code (.cs file).
Take TIMER for example
public class Form1 :System.Windows.Forms.Form
{
Ctimerw timerw = new Ctimerw(); // added
Format of the function reference
The type declaration has changed in Visual C++ and Visual C# .NET.
Therefore, please refer to the function declaration in a sample program for the type of a parameter in the Format.
The example of changing the type declaration
Visual C++ Visual C# .NET
BYTE * -> string or StringBuilder
DWORD -> uint
DWORD * -> ref uint or uint[]
Notes of using callback function
When notifying an interval timer event by using callback function in Visual C# .NET,
it is required to fix the callback function's memory address.
The following code is the sample to process an interval timer event.
For details, please refer to the sample programs.
■Declaring as global variables.
GCHandle gCh;
PTM_INTERVAL_CALLBACK pdelegate_func;
IntPtr pfunc;
■In the Load method, initializing the delegate for interrupt process, and add a reference to prevent garbage collection from being destroyed.
pdelegate_func = new PTM_INTERVAL_CALLBACK(CallBackProc);
gCh = GCHandle.Alloc(pdelegate_func);
■In the Close method, releasing the handle.
gCh.Free();
■Retrieving the fixed function pointer.
pfunc = Marshal.GetFunctionPointerForDelegate(pdelegate_func);
■Specifying the retrieved fixed pointer by function TimTimerCallBackProc.
Ret = timerw.TimerCallBackProc(Id, pfunc, Temp);