Open Core Interface - MLPI
MLPI-MotionLogicProgrammingInterface(mlpiCore)  1.26.2
Creating a new C/C++ project for Windows using Visual Studio 2005

Introduction

Although we recommend using Microsoft Visual Studio 2010 for MLPI Application development on a windows platform, it is also possible to use the older Microsoft Visual Studio 2005 version.

Learn how to set up a simple Microsoft Visual Studio 2005 project which runs on a standard windows platform and is able to connect to a MLPI device using MLPI function calls. All MLPI function calls are tunneled through TCP/IP over an Ethernet connection to the control. Please keep in mind that hard real-time from your application to the control is not possible using this setup.

Setting Up Visual Studio

You may want to include the paths to the MLPI-SDK as the default search path of your development environment. This way, you don't need to worry about absolute paths or copying the libs and headers to your project directory. To do this, open Visual Studio 2005 and go to Tools->Options->Projects And Solutions->VC++ Directories. In the left combo box called Platform, you have to select Win32. In the right combo box, choose Include Files and add the path to your <install>\mlpiCoreClient\include directory. Do the same for the Library Files, but insert the path to your library <install>\mlpiCoreClient\bin\... path.

Note
Starting at Server Version 1.18 the use of static libraries has been deprecated. In order to link the static library into the desired project, it is necessary to link the corresponding library with extension ".lib" located in the <install>\mlpiCore\bin path. This library will automatically link the shared library located in the same folder. In the following Subsection (Setting Up the Project) a different mannet to link the dynamic library is presented.
vsOptionsPath.png

It is also possible to set this option for each individual project in the project settings. To do this, you have to right-click the project root in the solution explorer and choose the Properties. You can find the "Additional Include Directories" under Configuration Properties->C/C++->General and the "Additional Library Directories" under Configuration Properties->Linker->General.

vsDirectorySettings.png

Setting Up the Project

Start Visual Studio 2005 and create a new project: ( From Menu: File->New->Project ).

vsNewProject32.png

On the left side, please select Visual C++ -> Win32 and start using a simple 'Win32 Console Application'.

vsProjectSettings32.png

Finish the project wizard by clicking 'Finish'. As an additional step, you have to change the link options for the runtime libraries from dynamic linking(/MD) to static linking(/MT). You can change this in the project options ( From Menu: Project->Properties). Then go to Configuration Properties->C/C++->Code Generation->Runtime Library and select Multi-threaded (/MT).

vsProjectRuntime32.png

You now have an empty Win32 project and may want to start developing with the MLPI-API library.

You therefore have to include the MLPI library as well as the required MLPI headers.

#pragma comment (lib, "libmlpiwin32.lib")
#include <mlpiApiLib.h>
#include <mlpiSystemLib.h>
Note
If you don't want to use the static Multi-threaded (/MT) runtime libraries, but the dynamic linking Multi-threaded DLL (/MD), then please use the MLPI library "libmlpiwin32_msvcrt.lib" instead of "libmlpiwin32.lib" in the pragma comment or your project settings. This might be necessary if you want to build for example a MFC application.
You have also the option to link dynamically against the MLPI by using dllmlpiwin32.dll. To do this, you have to link against "dllmlpiwin32.lib" and need to deploy the file dllmlpiwin32.dll. together with your application. It can be found in the SDK directory under <install>\mlpiCoreClient\bin\.... This might be necessary if you get linker conflicts with other static libraries your application might depend on. Or if you want to use a newer version of Visual Studio.

You are now able to use MLPI functions. Here is some example code showing how to connect to an MLPI device and read the current firmware version. Don't forget to replace the IP address of your control in the example code.

#include "stdafx.h"
#include <windows.h>
#pragma comment (lib, "libmlpiwin32.lib")
#include <mlpiGlobal.h>
#include <wchar16.h>
#include <mlpiApiLib.h>
#include <mlpiSystemLib.h>
int _tmain(int argc, _TCHAR* argv[])
{
WCHAR16 szText[128]={0};
//
// connect to API
//
MLPIRESULT result = mlpiApiConnect(L"192.168.0.1 -user=mlpiTest -password=mlpiTest", &connection); // replace with own control IP
if (MLPI_FAILED(result))
{
printf("\nERROR: failed to connect to MLPI. ErrorCode: 0x%08x", (unsigned)result);
return result;
}
//
// read and display some control information
//
// read control name
mlpiSystemGetName(connection, szText, _countof(szText));
printf("\nControlName: %S", szText);
// read firmware version information
mlpiSystemGetVersionInfo(connection, MLPI_VERSION_FIRMWARE, szText, _countof(szText));
printf("\nFirmware-Version: %S", szText);
//
// disconnect from mlpi and shutdown api
//
result = mlpiApiDisconnect(&connection);
if (MLPI_FAILED(result))
{
printf("\nERROR: failed to disconnect from MLPI. ErrorCode: 0x%08x", (unsigned)result);
return result;
}
connection = MLPI_INVALIDHANDLE;
printf("\n\n\n\npress key to quit");
getchar();
return 0;
}

Build your project by selecting Build->Build Solution from the Visual Studio menu.

Starting the Project

To start your project, select Build->Start Debugging or press F5. Your application should start running and you should see the name and firmware version of your device.