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

Introduction

We therefore recommend using Microsoft Visual Studio 2010 for MLPI application development on the windows platform; using the Express version is also approved. You can download the Express version under http://www.microsoft.com/visualstudio/en-us/products/2010-editions/visual-cpp-express

Learn how to set up a simple Microsoft Visual Studio 2010 Express project which runs on a standard windows platform and is able to connect to an 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 the Project

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

vs10eNewProject.png

On the left side, please select Win32 and start using a simple 'Win32 Console Application'.

vs10eProjectSettings.png

Finish the project wizard by clicking 'Finish'.

Setting Up Visual Studio

Since it is not possible to add the library path as default in the Express version, you have to set it individually for every new project. To do this, you have to right-click the project root in the solution explorer and choose properties. You can find the "Additional Include Directories" under Configuration Properties->C/C++->General. Add the path to your <install>\include directory. You have to perform this step for Configuration->Release too!

vs10eDirectoryInclude.png

The "Additional Library Directories" can be found under Configuration Properties->Linker->General. Here, you should add the path to your library file located in the installation directory. The static library is found in the <install>\lib directory, whereas the shared library is located in the <install>\lib directory. The specification of the directory containing the library file must also be done for the Configuration->Release.

Note
Starting at Server Version 1.18 the use of static libraries has been deprecated and hence the shared library must be used.
vs10eDirectoryLib.png

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).

vs10eProjectRuntime.png
Note
If you don't want to use the static Multi-threaded (/MT) runtime libraries, but the dynamic linking Multi-threaded DLL (/MD) runtime libraries, 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 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 needed MLPI headers.

#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 Debug->Build Solution from the Visual Studio menu.

Starting the Project

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