Skip to main content

Notes for Microsoft .NET Framework

When using Microsoft .NET Framework (hereafter ".NET environment") as your development environment, structure and constant definitions differ from the native interface. For details, see the API reference below.

API Reference

Supported .NET Framework version is 4.0 or later.

info

The bundled samples have been used with v4.6 (C# sample) and v4.5.2 (SDK GUI sample).

Structure Definitions

In a .NET environment, structures are defined as value structs. Member variable types are changed to C++/CLI-compatible types, while member names and structure definitions remain unchanged. However, some structures are handled as exceptions.

(1) In StMPXAPIVersion (API version information), the member APIVersion is defined as a string, as shown below.

StMPXAPIVersion

(2) In StMPXDeviceInfo (device information for MicroPeckerX), the member Model is defined as a string, as shown below.

StMPXDeviceInfo

Usage in Visual Studio

When using this SDK in C# or VB.NET, add the following wrapper DLL to your Visual Studio project references.

.NET EnvironmentWrapper DLL
32-bitMPXCtrldotNET40Free.dll
64-bitMPXCtrldotNET40Free_x64.dll

Example Settings for 32-bit

The following is an example setup procedure when using Microsoft Visual C++ 2019 as the development environment.

  1. Right-click References in Solution Explorer.
Setting Example 1
  1. Select Add Reference... from the context menu.
Setting Example 2
  1. In the Reference Manager dialog, click the Browse button and select MPXCtrldotNET40Free.dll in the file dialog.
Setting Example 3
  1. Confirm MPXCtrldotNET40Free.dll appears in the reference list and is checked, then click OK.
Setting Example 4
  1. Confirm MPXCtrldotNET40Free.dll is added under References in Solution Explorer.
Setting Example 5
tip

If the DLL information file (same name as the wrapper DLL with extension changed to .xml) is stored in the same folder as the wrapper DLL, API details are shown in code completion.

Required DLLs at Runtime

Referencing only the wrapper DLL is not sufficient to run the application. At runtime, place the native DLL in the same folder as your executable.

Runtime ProcessWrapper DLLNative DLL
32-bitMPXCtrldotNET40Free.dllMPXCtrlFree.dll
64-bitMPXCtrldotNET40Free_x64.dllMPXCtrlFree_x64.dll

For detailed bundled files, see Product Composition.

Match Bitness Exactly

  • Do not load 64-bit DLLs in a 32-bit process.
  • Do not load 32-bit DLLs in a 64-bit process.
  • Even when using AnyCPU, unify referenced/deployed DLLs according to the runtime environment.

If bitness does not match, BadImageFormatException or DLL load failure occurs.

Initializing Array Members in C#

Some structures in the .NET wrapper contain array members. After allocating the outer array with new, explicitly initialize array members of each element as well.

// Initialization example for CAN Slot/Log
var slots = new StMPXCANSlot[28];
for (int i = 0; i < slots.Length; i++)
{
slots[i].Increment = new byte[64];
slots[i].Frame.Data = new byte[64];
}

var canLogs = new StMPXCANLog[1024];
for (int i = 0; i < canLogs.Length; i++)
{
canLogs[i].Data = new byte[64];
}

// Initialization example for LIN Sim/Log
var masterSims = new StMPXLINMasterSim[2];
for (int i = 0; i < masterSims.Length; i++)
{
masterSims[i].Item = new StMPXLINMasterSimItem[64];
}

StMPXLINSlaveSim slaveSim = new StMPXLINSlaveSim();
slaveSim.Item = new StMPXLINSlaveSimItem[64];

var linLogs = new StMPXLINLog[1024];
for (int i = 0; i < linLogs.Length; i++)
{
linLogs[i].Data = new byte[64];
}

Accessing them without initialization causes NullReferenceException.