瀏覽代碼

add untracked files onto git

gsp 1 年之前
父節點
當前提交
b84bf1d6b3

+ 1205 - 0
OTSCPP/OTSControl/Bruker/Bruker.API.CommonFunctions.cpp

@@ -0,0 +1,1205 @@
+/*
+Bruker.API.CommonFunctions.cpp
+Implementation for Bruker CommonFunctions used by Esprit- and M4-API 
+
+Microsoft Visual Studio 2015
+*/
+#include "stdafx.h"
+#include <windows.h>
+#include <stdio.h>
+#include <stdint.h>
+#include "Bruker.API.CommonFunctions.h"
+namespace BrukerDll
+{
+
+	// type definitions for callback functions
+	typedef int32_t (WINAPI *PSetLanguage)(char* Language);
+	typedef int32_t (WINAPI *PQueryServers)(char* pServerList, int32_t BufSize);
+	typedef int32_t (WINAPI *PQueryUser)(char* pServer, char* pClientBuf, int32_t BufSize);
+	typedef int32_t (WINAPI *POpenClient)(char* pServer, char* pUser, char* pPassword, bool StartNew, bool GUI, uint32_t& CID);
+	typedef int32_t (WINAPI *POpenClientEx)(char* pServer, char* pUser, char* pPassword, const TOpenClientOptions& Options, uint32_t& CID);
+	typedef int32_t (WINAPI *POpenClientTCP)(char* pServer, char* pUser, char* pPassword, char* pHost, WORD Port, const TOpenClientOptions Options, uint32_t& CID);
+	typedef int32_t (WINAPI *PQueryInfo)(uint32_t CID, char* pInfo, int32_t BufSize);
+	typedef int32_t (WINAPI *PCloseConnection)(uint32_t CID);
+	typedef int32_t (WINAPI *PCloseClient)(uint32_t CID);
+	typedef int32_t (WINAPI *PGetDebugErrorString)(uint32_t CID, int32_t aError, char* pErrorStr, int32_t& BufSize);
+	typedef int32_t (WINAPI *PWriteDebugErrorStringToLog)(uint32_t CID, int32_t aError);
+	typedef int32_t (WINAPI *PCheckConnection)(uint32_t CID);
+	typedef int32_t (WINAPI *PCombineSpectrometer)(uint32_t CID, int32_t Devices);
+	typedef int32_t (WINAPI *PGetSpectrometerStatus)(uint32_t CID, int32_t SPU, TRTSpectrometerStatus& Status);
+	typedef int32_t (WINAPI *PSetDetectorCoolingMode)(uint32_t CID, int32_t SPU, int32_t Det, int32_t aCoolingMode);
+	typedef int32_t (WINAPI *PResetSpectrometerInterlock)(uint32_t CID, int32_t SPU);
+	typedef int32_t (WINAPI *PStartSpectrumMeasurement)(uint32_t CID, int32_t Device, uint32_t RealTime);
+	typedef int32_t (WINAPI *PStartSpectrumLifeTimeMeasurement)(uint32_t CID, int32_t Device, uint32_t LifeTime);
+	typedef int32_t (WINAPI *PStartSpectrumCounterMeasurement)(uint32_t CID, int32_t SPU, double StartEnergy, double EndEnergy, uint32_t Counts);
+	typedef int32_t (WINAPI *PStopSpectrumMeasurement)(uint32_t CID, int32_t Device);
+	typedef int32_t (WINAPI *PGetSpectrumMeasureState)(uint32_t CID, int32_t Device, bool& Running, double& State, double& PulseRate);
+	typedef int32_t (WINAPI *PGetSpectrumMeasureStateEx)(uint32_t CID, int32_t Device, bool& Running, double& State, double& PulseRate, int32_t& RealTime);
+	typedef int32_t (WINAPI *PReadSpectrum)(uint32_t CID, int32_t Device);
+	typedef int32_t (WINAPI *PGetSpectrometerConfiguration)(uint32_t CID, int32_t SPU, uint32_t& MaxEnergy, uint32_t& PulseThroughput);
+	typedef int32_t (WINAPI *PGetSpectrometerConfigurationEx)(uint32_t CID, int32_t SPU, int32_t Det, uint32_t& MaxEnergyIndex, uint32_t& PulseThroughputIndex);
+	typedef int32_t (WINAPI *PSetSpectrometerConfiguration)(uint32_t CID, int32_t SPU, int32_t Det, const uint32_t MaxEnergyIndex, const uint32_t PulseThroughputIndex);
+	typedef int32_t (WINAPI *PSetActiveDetectors)(uint32_t CID, int32_t SPU, const uint32_t Detectors);
+	typedef int32_t (WINAPI *PGetActiveDetectors)(uint32_t CID, int32_t SPU, uint32_t& Detectors);
+	typedef int32_t (WINAPI *PGetAvailableDetectors)(uint32_t CID, int32_t SPU, uint32_t& Detectors);
+	typedef int32_t (WINAPI *PGetAvailableWDSDetectors)(uint32_t CID, int32_t SPU, uint32_t& Detectors);
+	typedef int32_t (WINAPI *PGetHardwareConfiguration)(uint32_t CID, TRTHardwareConfiguration& aHardwareConfiguration);
+	typedef int32_t (WINAPI *PCalibrateSpectrometer)(uint32_t CID, int32_t Device, bool ShowProgress, PRTCalibSettings Settings, PRTCalibResults Results);
+	typedef int32_t (WINAPI *PGetSpectrometerParam)(uint32_t CID, int32_t Device, char* ParamName, char* ParamType, void* Buffer, int32_t BufSize);
+	typedef int32_t (WINAPI *PGetSpectrometerCount)(uint32_t CID, int32_t& Value);
+	typedef int32_t (WINAPI *PGetSpectrometerRanges)(uint32_t CID, int32_t SPU, int32_t Det, TRTDetectorRanges& aDetectorSettings);
+	typedef int32_t (WINAPI *PGetSpectrometerParams)(uint32_t CID, int32_t SPU, void* Buffer, int32_t& BufSize);
+	typedef int32_t (WINAPI *PGetSpectrum)(uint32_t CID, int32_t Buffer, PRTSpectrumHeaderRec pSpectrumBuf, int32_t BufSize);
+	typedef int32_t (WINAPI *PQuantifySpectrum)(uint32_t CID, int32_t Buffer, char* pMethodName, char* pParams, char* pResultBuf, int32_t ResultBufSize);
+	typedef int32_t (WINAPI *PSendRCLCommand)(uint32_t CID, int32_t Device, char* pCommand, char* pAnswer, int32_t AnswerBufSize);
+	typedef int32_t (WINAPI *PSendRCLCommandOnly)(uint32_t CID, int32_t Device, char* Command);
+	typedef int32_t (WINAPI *PReceiveRCLAnswer)(uint32_t CID, int32_t Device, char* Answer, int32_t AnswerBufSize);
+	typedef int32_t (WINAPI *PLockSpectrometer)(uint32_t CID, int32_t Device);
+	typedef int32_t (WINAPI *PUnlockSpectrometer)(uint32_t CID, int32_t Device);
+	typedef int32_t (WINAPI *PLoadSpectrum)(uint32_t CID, char* pFileName);
+	typedef int32_t (WINAPI *PPutSpectrum)(uint32_t CID, void* Spectrum, int32_t BufSize);
+	typedef int32_t (WINAPI *PSaveSpectrum)(uint32_t CID, int32_t Buffer, char* pFileName);
+	typedef int32_t (WINAPI *PCreateSpectrum)(char* SpectrometerParams, PRTSpectrumHeaderRec SpectrumData, char* ResultData, int32_t& ResultSize);
+	typedef int32_t (WINAPI *PGetCorrectedSpectrum)(char* SpectrometerParams, PRTSpectrumHeaderRec Spectrum, double* ResultData);
+	typedef int32_t (WINAPI *PShowSpectrum)(uint32_t CID, int32_t Buffer, char* Name);
+	typedef int32_t (WINAPI *PDeleteSpectrum)(uint32_t CID, char* aName);
+	typedef int32_t (WINAPI *PGetSpectrumGraphic)(uint32_t CID, int32_t Buffer, int32_t Width, int32_t Height, char* Format, void* ResultBuf, uint32_t& ResultBufSize);
+	typedef int32_t (WINAPI *PGetHardwareProfiles)(uint32_t CID, char* pProfiles, int32_t BufSize);
+	typedef int32_t (WINAPI *PSetHardwareProfile)(uint32_t CID, char* pProfile);
+	typedef int32_t (WINAPI *PGetQuantificationMethods)(uint32_t CID, bool AutomaticOnly, char* pMethods, int32_t BufSize);
+	typedef int32_t (WINAPI *PGetQuantificationMethodElements)(uint32_t CID, char* MethodName, char* ElementBuffer, int32_t BufSize);
+	typedef int32_t (WINAPI *PEditQuantificationMethod)(uint32_t CID, char* MethodName);
+	typedef int32_t (WINAPI *PCopyQuantificationMethod)(uint32_t CID, char* MethodName, char* TargetName, bool ToProfile);
+	typedef int32_t (WINAPI *PGetRegionForElement)(uint32_t CID, int32_t Buffer, char* Params, char* ResultBuf, int32_t ResultBufSize);
+	typedef int32_t (WINAPI *PXRayTubeSetConfiguration)(uint32_t CID, int32_t Tube, uint32_t HighVoltage, uint32_t Current, uint32_t FilterIndex);
+	typedef int32_t (WINAPI *PXRayTubeGetState)(uint32_t CID, int32_t Tube, uint32_t& HighVoltage, uint32_t& Current, uint32_t& FilterIndex, bool& ShutterOpen);
+	typedef int32_t (WINAPI *PXRayTubeOpenShutter)(uint32_t CID, int32_t Tube);
+	typedef int32_t (WINAPI *PXRayTubeCloseShutter)(uint32_t CID, int32_t Tube);
+	typedef int32_t (WINAPI *PXRayTubeHVOn)(uint32_t CID, int32_t Tube, int32_t DestHV, int32_t DestCurrent, bool HVOn);
+	typedef int32_t (WINAPI *PXRaySetActiveTube)(uint32_t CID, int32_t Tube);
+	typedef int32_t (WINAPI *PXRayGetActiveTube)(uint32_t CID, int32_t& Tube);
+	typedef int32_t (WINAPI *PSetImageExportParameter)(uint32_t CID, int32_t ExportImageWidth, bool ExportWithOverlay);
+	typedef int32_t (WINAPI *PHyMapStop)(uint32_t CID, bool WaitForFrameEnd);
+	typedef int32_t (WINAPI *PHyMapClearDatabase)(uint32_t CID);
+	typedef int32_t (WINAPI *PHyMapGetState)(uint32_t CID, bool& Running, double& MeasureState);
+	typedef int32_t (WINAPI *PHyMapGetStateEx)(uint32_t CID, bool& Running, double& MeasureState, int32_t& CurrentLine);
+	typedef int32_t (WINAPI *PHyMapGetXYSpectrum)(uint32_t CID, int32_t X, int32_t Y, bool Corrected, PRTSpectrumHeaderRec SpectrumBuffer, int32_t BufferSize);
+	typedef int32_t (WINAPI *PHyMapGetLineSpectra)(uint32_t CID, int32_t X, int32_t Y, int32_t Count, bool Corrected, PPointerArray SpectrumBuffer, int32_t BufferSize);
+	typedef int32_t (WINAPI *PHyMapGetCompressedLineSpectra)(uint32_t CID, int32_t X, int32_t Y, int32_t Count, bool Corrected, PPointerArray SpectrumBuffer, int32_t BufferSize);
+	typedef int32_t (WINAPI *PHyMapQuantifySpectra)(uint32_t CID, PPointArray Points, int32_t PointCount, int32_t Binning, char* MethodName, char* Params, char* ResultBuf, int32_t ResultBufSize);
+	typedef int32_t (WINAPI *PHyMapSaveToFile)(uint32_t CID, char* aFileName);
+	typedef int32_t (WINAPI *PHyMapLoadFromFile)(unsigned _int32 CID, char* aFileName, int32_t& Width, int32_t& Height, int32_t& DetCount, int32_t& ImgCount);
+	typedef int32_t (WINAPI *PHyMapGetMaxPixelSpectrum)(uint32_t CID, PRTSpectrumHeaderRec SpectrumBuffer, int32_t BufferSize);
+	typedef int32_t (WINAPI *PHyMapAutoIdent)(uint32_t CID, char* pMethodName, char* pElementBuffer, int32_t ElementBufSize);
+	typedef int32_t (WINAPI *PHyMapGetImage)(uint32_t CID, char* Format, int32_t ImgChannel, void* Buffer, uint32_t& BufferSize);
+	typedef int32_t (WINAPI *PHyMapGetElementData)(uint32_t CID, int32_t ElementIndex, void* Buffer, uint32_t& BufferSize);
+	typedef int32_t (WINAPI *PHyMapGetElementImage)(uint32_t CID, char* Format, int32_t ElementIndex, void* Buffer, uint32_t& BufferSize);
+	typedef int32_t (WINAPI *PHyMapGetMixedMapImage)(uint32_t CID, char* Format, void* Buffer, uint32_t& BufferSize);
+	typedef int32_t (WINAPI *PHyMapSaveImage)(uint32_t CID, int32_t ImgChannel, char* aFileName);
+	typedef int32_t (WINAPI *PHyMapSaveElementImage)(uint32_t CID, int32_t ElementIndex, char* aFileName);
+	typedef int32_t (WINAPI *PHyMapSaveMixedMapImage)(uint32_t CID, char* aFileName);
+
+	// DLL Handle
+	HMODULE hDllBaseAddress;
+
+	// global callback function pointers
+	PSetLanguage pSetLanguage = NULL;
+	PQueryServers pQueryServers = NULL;
+	PQueryUser pQueryUser = NULL;
+	POpenClient pOpenClient = NULL;
+	POpenClientEx pOpenClientEx = NULL;
+	POpenClientTCP pOpenClientTCP = NULL;
+	PQueryInfo pQueryInfo = NULL;
+	PCloseConnection pCloseConnection = NULL;
+	PCloseClient pCloseClient = NULL;
+	PGetDebugErrorString pGetDebugErrorString = NULL;
+	PWriteDebugErrorStringToLog pWriteDebugErrorStringToLog = NULL;
+	PCheckConnection pCheckConnection = NULL;
+	PCombineSpectrometer pCombineSpectrometer = NULL;
+	PGetSpectrometerStatus pGetSpectrometerStatus = NULL;
+	PSetDetectorCoolingMode pSetDetectorCoolingMode = NULL;
+	PResetSpectrometerInterlock pResetSpectrometerInterlock = NULL;
+	PStartSpectrumMeasurement pStartSpectrumMeasurement = NULL;
+	PStartSpectrumLifeTimeMeasurement pStartSpectrumLifeTimeMeasurement = NULL;
+	PStartSpectrumCounterMeasurement pStartSpectrumCounterMeasurement = NULL;
+	PStopSpectrumMeasurement pStopSpectrumMeasurement = NULL;
+	PGetSpectrumMeasureState pGetSpectrumMeasureState = NULL;
+	PGetSpectrumMeasureStateEx pGetSpectrumMeasureStateEx = NULL;
+	PReadSpectrum pReadSpectrum = NULL;
+	PGetSpectrometerConfiguration pGetSpectrometerConfiguration = NULL;
+	PGetSpectrometerConfigurationEx pGetSpectrometerConfigurationEx = NULL;
+	PSetSpectrometerConfiguration pSetSpectrometerConfiguration = NULL;
+	PSetActiveDetectors pSetActiveDetectors = NULL;
+	PGetActiveDetectors pGetActiveDetectors = NULL;
+	PGetAvailableDetectors pGetAvailableDetectors = NULL;
+	PGetAvailableWDSDetectors pGetAvailableWDSDetectors = NULL;
+	PGetHardwareConfiguration pGetHardwareConfiguration = NULL;
+	PCalibrateSpectrometer pCalibrateSpectrometer = NULL;
+	PGetSpectrometerParam pGetSpectrometerParam = NULL;
+	PGetSpectrometerCount pGetSpectrometerCount = NULL;
+	PGetSpectrometerRanges pGetSpectrometerRanges = NULL;
+	PGetSpectrometerParams pGetSpectrometerParams = NULL;
+	PGetSpectrum pGetSpectrum = NULL;
+	PQuantifySpectrum pQuantifySpectrum = NULL;
+	PSendRCLCommand pSendRCLCommand = NULL;
+	PSendRCLCommandOnly pSendRCLCommandOnly = NULL;
+	PReceiveRCLAnswer pReceiveRCLAnswer = NULL;
+	PLockSpectrometer pLockSpectrometer = NULL;
+	PUnlockSpectrometer pUnlockSpectrometer = NULL;
+	PLoadSpectrum pLoadSpectrum = NULL;
+	PPutSpectrum pPutSpectrum = NULL;
+	PSaveSpectrum pSaveSpectrum = NULL;
+	PCreateSpectrum pCreateSpectrum = NULL;
+	PGetCorrectedSpectrum pGetCorrectedSpectrum = NULL;
+	PShowSpectrum pShowSpectrum = NULL;
+	PDeleteSpectrum pDeleteSpectrum = NULL;
+	PGetSpectrumGraphic pGetSpectrumGraphic = NULL;
+	PGetHardwareProfiles pGetHardwareProfiles = NULL;
+	PSetHardwareProfile pSetHardwareProfile = NULL;
+	PGetQuantificationMethods pGetQuantificationMethods = NULL;
+	PGetQuantificationMethodElements pGetQuantificationMethodElements = NULL;
+	PEditQuantificationMethod pEditQuantificationMethod = NULL;
+	PCopyQuantificationMethod pCopyQuantificationMethod = NULL;
+	PGetRegionForElement pGetRegionForElement = NULL;
+	PXRayTubeSetConfiguration pXRayTubeSetConfiguration = NULL;
+	PXRayTubeGetState pXRayTubeGetState = NULL;
+	PXRayTubeOpenShutter pXRayTubeOpenShutter = NULL;
+	PXRayTubeCloseShutter pXRayTubeCloseShutter = NULL;
+	PXRayTubeHVOn pXRayTubeHVOn = NULL;
+	PXRaySetActiveTube pXRaySetActiveTube = NULL;
+	PXRayGetActiveTube pXRayGetActiveTube = NULL;
+	PSetImageExportParameter pSetImageExportParameter = NULL;
+	PHyMapStop pHyMapStop = NULL;
+	PHyMapClearDatabase pHyMapClearDatabase = NULL;
+	PHyMapGetState pHyMapGetState = NULL;
+	PHyMapGetStateEx pHyMapGetStateEx = NULL;
+	PHyMapGetXYSpectrum pHyMapGetXYSpectrum = NULL;
+	PHyMapGetLineSpectra pHyMapGetLineSpectra = NULL;
+	PHyMapGetCompressedLineSpectra pHyMapGetCompressedLineSpectra = NULL;
+	PHyMapQuantifySpectra pHyMapQuantifySpectra = NULL;
+	PHyMapSaveToFile pHyMapSaveToFile = NULL;
+	PHyMapLoadFromFile pHyMapLoadFromFile = NULL;
+	PHyMapGetMaxPixelSpectrum pHyMapGetMaxPixelSpectrum = NULL;
+	PHyMapAutoIdent pHyMapAutoIdent = NULL;
+	PHyMapGetImage pHyMapGetImage = NULL;
+	PHyMapGetElementData pHyMapGetElementData = NULL;
+	PHyMapGetElementImage pHyMapGetElementImage = NULL;
+	PHyMapGetMixedMapImage pHyMapGetMixedMapImage = NULL;
+	PHyMapSaveImage pHyMapSaveImage = NULL;
+	PHyMapSaveElementImage pHyMapSaveElementImage = NULL;
+	PHyMapSaveMixedMapImage pHyMapSaveMixedMapImage = NULL;
+
+	bool LoadCommonFunctions(LPCTSTR LibFile)
+	{
+		hDllBaseAddress = LoadLibrary(LibFile);
+
+		if (!hDllBaseAddress)
+		{
+			DWORD lastError = GetLastError();
+			TCHAR buf[200];
+			int j = _stprintf_s(buf, 200, _T("CommonFunctions.cpp: Failed to load DLL %s \n"), LibFile);
+			j += _stprintf_s(buf + j, 200 - j, _T("CommonFunctions.cpp: ErrorCode: %d \n"), lastError);
+			OutputDebugString(buf);
+			return false;
+		}
+
+		pSetLanguage = (PSetLanguage)GetProcAddress(hDllBaseAddress, "SetLanguage");
+		if (!pSetLanguage) OutputDebugString(_T("Failed to Load DLL function SetLanguage\n"));
+
+		pQueryServers = (PQueryServers)GetProcAddress(hDllBaseAddress, "QueryServers");
+		if (!pQueryServers) OutputDebugString(_T("Failed to load DLL function QueryServers\n"));
+
+		pQueryUser = (PQueryUser)GetProcAddress(hDllBaseAddress, "QueryUser");
+		if (!pQueryUser) OutputDebugString(_T("Failed to load DLL function QueryUser\n"));
+
+		pOpenClient = (POpenClient)GetProcAddress(hDllBaseAddress, "OpenClient");
+		if (!pOpenClient) OutputDebugString(_T("Failed to load DLL function OpenClient\n"));
+
+		pOpenClientEx = (POpenClientEx)GetProcAddress(hDllBaseAddress, "OpenClientEx");
+		if (!pOpenClientEx) OutputDebugString(_T("Failed to load DLL function OpenClientEx\n"));
+
+		pOpenClientTCP = (POpenClientTCP)GetProcAddress(hDllBaseAddress, "OpenClientTCP");
+		if (!pOpenClientTCP) OutputDebugString(_T("Failed to load DLL function OpenClientTCP\n"));
+
+		pQueryInfo = (PQueryInfo)GetProcAddress(hDllBaseAddress, "QueryInfo");
+		if (!pQueryInfo) OutputDebugString(_T("Failed to load DLL function QueryInfo\n"));
+
+		pCloseConnection = (PCloseConnection)GetProcAddress(hDllBaseAddress, "CloseConnection");
+		if (!pCloseConnection) OutputDebugString(_T("Failed to load DLL function CloseConnection\n"));
+
+		pCloseClient = (PCloseClient)GetProcAddress(hDllBaseAddress, "CloseClient");
+		if (!pCloseClient) OutputDebugString(_T("Failed to load DLL function CloseClient\n"));
+
+		pGetDebugErrorString = (PGetDebugErrorString)GetProcAddress(hDllBaseAddress, "GetDebugErrorString");
+		if (!pGetDebugErrorString) OutputDebugString(_T("Failed to load DLL function GetDebugErrorString\n"));
+
+		pWriteDebugErrorStringToLog = (PWriteDebugErrorStringToLog)GetProcAddress(hDllBaseAddress, "WriteDebugErrorStringToLog");
+		if (!pWriteDebugErrorStringToLog) OutputDebugString(_T("Failed to load DLL function WriteDebugErrorStringToLog\n"));
+
+		pCheckConnection = (PCheckConnection)GetProcAddress(hDllBaseAddress, "CheckConnection");
+		if (!pCheckConnection) OutputDebugString(_T("Failed to load DLL function CheckConnection\n"));
+
+		pCombineSpectrometer = (PCombineSpectrometer)GetProcAddress(hDllBaseAddress, "CombineSpectrometer");
+		if (!pCombineSpectrometer) OutputDebugString(_T("Failed to load DLL function CombineSpectrometer\n"));
+
+		pGetSpectrometerStatus = (PGetSpectrometerStatus)GetProcAddress(hDllBaseAddress, "GetSpectrometerStatus");
+		if (!pGetSpectrometerStatus) OutputDebugString(_T("Failed to load DLL function GetSpectrometerStatus\n"));
+
+		pSetDetectorCoolingMode = (PSetDetectorCoolingMode)GetProcAddress(hDllBaseAddress, "SetDetectorCoolingMode");
+		if (!pSetDetectorCoolingMode) OutputDebugString(_T("Failed to load DLL function SetDetectorCoolingMode\n"));
+
+		pResetSpectrometerInterlock = (PResetSpectrometerInterlock)GetProcAddress(hDllBaseAddress, "ResetSpectrometerInterlock");
+		if (!pResetSpectrometerInterlock) OutputDebugString(_T("Failed to load DLL function ResetSpectrometerInterlock\n"));
+
+		pStartSpectrumMeasurement = (PStartSpectrumMeasurement)GetProcAddress(hDllBaseAddress, "StartSpectrumMeasurement");
+		if (!pStartSpectrumMeasurement) OutputDebugString(_T("Failed to load DLL function StartSpectrumMeasurement\n"));
+
+		pStartSpectrumLifeTimeMeasurement = (PStartSpectrumLifeTimeMeasurement)GetProcAddress(hDllBaseAddress, "StartSpectrumLifeTimeMeasurement");
+		if (!pStartSpectrumLifeTimeMeasurement) OutputDebugString(_T("Failed to load DLL function StartSpectrumLifeTimeMeasurement\n"));
+
+		pStartSpectrumCounterMeasurement = (PStartSpectrumCounterMeasurement)GetProcAddress(hDllBaseAddress, "StartSpectrumCounterMeasurement");
+		if (!pStartSpectrumCounterMeasurement) OutputDebugString(_T("Failed to load DLL function StartSpectrumCounterMeasurement\n"));
+
+		pStopSpectrumMeasurement = (PStopSpectrumMeasurement)GetProcAddress(hDllBaseAddress, "StopSpectrumMeasurement");
+		if (!pStopSpectrumMeasurement) OutputDebugString(_T("Failed to load DLL function StopSpectrumMeasurement\n"));
+
+		pGetSpectrumMeasureState = (PGetSpectrumMeasureState)GetProcAddress(hDllBaseAddress, "GetSpectrumMeasureState");
+		if (!pGetSpectrumMeasureState) OutputDebugString(_T("Failed to load DLL function GetSpectrumMeasureState\n"));
+
+		pGetSpectrumMeasureStateEx = (PGetSpectrumMeasureStateEx)GetProcAddress(hDllBaseAddress, "GetSpectrumMeasureStateEx");
+		if (!pGetSpectrumMeasureStateEx) OutputDebugString(_T("Failed to load DLL function GetSpectrumMeasureStateEx\n"));
+
+		pReadSpectrum = (PReadSpectrum)GetProcAddress(hDllBaseAddress, "ReadSpectrum");
+		if (!pReadSpectrum) OutputDebugString(_T("Failed to load DLL function ReadSpectrum\n"));
+
+		pGetSpectrometerConfiguration = (PGetSpectrometerConfiguration)GetProcAddress(hDllBaseAddress, "GetSpectrometerConfiguration");
+		if (!pGetSpectrometerConfiguration) OutputDebugString(_T("Failed to load DLL function GetSpectrometerConfiguration\n"));
+
+		pGetSpectrometerConfigurationEx = (PGetSpectrometerConfigurationEx)GetProcAddress(hDllBaseAddress, "GetSpectrometerConfigurationEx");
+		if (!pGetSpectrometerConfigurationEx) OutputDebugString(_T("Failed to load DLL function GetSpectrometerConfigurationEx\n"));
+
+		pSetSpectrometerConfiguration = (PSetSpectrometerConfiguration)GetProcAddress(hDllBaseAddress, "SetSpectrometerConfiguration");
+		if (!pSetSpectrometerConfiguration) OutputDebugString(_T("Failed to load DLL function SetSpectrometerConfiguration\n"));
+
+		pSetActiveDetectors = (PSetActiveDetectors)GetProcAddress(hDllBaseAddress, "SetActiveDetectors");
+		if (!pSetActiveDetectors) OutputDebugString(_T("Failed to load DLL function SetActiveDetectors\n"));
+
+		pGetActiveDetectors = (PGetActiveDetectors)GetProcAddress(hDllBaseAddress, "GetActiveDetectors");
+		if (!pGetActiveDetectors)OutputDebugString(_T("Failed to load DLL function GetActiveDetectors\n"));
+
+		pGetAvailableDetectors = (PGetAvailableDetectors)GetProcAddress(hDllBaseAddress, "GetAvailableDetectors");
+		if (!pGetAvailableDetectors) OutputDebugString(_T("Failed to load DLL function GetAvailableDetectors\n"));
+
+		pGetAvailableWDSDetectors = (PGetAvailableWDSDetectors)GetProcAddress(hDllBaseAddress, "GetAvailableWDSDetectors");
+		if (!pGetAvailableWDSDetectors) OutputDebugString(_T("Failed to load DLL function GetAvailableWDSDetectors\n"));
+
+		pGetHardwareConfiguration = (PGetHardwareConfiguration)GetProcAddress(hDllBaseAddress, "GetHardwareConfiguration");
+		if (!pGetHardwareConfiguration) OutputDebugString(_T("Failed to load DLL function GetHardwareConfiguration\n"));
+
+		pCalibrateSpectrometer = (PCalibrateSpectrometer)GetProcAddress(hDllBaseAddress, "CalibrateSpectrometer");
+		if (!pCalibrateSpectrometer) OutputDebugString(_T("Failed to load DLL function CalibrateSpectrometer\n"));
+
+		pGetSpectrometerParam = (PGetSpectrometerParam)GetProcAddress(hDllBaseAddress, "GetSpectrometerParam");
+		if (!pGetSpectrometerParam) OutputDebugString(_T("Failed to load DLL function GetSpectrometerParam\n"));
+
+		pGetSpectrometerCount = (PGetSpectrometerCount)GetProcAddress(hDllBaseAddress, "GetSpectrometerCount");
+		if (!pGetSpectrometerCount) OutputDebugString(_T("Failed to load DLL function GetSpectrometerCount\n"));
+
+		pGetSpectrometerRanges = (PGetSpectrometerRanges)GetProcAddress(hDllBaseAddress, "GetSpectrometerRanges");
+		if (!pGetSpectrometerRanges) OutputDebugString(_T("Failed to load DLL function GetSpectrometerRanges\n"));
+
+		pGetSpectrometerParams = (PGetSpectrometerParams)GetProcAddress(hDllBaseAddress, "GetSpectrometerParams");
+		if (!pGetSpectrometerParams) OutputDebugString(_T("Failed to load DLL function GetSpectrometerParams\n"));
+
+		pGetSpectrum = (PGetSpectrum)GetProcAddress(hDllBaseAddress, "GetSpectrum");
+		if (!pGetSpectrum) OutputDebugString(_T("Failed to load DLL function GetSpectrum\n"));
+
+		pQuantifySpectrum = (PQuantifySpectrum)GetProcAddress(hDllBaseAddress, "QuantifySpectrum");
+		if (!pQuantifySpectrum) OutputDebugString(_T("Failed to load DLL function QuantifySpectrum\n"));
+
+		pSendRCLCommand = (PSendRCLCommand)GetProcAddress(hDllBaseAddress, "SendRCLCommand");
+		if (!pSendRCLCommand) OutputDebugString(_T("Failed to load DLL funtion SendRCLCommand\n"));
+
+		pSendRCLCommandOnly = (PSendRCLCommandOnly)GetProcAddress(hDllBaseAddress, "SendRCLCommandOnly");
+		if (!pSendRCLCommandOnly) OutputDebugString(_T("Failed to load DLL function SendRCLCommandOnly\n"));
+
+		pReceiveRCLAnswer = (PReceiveRCLAnswer)GetProcAddress(hDllBaseAddress, "ReceiveRCLAnswer");
+		if (!pReceiveRCLAnswer) OutputDebugString(_T("Failed to load DLL function ReceiveRCLAnswer\n"));
+
+		pLockSpectrometer = (PLockSpectrometer)GetProcAddress(hDllBaseAddress, "LockSpectrometer");
+		if (!pLockSpectrometer) OutputDebugString(_T("Failed to load DLL function LockSpectrometer\n"));
+
+		pUnlockSpectrometer = (PUnlockSpectrometer)GetProcAddress(hDllBaseAddress, "UnlockSpectrometer");
+		if (!pUnlockSpectrometer) OutputDebugString(_T("Failed to load DLL function UnlockSpectrometer\n"));
+
+		pLoadSpectrum = (PLoadSpectrum)GetProcAddress(hDllBaseAddress, "LoadSpectrum");
+		if (!pLoadSpectrum) OutputDebugString(_T("Failed to load DLL function LoadSpectrum\n"));
+
+		pPutSpectrum = (PPutSpectrum)GetProcAddress(hDllBaseAddress, "PutSpectrum");
+		if (!pPutSpectrum) OutputDebugString(_T("Failed to load DLL function PutSpectrum\n"));
+
+		pSaveSpectrum = (PSaveSpectrum)GetProcAddress(hDllBaseAddress, "SaveSpectrum");
+		if (!pSaveSpectrum) OutputDebugString(_T("Failed to load DLL function SaveSpectrum\n"));
+
+		pCreateSpectrum = (PCreateSpectrum)GetProcAddress(hDllBaseAddress, "CreateSpectrum");
+		if (!pCreateSpectrum) OutputDebugString(_T("Failed to load DLL function CreateSpectrum\n"));
+
+		pGetCorrectedSpectrum = (PGetCorrectedSpectrum)GetProcAddress(hDllBaseAddress, "GetCorrectedSpectrum");
+		if (!pGetCorrectedSpectrum) OutputDebugString(_T("Failed to load DLL function GetCorrectedSpectrum\n"));
+
+		pShowSpectrum = (PShowSpectrum)GetProcAddress(hDllBaseAddress, "ShowSpectrum");
+		if (!pShowSpectrum) OutputDebugString(_T("Failed to load DLL function ShowSpectrum\n"));
+
+		pDeleteSpectrum = (PDeleteSpectrum)GetProcAddress(hDllBaseAddress, "DeleteSpectrum");
+		if (!pDeleteSpectrum) OutputDebugString(_T("Failed to load DLL function DeleteSpectrum\n"));
+
+		pGetSpectrumGraphic = (PGetSpectrumGraphic)GetProcAddress(hDllBaseAddress, "GetSpectrumGraphic");
+		if (!pGetSpectrumGraphic) OutputDebugString(_T("Failed to load DLL function GetSpectrumGraphic\n"));
+
+		pGetHardwareProfiles = (PGetHardwareProfiles)GetProcAddress(hDllBaseAddress, "GetHardwareProfiles");
+		if (!pGetHardwareProfiles) OutputDebugString(_T("Failed to load DLL function GetHardwareProfiles\n"));
+
+		pSetHardwareProfile = (PSetHardwareProfile)GetProcAddress(hDllBaseAddress, "SetHardwareProfile");
+		if (!pSetHardwareProfile) OutputDebugString(_T("Failed to load DLL function SetHardwareProfile\n"));
+
+		pGetQuantificationMethods = (PGetQuantificationMethods)GetProcAddress(hDllBaseAddress, "GetQuantificationMethods");
+		if (!pGetQuantificationMethods) OutputDebugString(_T("Failed to load DLL function GetQuantificationMethods\n"));
+
+		pGetQuantificationMethodElements = (PGetQuantificationMethodElements)GetProcAddress(hDllBaseAddress, "GetQuantificationMethodElements");
+		if (!pGetQuantificationMethodElements) OutputDebugString(_T("Failed to load DLL function GetQuantificationMethodElements\n"));
+
+		pEditQuantificationMethod = (PEditQuantificationMethod)GetProcAddress(hDllBaseAddress, "EditQuantificationMethod");
+		if (!pEditQuantificationMethod) OutputDebugString(_T("Failed to load DLL function EditQuantificationMethod\n"));
+
+		pCopyQuantificationMethod = (PCopyQuantificationMethod)GetProcAddress(hDllBaseAddress, "CopyQuantificationMethod");
+		if (!pCopyQuantificationMethod) OutputDebugString(_T("Failed to load DLL function CopyQuantificationMethod\n"));
+
+		pGetRegionForElement = (PGetRegionForElement)GetProcAddress(hDllBaseAddress, "GetRegionForElement");
+		if (!pGetRegionForElement) OutputDebugString(_T("Failed to load DLL function GetRegionForElement\n"));
+
+		pXRayTubeSetConfiguration = (PXRayTubeSetConfiguration)GetProcAddress(hDllBaseAddress, "XRayTubeSetConfiguration");
+		if (!pXRayTubeSetConfiguration) OutputDebugString(_T("Failed to load DLL function XRayTubeSetConfiguration\n"));
+
+		pXRayTubeGetState = (PXRayTubeGetState)GetProcAddress(hDllBaseAddress, "XRayTubeGetState");
+		if (!pXRayTubeGetState) OutputDebugString(_T("Failed to load DLL function XRayTubeGetState\n"));
+
+		pXRayTubeOpenShutter = (PXRayTubeOpenShutter)GetProcAddress(hDllBaseAddress, "XRayTubeOpenShutter");
+		if (!pXRayTubeOpenShutter) OutputDebugString(_T("Failed to load DLL function XRayTubeOpenShutter\n"));
+
+		pXRayTubeCloseShutter = (PXRayTubeCloseShutter)GetProcAddress(hDllBaseAddress, "XRayTubeCloseShutter");
+		if (!pXRayTubeCloseShutter) OutputDebugString(_T("Failed to load DLL function XRayTubeCloseShutter\n"));
+
+		pXRayTubeHVOn = (PXRayTubeHVOn)GetProcAddress(hDllBaseAddress, "XRayTubeHVOn");
+		if (!pXRayTubeHVOn) OutputDebugString(_T("Failed to load DLL function XRayTubeHVOn\n"));
+	
+		pXRaySetActiveTube = (PXRaySetActiveTube)GetProcAddress(hDllBaseAddress, "XRaySetActiveTube");
+		if (!pXRaySetActiveTube) OutputDebugString(_T("Failed to load DLL function XRaySetActiveTube\n"));
+	
+		pXRayGetActiveTube = (PXRayGetActiveTube)GetProcAddress(hDllBaseAddress, "XRayGetActiveTube");
+		if (!pXRayGetActiveTube) OutputDebugString(_T("Failed to load DLL function XRayGetActiveTube\n"));
+
+		pSetImageExportParameter = (PSetImageExportParameter)GetProcAddress(hDllBaseAddress, "SetImageExportParameter");
+		if (!pSetImageExportParameter) OutputDebugString(_T("Failed to load DLL function SetImageExportParameter\n"));
+
+		pHyMapStop = (PHyMapStop)GetProcAddress(hDllBaseAddress, "HyMapStop");
+		if (!pHyMapStop) OutputDebugString(_T("Failed to load DLL function HyMapStop\n"));
+
+		pHyMapClearDatabase = (PHyMapClearDatabase)GetProcAddress(hDllBaseAddress, "HyMapClearDatabase");
+		if (!pHyMapClearDatabase) OutputDebugString(_T("Failed to load DLL function HyMapClearDatabase\n"));
+
+		pHyMapGetState = (PHyMapGetState)GetProcAddress(hDllBaseAddress, "HyMapGetState");
+		if (!pHyMapGetState) OutputDebugString(_T("Failed to load DLL function HyMapGetState\n"));
+
+		pHyMapGetStateEx = (PHyMapGetStateEx)GetProcAddress(hDllBaseAddress, "HyMapGetStateEx");
+		if (!pHyMapGetStateEx) OutputDebugString(_T("Failed to load DLL function HyMapGetStateEx\n"));
+
+		pHyMapGetXYSpectrum = (PHyMapGetXYSpectrum)GetProcAddress(hDllBaseAddress, "HyMapGetXYSpectrum");
+		if (!pHyMapGetXYSpectrum) OutputDebugString(_T("Failed to load DLL function HyMapGetXYSpectrum\n"));
+
+		pHyMapGetLineSpectra = (PHyMapGetLineSpectra)GetProcAddress(hDllBaseAddress, "HyMapGetLineSpectra");
+		if (!pHyMapGetLineSpectra) OutputDebugString(_T("Failed to load DLL function HyMapGetLineSpectra\n"));
+   
+	   pHyMapGetCompressedLineSpectra = (PHyMapGetCompressedLineSpectra)GetProcAddress(hDllBaseAddress, "HyMapGetCompressedLineSpectra");
+		if (!pHyMapGetCompressedLineSpectra) OutputDebugString(_T("Failed to load DLL function HyMapGetCompressedLineSpectra\n"));
+
+		pHyMapQuantifySpectra = (PHyMapQuantifySpectra)GetProcAddress(hDllBaseAddress, "HyMapQuantifySpectra");
+		if (!pHyMapQuantifySpectra) OutputDebugString(_T("Failed to load DLL function HyMapQuantifySpectra\n"));
+
+		pHyMapSaveToFile = (PHyMapSaveToFile)GetProcAddress(hDllBaseAddress, "HyMapSaveToFile");
+		if (!pHyMapSaveToFile) OutputDebugString(_T("Failed to load DLL function HyMapSaveToFile\n"));
+
+		pHyMapLoadFromFile = (PHyMapLoadFromFile)GetProcAddress(hDllBaseAddress, "HyMapLoadFromFile");
+		if (!pHyMapLoadFromFile) OutputDebugString(_T("Failed to load DLL function HyMapLoadFromFile\n"));
+
+		pHyMapGetMaxPixelSpectrum = (PHyMapGetMaxPixelSpectrum)GetProcAddress(hDllBaseAddress, "HyMapGetMaxPixelSpectrum");
+		if (!pHyMapGetMaxPixelSpectrum) OutputDebugString(_T("Failed to load DLL function HyMapGetMaxPixelSpectrum\n"));
+
+		pHyMapAutoIdent = (PHyMapAutoIdent)GetProcAddress(hDllBaseAddress, "HyMapAutoIdent");
+		if (!pHyMapAutoIdent) OutputDebugString(_T("Failed to load DLL function HyMapAutoIdent\n"));
+
+		pHyMapGetImage = (PHyMapGetImage)GetProcAddress(hDllBaseAddress, "HyMapGetImage");
+		if (!pHyMapGetImage) OutputDebugString(_T("Failed to load DLL function HyMapGetImage\n"));
+
+		pHyMapGetElementData = (PHyMapGetElementData)GetProcAddress(hDllBaseAddress, "HyMapGetElementData");
+		if (!pHyMapGetElementData) OutputDebugString(_T("Failed to load DLL function HyMapGetElementData\n"));
+
+		pHyMapGetElementImage = (PHyMapGetElementImage)GetProcAddress(hDllBaseAddress, "HyMapGetElementImage");
+		if (!pHyMapGetElementImage) OutputDebugString(_T("Failed to load DLL function HyMapGetElementImage\n"));
+
+		pHyMapGetMixedMapImage = (PHyMapGetMixedMapImage)GetProcAddress(hDllBaseAddress, "HyMapGetMixedMapImage");
+		if (!pHyMapGetMixedMapImage) OutputDebugString(_T("Failed to load DLL function HyMapGetMixedMapImage\n"));
+
+		pHyMapSaveImage = (PHyMapSaveImage)GetProcAddress(hDllBaseAddress, "HyMapSaveImage");
+		if (!pHyMapSaveImage) OutputDebugString(_T("Failed to load DLL function HyMapSaveImage\n"));
+
+		pHyMapSaveElementImage = (PHyMapSaveElementImage)GetProcAddress(hDllBaseAddress, "HyMapSaveElementImage");
+		if (!pHyMapSaveElementImage) OutputDebugString(_T("Failed to load DLL function HyMapSaveElementImage\n"));
+
+		pHyMapSaveMixedMapImage = (PHyMapSaveMixedMapImage)GetProcAddress(hDllBaseAddress, "HyMapSaveMixedMapImage");
+		if (!pHyMapSaveMixedMapImage) OutputDebugString(_T("Failed to load DLL function HyMapSaveMixedMapImage\n"));
+
+		return true;
+	}
+
+	// Converts Int-Value to String-Value
+	std::string IntToString(int number)
+	{
+		std::ostringstream oss;
+		oss << number;
+		return oss.str();
+	}
+
+	// Converts Double-Value to String-Value
+	std::string DoubleToString(double number)
+	{
+		std::ostringstream oss;
+		oss.precision(4);
+		oss << number;
+		return oss.str();
+	}
+
+	int32_t  SetLanguage(char* Language)
+	{
+		if (pSetLanguage)
+			return pSetLanguage(Language);
+		else return -1;
+	}
+
+	// Query all known servers for which can be used by client program
+	int32_t QueryServers(char* pServerList, int32_t BufSize)
+	{
+		if (pQueryServers)
+			return pQueryServers(pServerList, BufSize);
+		else return -1;
+	}
+
+	// Query all running client programs for connected servers
+	int32_t QueryUser(char* pServer, char* pClientBuf, int32_t BufSize)
+	{
+		if (pQueryUser)
+			return pQueryUser(pServer, pClientBuf, BufSize);
+		else return -1;
+	}
+
+	// Start Quantax program and login automatically
+	// Password		: Password of user with UserName
+	// GUI			: Whether to start the user interface or not
+	// Result		: Function call sucessful or not ( 0 = success, otherwise error )
+	int32_t OpenClient(char* pServer, char* pUser, char* pPassword, bool StartNew, bool GUI, uint32_t& CID)
+	{
+		if (pOpenClient)
+			return pOpenClient(pServer, pUser, pPassword, StartNew, GUI, CID);
+		else return -1;
+	}
+
+
+	int32_t OpenClientEx(char* pServer, char* pUser, char* pPassword, const TOpenClientOptions& Options, uint32_t& CID)
+	{
+		if (pOpenClientEx)
+			return pOpenClientEx(pServer, pUser, pPassword, Options, CID);
+		else return -1;
+	}
+
+	int32_t OpenClientTCP(char* pServer, char* pUser, char* pPassword, char* pHost, uint16_t Port, const TOpenClientOptions Options, uint32_t& CID)
+	{
+		if (pOpenClientTCP)
+			return pOpenClientTCP(pServer, pUser, pPassword, pHost, Port, Options, CID);
+		else return -1;
+	}
+
+	// query some information about a specific connection
+	int32_t QueryInfo(uint32_t CID, char* pInfo, int32_t BufSize)
+	{
+		if (pQueryInfo)
+			return pQueryInfo(CID, pInfo, BufSize);
+		else return -1;
+	}
+
+	// Close current connection
+	// Result		: Function call sucessful or not ( 0 = success, otherwise error )
+	int32_t CloseConnection(uint32_t CID)
+	{
+		if (pCloseConnection)
+			return pCloseConnection(CID);
+		else return -1;
+	}
+
+	// Stop Quantax
+	// Result		: Function call sucessful or not ( 0 = success, otherwise error )
+	int32_t CloseClient(uint32_t CID)
+	{
+		if (pCloseClient)
+			return pCloseClient(CID);
+		else return -1;
+	}
+
+	// returns description string for error values
+	int32_t GetDebugErrorString(uint32_t CID, int32_t aError, char* pErrorStr, int32_t& BufSize)
+	{
+		if (pGetDebugErrorString)
+			return pGetDebugErrorString(CID, aError, pErrorStr, BufSize);
+		else return -1;
+	}
+
+	// writes description string for error values to log
+	int32_t WriteDebugErrorStringToLog(uint32_t CID, int32_t aError)
+	{
+		if (pWriteDebugErrorStringToLog)
+			return pWriteDebugErrorStringToLog(CID, aError);
+		else return -1;
+	}
+
+	// Is a specific client connection ok?
+	int32_t  CheckConnection(uint32_t CID)
+	{
+		if (pCheckConnection)
+			return pCheckConnection(CID);
+		else return -1;
+	}
+
+	// Devices		: bit combination of spectrometers to combine
+	// Result		: Function call sucessful or not ( 0 = success, otherwise error )
+	int32_t CombineSpectrometer(uint32_t CID, int32_t Devices)
+	{
+		if (pCombineSpectrometer)
+			return pCombineSpectrometer(CID, Devices);
+		else return -1;
+	}
+
+	int32_t GetSpectrometerStatus(uint32_t CID, int32_t SPU, TRTSpectrometerStatus& Status)
+	{
+		if (pGetSpectrometerStatus)
+			return pGetSpectrometerStatus(CID, SPU, Status);
+		else return -1;
+	}
+	int32_t SetDetectorCoolingMode(uint32_t CID, int32_t SPU, int32_t Det, int32_t aCoolingMode)
+	{
+		if (pSetDetectorCoolingMode)
+			return pSetDetectorCoolingMode(CID, SPU, Det, aCoolingMode);
+		else return -1;
+	}
+	int32_t ResetSpectrometerInterlock(uint32_t CID, int32_t SPU)
+	{
+		if (pResetSpectrometerInterlock)
+			return pResetSpectrometerInterlock(CID, SPU);
+		else return -1;
+	}
+
+	// Device		: Number of spectrometer ( 1 in most cases )
+	// RealTime		: Measure time in ms ( 0 means endless measurement )
+	// Result		: Function call sucessful or not ( 0 = success, otherwise error )
+	int32_t StartSpectrumMeasurement(uint32_t CID, int32_t Device, uint32_t RealTime)
+	{
+		if (pStartSpectrumMeasurement)
+			return pStartSpectrumMeasurement(CID, Device, RealTime);
+		else return -1;
+	}
+
+	// Device		: Number of spectrometer ( 1 in most cases )
+	// LifeTime		: Life time in ms ( > 0 )
+	// Result		: Function call sucessful or not ( 0 = success, otherwise error )
+	int32_t StartSpectrumLifeTimeMeasurement(uint32_t CID, int32_t Device, uint32_t LifeTime)
+	{
+		if (pStartSpectrumLifeTimeMeasurement)
+			return pStartSpectrumLifeTimeMeasurement(CID, Device, LifeTime);
+		else return -1;
+	}
+
+	// Device       : Number of spectrometer ( 1 in most cases )
+	// StartEnergy,
+	// EndEnergy	: Spectrum region borders for counter measurement (in keV)
+	// Counts		: Counter value for automatic measurement stop 
+	// Result       : Function call sucessful or not ( 0 = success, otherwise error )
+	int32_t StartSpectrumCounterMeasurement(uint32_t CID, int32_t SPU, double StartEnergy, double EndEnergy, uint32_t Counts)
+	{
+		if (pStartSpectrumCounterMeasurement)
+			return pStartSpectrumCounterMeasurement(CID, SPU, StartEnergy, EndEnergy, Counts);
+		else return -1;
+	}
+
+	// Device		: Number of spectrometer ( 1 in most cases )
+	// Result		: Function call sucessful or not ( 0 = success, otherwise error )
+	int32_t StopSpectrumMeasurement(uint32_t CID, int32_t Device)
+	{
+		if (pStopSpectrumMeasurement)
+			return pStopSpectrumMeasurement(CID, Device);
+		else return -1;
+	}
+
+
+	// Read some values about current aquisition
+	// Device		: Number of spectrometer ( 1 in most cases )
+	// Running		: Aquisition active or not
+	// State		: State of aquisition in % ( 100 % means ready )
+	// PulseRate
+	// Result		: Function call sucessful or not ( 0 = success, otherwise error )
+	int32_t GetSpectrumMeasureState(uint32_t CID, int32_t Device, bool& Running, double& State, double& PulseRate)
+	{
+		if (pGetSpectrumMeasureState)
+			return pGetSpectrumMeasureState(CID, Device, Running, State, PulseRate);
+		else return -1;
+	}
+
+	// Device		: Number of spectrometer ( 1 in most cases )
+	// Running		: Aquisition active or not
+	// State        : State of aquisition in % ( 100 % means ready )
+	// PulseRate	: current input pulse rate in cps
+	// RealTime		: current measure time in ms
+	// Result		: Function call sucessful or not ( 0 = success, otherwise error )
+	int32_t GetSpectrumMeasureStateEx(uint32_t CID, int32_t Device, bool& Running, double& State, double& PulseRate, int32_t& RealTime)
+	{
+		if (pGetSpectrumMeasureStateEx)
+			return pGetSpectrumMeasureStateEx(CID, Device, Running, State, PulseRate, RealTime);
+		else return -1;
+	}
+
+	// Read current spectrum from spectrometer to buffer
+	// Device		: Number of spectrometer ( 1 in most cases )
+	// Result		: Function call sucessful or not ( 0 = success, otherwise error )
+	int32_t ReadSpectrum(uint32_t CID, int32_t Device)
+	{
+		if (pReadSpectrum)
+			return pReadSpectrum(CID, Device);
+		else return -1;
+	}
+
+	int32_t GetSpectrometerConfiguration(uint32_t CID, int32_t SPU, uint32_t& MaxEnergy, uint32_t& PulseThroughput)
+	{
+		if (pGetSpectrometerConfiguration)
+			return pGetSpectrometerConfiguration(CID, SPU, MaxEnergy, PulseThroughput);
+		else return -1;
+	}
+
+	// Read current spectrometer configuration for a given detector
+	int32_t GetSpectrometerConfigurationEx(uint32_t CID, int32_t SPU, int32_t Det, uint32_t& MaxEnergyIndex, uint32_t& PulseThroughputIndex)
+	{
+		if (pGetSpectrometerConfigurationEx)
+			return pGetSpectrometerConfigurationEx(CID, SPU, Det, MaxEnergyIndex, PulseThroughputIndex);
+		else return -1;
+	}
+	int32_t SetSpectrometerConfiguration(uint32_t CID, int32_t SPU, int32_t Det, const uint32_t MaxEnergyIndex, const uint32_t PulseThroughputIndex)
+	{
+		if (pSetSpectrometerConfiguration)
+			return pSetSpectrometerConfiguration(CID, SPU, Det, MaxEnergyIndex, PulseThroughputIndex);
+		else return -1;
+	}
+	// Detectors : Active Detectors as bitmask (1 shl 0, etc.)
+	int32_t SetActiveDetectors(uint32_t CID, int32_t SPU, const uint32_t Detectors)
+	{
+		if (pSetActiveDetectors)
+			return pSetActiveDetectors(CID, SPU, Detectors);
+		else return -1;
+	}
+	// Detectors : Active Detectors as bitmask (1 shl 0, etc.)
+	int32_t GetActiveDetectors(uint32_t CID, int32_t SPU, uint32_t& Detectors)
+	{
+		if (pGetActiveDetectors)
+			return GetActiveDetectors(CID, SPU, Detectors);
+		else return -1;
+	}
+	// Detectors : Available Detectors as bitmask (1 shl 0, etc.)
+	int32_t GetAvailableDetectors(uint32_t CID, int32_t SPU, uint32_t& Detectors)
+	{
+		if (pGetAvailableDetectors)
+			return pGetAvailableDetectors(CID, SPU, Detectors);
+		else return -1;
+	}
+	// Detectors : Available WDSDetectors as bitmask (1 shl 0, etc.)
+	int32_t GetAvailableWDSDetectors(uint32_t CID, int32_t SPU, uint32_t& Detectors)
+	{
+		if (pGetAvailableWDSDetectors)
+			return pGetAvailableWDSDetectors(CID, SPU, Detectors);
+		else return -1;
+	}
+
+	int32_t GetHardwareConfiguration(uint32_t CID, TRTHardwareConfiguration& aHardwareConfiguration)
+	{
+		if (pGetHardwareConfiguration)
+			return pGetHardwareConfiguration(CID, aHardwareConfiguration);
+		else return -1;
+	}
+
+
+	// Device		: Number of spectrometer ( 1 in most cases )
+	// Result		: Function call sucessful or not ( 0 = success, otherwise error )
+	int32_t CalibrateSpectrometer(uint32_t CID, int32_t Device, bool ShowProgress, PRTCalibSettings Settings, PRTCalibResults Results)
+	{
+		if (pCalibrateSpectrometer)
+			return pCalibrateSpectrometer(CID, Device, ShowProgress, Settings, Results);
+		else return -1;
+	}
+
+	// Device		: Number of spectrometer ( 1 in most cases )
+	// ParamName	: Name of the parameter to read
+	//                 Current implemented names: 'MaxEnergy', 'PulseThroughput', 'DetectorTemperature' as 'Integer' or 'Double'
+	// ParamType	: Type of the parameter to read (Byte,Boolean,Word,Integer,Double,Memory)
+	// Buffer		: Pointer to variable of that type
+	// BufSize		: if ParamType is Memory than BufSize if size of the memory block described by 'Buffer'
+	// Result		: Function call sucessful or not ( 0 = success, otherwise error )
+	int32_t GetSpectrometerParam(uint32_t CID, int32_t Device, char* ParamName, char* ParamType, void* Buffer, int32_t BufSize)
+	{
+		if (pGetSpectrometerParam)
+			return pGetSpectrometerParam(CID, Device, ParamName, ParamType, Buffer, BufSize);
+		else return -1;
+	}
+
+	// Reads the amount of available spectrometers
+	int32_t GetSpectrometerCount(uint32_t CID, int32_t& Value)
+	{
+		if (pGetSpectrometerCount)
+			return pGetSpectrometerCount(CID, Value);
+		else return -1;
+	}
+
+	// Gets SpectrometerRanges (Pulserate and EnergyRange)
+	// MaxEnergy
+	// PulseThroughPut
+	// EnergyIndexCount
+	// PulseIndexCount
+	int32_t GetSpectrometerRanges(uint32_t CID, int32_t SPU, int32_t Det, TRTDetectorRanges& aDetectorSettings)
+	{
+		if (pGetSpectrometerRanges)
+			return pGetSpectrometerRanges(CID, SPU, Det, aDetectorSettings);
+		else return -1;
+	}
+
+	// Read full parameter block of current spectrometer params (needed to create full Bruker spectrum)
+	int32_t GetSpectrometerParams(uint32_t CID, int32_t SPU, void* Buffer, int32_t& BufSize)
+	{
+		if (pGetSpectrometerParams)
+			return pGetSpectrometerParams(CID, SPU, Buffer, BufSize);
+		else return -1;
+	}
+
+	// Buffer		: Buffer index ( 0 for loaded spectrum buffer, > 0 for spectrometer buffers )
+	// Result		: Function call sucessful or not ( 0 = success, otherwise error )
+	int32_t GetSpectrum(uint32_t CID, int32_t Buffer, PRTSpectrumHeaderRec pSpectrumBuf, int32_t BufSize)
+	{
+		if (pGetSpectrum)
+			return pGetSpectrum(CID, Buffer, pSpectrumBuf, BufSize);
+		else return -1;
+	}
+
+	// Device		: Number of spectrometer ( 1 in most cases )
+	// Result		: Function call sucessful or not ( 0 = success, otherwise error )
+	int32_t QuantifySpectrum(uint32_t CID, int32_t Buffer, char* pMethodName, char* pParams, char* pResultBuf, int32_t ResultBufSize)
+	{
+		if (pQuantifySpectrum)
+			return pQuantifySpectrum(CID, Buffer, pMethodName, pParams, pResultBuf, ResultBufSize);
+		else return -1;
+	}
+
+	// Sends a RCL 2.2 command to spectrometer and returns the answer( see RCL 2.2 description of commands )
+	// Device		: Number of spectrometer ( 1 in most cases )
+	// Result		: Function call sucessful or not ( 0 = success, otherwise error )
+	int32_t SendRCLCommand(uint32_t CID, int32_t Device, char* pCommand, char* pAnswer, int32_t AnswerBufSize)
+	{
+		if (pSendRCLCommand)
+			return pSendRCLCommand(CID, Device, pCommand, pAnswer, AnswerBufSize);
+		else return -1;
+	}
+
+	// Sends a RCL 2.2 command to spectrometer, does not wait for answer ( see RCL 2.2 description of commands )
+	int32_t SendRCLCommandOnly(uint32_t CID, int32_t Device, char* Command)
+	{
+		if (pSendRCLCommandOnly)
+			return pSendRCLCommandOnly(CID, Device, Command);
+		else return -1;
+	}
+
+	// Receives the answer of the above function
+	int32_t ReceiveRCLAnswer(uint32_t CID, int32_t Device, char* Answer, int32_t AnswerBufSize)
+	{
+		if (pReceiveRCLAnswer)
+			return pReceiveRCLAnswer(CID, Device, Answer, AnswerBufSize);
+		else return -1;
+	}
+
+	// Interupts QM100's communication to specified device until 'UnlockSpectrometer' is called
+	int32_t LockSpectrometer(uint32_t CID, int32_t Device)
+	{
+		if (pLockSpectrometer)
+			return pLockSpectrometer(CID, Device);
+		else return -1;
+	}
+
+	int32_t UnlockSpectrometer(uint32_t CID, int32_t Device)
+	{
+		if (pUnlockSpectrometer)
+			return pUnlockSpectrometer(CID, Device);
+		else return -1;
+	}
+
+	// Load spectrum from file to buffer
+	// pFilename	: Complete filename for spectrum ( normally with *.spx extension )
+	// Result		: Function call sucessful or not ( 0 = success, otherwise error )
+	int32_t LoadSpectrum(uint32_t CID, char* pFileName)
+	{
+		if (pLoadSpectrum)
+			return pLoadSpectrum(CID, pFileName);
+		else return -1;
+	}
+
+	// Send spectrum back to 'loaded' buffer	
+	// Spectrum		: Bruker spectrum buffer
+	// BufferSize	: size of spectrum buffer
+	// Result		: Function call sucessful or not ( 0 = success, otherwise error )
+	// Remarks		: if one wants to use that function one has to build a complete Bruker spectrum with
+	//                functions 'GetSpectrum', 'GetSpectrometerParams' and 'CreateSpectrum'
+	int32_t PutSpectrum(uint32_t CID, void* Spectrum, int32_t BufSize)
+	{
+		if (pPutSpectrum)
+			return pPutSpectrum(CID, Spectrum, BufSize);
+		else return -1;
+	}
+
+	// Save spectrum buffer to file	
+	// pFilename	: Complete filename for spectrum ( normally with *.spx extension )
+	// Result		: Function call sucessful or not ( 0 = success, otherwise error )
+	int32_t SaveSpectrum(uint32_t CID, int32_t Buffer, char* pFileName)
+	{
+		if (pSaveSpectrum)
+			return pSaveSpectrum(CID, Buffer, pFileName);
+		else return -1;
+	}
+
+	// Create a complete Bruker spectrum from
+	int32_t CreateSpectrum(char* SpectrometerParams, PRTSpectrumHeaderRec SpectrumData, char* ResultData, int32_t& ResultSize)
+	{
+		if (pCreateSpectrum)
+			return pCreateSpectrum(SpectrometerParams, SpectrumData, ResultData, ResultSize);
+		else return -1;
+	}
+
+	int32_t GetCorrectedSpectrum(char* SpectrometerParams, PRTSpectrumHeaderRec Spectrum, double* ResultData)
+	{
+		if (pGetCorrectedSpectrum)
+			return pGetCorrectedSpectrum(SpectrometerParams, Spectrum, ResultData);
+		else return -1;
+	}
+
+	int32_t ShowSpectrum(uint32_t CID, int32_t Buffer, char* Name)
+	{
+		if (pShowSpectrum)
+			return pShowSpectrum(CID, Buffer, Name);
+		else return -1;
+	}
+
+	int32_t DeleteSpectrum(uint32_t CID, char* aName)
+	{
+		if (pDeleteSpectrum)
+			return pDeleteSpectrum(CID, aName);
+		else return -1;
+	}
+
+	// Buffer         : Buffer index ( 0 for loaded spectrum buffer, > 0 for spectrometer buffers )
+	// Width,
+	// Height         : Graphic dimension
+	// Format         : bmp, png, jpeg, tif
+	// ResultBuf      : should be able to save the whole image
+	// ResultBufSize  : input is maximum, output is really used
+	int32_t GetSpectrumGraphic(uint32_t CID, int32_t Buffer, int32_t Width, int32_t Height, char* Format, void* ResultBuf, uint32_t& ResultBufSize)
+	{
+		if (pGetSpectrumGraphic)
+			return pGetSpectrumGraphic(CID, Buffer, Width, Height, Format, ResultBuf, ResultBufSize);
+		else return -1;
+	}
+
+	// Get a list of avaliable hardware profiles from client
+	int32_t GetHardwareProfiles(uint32_t CID, char* pProfiles, int32_t BufSize)
+	{
+		if (pGetHardwareProfiles)
+			return pGetHardwareProfiles(CID, pProfiles, BufSize);
+		else return -1;
+	}
+
+	// Set a specific hardware profile
+	int32_t SetHardwareProfile(uint32_t CID, char* pProfile)
+	{
+		if (pSetHardwareProfile)
+			return pSetHardwareProfile(CID, pProfile);
+		else return -1;
+	}
+
+	// Get a list of avaliable quantification methods
+	int32_t GetQuantificationMethods(uint32_t CID, bool AutomaticOnly, char* pMethods, int32_t BufSize)
+	{
+		if (pGetQuantificationMethods)
+			return pGetQuantificationMethods(CID, AutomaticOnly, pMethods, BufSize);
+		else return -1;
+	}
+
+	// Get a list of predefined elements from a given quant method
+	int32_t GetQuantificationMethodElements(uint32_t CID, char* MethodName, char* ElementBuffer, int32_t BufSize)
+	{
+		if (pGetQuantificationMethodElements)
+			return pGetQuantificationMethodElements(CID, MethodName, ElementBuffer, BufSize);
+		else return -1;
+	}
+
+	// Call method editor for a given quant method
+	int32_t EditQuantificationMethod(uint32_t CID, char* MethodName)
+	{
+		if (pEditQuantificationMethod)
+			return pEditQuantificationMethod(CID, MethodName);
+		else return -1;
+	}
+
+	// Loads a method and saves it again. purpose: rename, conversion from mtd into mtdx
+	int32_t CopyQuantificationMethod(uint32_t CID, char* MethodName, char* TargetName, bool ToProfile)
+	{
+		if (pCopyQuantificationMethod)
+			return pCopyQuantificationMethod(CID, MethodName, TargetName, ToProfile);
+		else return -1;
+	}
+
+	// Get a channel region for desired element and X ray line
+	int32_t GetRegionForElement(uint32_t CID, int32_t Buffer, char* Params, char* ResultBuf, int32_t ResultBufSize)
+	{
+		if (pGetRegionForElement)
+			return pGetRegionForElement(CID, Buffer, Params, ResultBuf, ResultBufSize);
+		else return -1;
+	}
+
+	// HighVoltage : tube voltate [Volt]
+	// Current     : tube current [µA]
+	// FilterIndex : index of selected filter
+	int32_t XRayTubeSetConfiguration(uint32_t CID, int32_t Tube, uint32_t HighVoltage, uint32_t Current, uint32_t FilterIndex)
+	{
+		if (pXRayTubeSetConfiguration)
+			return pXRayTubeSetConfiguration(CID, Tube, HighVoltage, Current, FilterIndex);
+		else return -1;
+	}
+
+	// HighVoltage : tube voltate [Volt]
+	// Current     : tube current [µA]
+	// FilterIndex : index of selected filter
+	int32_t XRayTubeGetState(uint32_t CID, int32_t Tube, uint32_t& HighVoltage, uint32_t& Current, uint32_t& FilterIndex, bool& ShutterOpen)
+	{
+		if (pXRayTubeGetState)
+			return pXRayTubeGetState(CID, Tube, HighVoltage, Current, FilterIndex, ShutterOpen);
+		else return -1;
+	}
+
+	int32_t XRayTubeOpenShutter(uint32_t CID, int32_t Tube)
+	{
+		if (pXRayTubeOpenShutter)
+			return pXRayTubeOpenShutter(CID, Tube);
+		else return -1;
+	}
+
+	int32_t XRayTubeCloseShutter(uint32_t CID, int32_t Tube)
+	{
+		if (pXRayTubeCloseShutter)
+			return pXRayTubeCloseShutter(CID, Tube);
+		else return -1;
+	}
+
+	int32_t XRaySetActiveTube(uint32_t CID, int32_t Tube)
+	{
+		if (pXRaySetActiveTube)
+			return pXRaySetActiveTube(CID, Tube);
+		else return -1;
+	}
+
+	int32_t XRayGetActiveTube(uint32_t CID, int32_t& Tube)
+	{
+		if (pXRayGetActiveTube)
+			return pXRayGetActiveTube(CID, Tube);
+		else return -1;
+	}
+
+	int32_t XRayTubeHVOn(uint32_t CID, int32_t Tube, int32_t DestHV, int32_t DestCurrent, bool HVOn)
+	{
+		if (pXRayTubeHVOn)
+			return pXRayTubeHVOn(CID, Tube, DestHV, DestCurrent, HVOn);
+		else return -1;
+	}
+	int32_t SetImageExportParameter(uint32_t CID, int32_t ExportImageWidth, bool ExportWithOverlay)
+	{
+		if (pSetImageExportParameter)
+			return pSetImageExportParameter(CID, ExportImageWidth, ExportWithOverlay);
+		else return -1;
+	}
+
+	int32_t HyMapStop(uint32_t CID, bool WaitForFrameEnd)
+	{
+		if (pHyMapStop)
+			return pHyMapStop(CID, WaitForFrameEnd);
+		else return -1;
+	}
+
+	int32_t HyMapClearDatabase(uint32_t CID)
+	{
+		if (pHyMapClearDatabase)
+			return pHyMapClearDatabase(CID);
+		else return -1;
+	}
+
+	int32_t HyMapGetState(uint32_t CID, bool& Running, double& MeasureState)
+	{
+		if (pHyMapGetState)
+			return pHyMapGetState(CID, Running, MeasureState);
+		else return -1;
+	}
+
+	int32_t HyMapGetStateEx(uint32_t CID, bool& Running, double& MeasureState, int32_t& CurrentLine)
+	{
+		if (pHyMapGetStateEx)
+			return pHyMapGetStateEx(CID, Running, MeasureState, CurrentLine);
+		else return -1;
+	}
+
+	int32_t HyMapGetXYSpectrum(uint32_t CID, int32_t X, int32_t Y, bool Corrected, PRTSpectrumHeaderRec SpectrumBuffer, int32_t BufferSize)
+	{
+		if (pHyMapGetXYSpectrum)
+			return pHyMapGetXYSpectrum(CID, X, Y, Corrected, SpectrumBuffer, BufferSize);
+		else return -1;
+	}
+
+	// SpectrumBuffer : pointer to array of pointers for spectra, must have space for 'Count' pointers, each with allocated space for a full spectrum
+	int32_t HyMapGetLineSpectra(uint32_t CID, int32_t X, int32_t Y, int32_t Count, bool Corrected, PPointerArray SpectrumBuffer, int32_t BufferSize)
+	{
+		if (pHyMapGetLineSpectra)
+			return pHyMapGetLineSpectra(CID, X, Y, Count, Corrected, SpectrumBuffer, BufferSize);
+		else return -1;
+	}
+
+	// SpectrumBuffer : pointer to array of pointers for spectra, must have space for 'Count' pointers, each with allocated space for a full spectrum
+	int32_t HyMapGetCompressedLineSpectra(uint32_t CID, int32_t X, int32_t Y, int32_t Count, bool Corrected, PPointerArray SpectrumBuffer, int32_t BufferSize)
+	{
+		if (pHyMapGetCompressedLineSpectra)
+			return pHyMapGetCompressedLineSpectra(CID, X, Y, Count, Corrected, SpectrumBuffer, BufferSize);
+		else return -1;
+	}
+
+	int32_t HyMapQuantifySpectra(uint32_t CID, PPointArray Points, int32_t PointCount, int32_t Binning, char* MethodName, char* Params, char* ResultBuf, int32_t ResultBufSize)
+	{
+		if (pHyMapQuantifySpectra)
+			return pHyMapQuantifySpectra(CID, Points, PointCount, Binning, MethodName, Params, ResultBuf, ResultBufSize);
+		else return -1;
+	}
+
+	// aFileName   : file name
+	int32_t HyMapSaveToFile(uint32_t CID, char* aFileName)
+	{
+		if (pHyMapSaveToFile)
+			return pHyMapSaveToFile(CID, aFileName);
+		else return -1;
+	}
+
+	// aFileName   : file name
+	int32_t HyMapLoadFromFile(unsigned _int32 CID, char* aFileName, int32_t& Width, int32_t& Height, int32_t& DetCount, int32_t& ImgCount)
+	{
+		if (pHyMapLoadFromFile)
+			return pHyMapLoadFromFile(CID, aFileName, Width, Height, DetCount, ImgCount);
+		else return -1;
+	}
+
+	// SpectrumBuffer : pointer to memory, must have space for one full spectrum
+	// BufferSize     : size of the above buffer
+	int32_t HyMapGetMaxPixelSpectrum(uint32_t CID, PRTSpectrumHeaderRec SpectrumBuffer, int32_t BufferSize)
+	{
+		if (pHyMapGetMaxPixelSpectrum)
+			return pHyMapGetMaxPixelSpectrum(CID, SpectrumBuffer, BufferSize);
+		else return -1;
+	}
+
+	// pMethodName    : name of method to be used
+	// pElementBuffer : buffer to get a list of atomic numbers as result of element identification
+	// ElementBufSize : size of element buffer
+	int32_t HyMapAutoIdent(uint32_t CID, char* pMethodName, char* pElementBuffer, int32_t ElementBufSize)
+	{
+		if (pHyMapAutoIdent)
+			return pHyMapAutoIdent(CID, pMethodName, pElementBuffer, ElementBufSize);
+		else return -1;
+	}
+
+	// Format       : bmp, png, jpeg, tif
+	// ImgChannel   : the plane to be shown
+	// Buffer       : should be able to save the whole image
+	// Buffersize   : input is maximum, output is really used
+	int32_t HyMapGetImage(uint32_t CID, char* Format, int32_t ImgChannel, void* Buffer, uint32_t& BufferSize)
+	{
+		if (pHyMapGetImage)
+			return pHyMapGetImage(CID, Format, ImgChannel, Buffer, BufferSize);
+		else return -1;
+	}
+
+	// ElementIndex : the plane to be shown
+	// Buffer       : should be able to save the whole image
+	// Buffersize   : input is maximum, output is really used
+	int32_t HyMapGetElementData(uint32_t CID, int32_t ElementIndex, void* Buffer, uint32_t& BufferSize)
+	{
+		if (pHyMapGetElementData)
+			return pHyMapGetElementData(CID, ElementIndex, Buffer, BufferSize);
+		else return -1;
+	}
+
+	// Format       : bmp, png, jpeg, tif
+	// ElementIndex : the plane to be shown
+	// Buffer       : should be able to save the whole image
+	// Buffersize   : input is maximum, output is really used
+	int32_t HyMapGetElementImage(uint32_t CID, char* Format, int32_t ElementIndex, void* Buffer, uint32_t& BufferSize)
+	{
+		if (pHyMapGetElementImage)
+			return pHyMapGetElementImage(CID, Format, ElementIndex, Buffer, BufferSize);
+		else return -1;
+	}
+
+	// Format       : bmp, png, jpeg, tif
+	// Buffer       : should be able to save the whole image
+	// Buffersize   : input is maximum, output is really used
+	int32_t HyMapGetMixedMapImage(uint32_t CID, char* Format, void* Buffer, uint32_t& BufferSize)
+	{
+		if (pHyMapGetMixedMapImage)
+			return pHyMapGetMixedMapImage(CID, Format, Buffer, BufferSize);
+		else return -1;
+	}
+
+	// ImgChannel   : the plane to be shown
+	// aFileName   : file name
+	int32_t HyMapSaveImage(uint32_t CID, int32_t ImgChannel, char* aFileName)
+	{
+		if (pHyMapSaveImage)
+			return pHyMapSaveImage(CID, ImgChannel, aFileName);
+		else return -1;
+	}
+
+	// ElementIndex : the plane to be shown
+	// aFileName   : file name
+	int32_t HyMapSaveElementImage(uint32_t CID, int32_t ElementIndex, char* aFileName)
+	{
+		if (pHyMapSaveElementImage)
+			return pHyMapSaveElementImage(CID, ElementIndex, aFileName);
+		else return -1;
+	}
+
+	// aFileName   : file name
+	int32_t HyMapSaveMixedMapImage(uint32_t CID, char* aFileName)
+	{
+		if (pHyMapSaveMixedMapImage)
+			return pHyMapSaveMixedMapImage(CID, aFileName);
+		else return -1;
+	}
+}

+ 720 - 0
OTSCPP/OTSControl/Bruker/Bruker.API.CommonFunctions.h

@@ -0,0 +1,720 @@
+/*
+Bruker.API.CommonTypes.h
+Header File for Bruker Common-Interface
+
+Microsoft Visual Studio 2015
+*/
+#pragma once
+#ifndef BrukerAPICommonFunctionsH
+#define BrukerAPICommonFunctionsH
+
+#include <stddef.h>
+#include <stdint.h>
+#include <tchar.h>
+#include <iostream>
+#include <sstream>
+#include <string>
+namespace BrukerDll
+{ 
+	struct TOpenClientOptions;
+	struct TRTAPISpectrumHeaderRec;
+	struct TRTCalibResults;
+	struct TRTCalibSettings;
+	struct TRTDetectorRanges;
+	struct TRTDetectorStatus;
+	struct TRTHardwareConfiguration;
+	struct TRTSpectrometerStatus;
+
+	#pragma pack(push, 1)					// structure to describe a point, should be compatible to Windows.Point
+	struct TPoint {
+		int32_t X;
+		int32_t Y;
+	};
+	#pragma pack(pop)
+
+
+	#pragma pack(push, 1)
+	struct TRTSpectrumHeaderRec {
+		uint8_t IdentifierLength;
+		char Identifier[25];			// 'Rontec XRay spectrum'
+		int32_t Version;				// Version information
+		int32_t Size;					// Size in byte
+		double DateTime;				// Delphi 5.0 version of date and time
+		int32_t ChannelCount;			//
+		int32_t ChannelOffset;			// First channel index
+		double CalibrationAbs;			// Energy of first channel
+		double CalibrationLin;          // keV per channel
+		double SigmaAbs;				// Sigma^2 energy calibration
+		double SigmaLin;
+		// additional data compared to normal Roentec header
+		int32_t RealTime;					// real measure time in ms
+		int32_t LifeTime;					// life time in ms
+	};
+	#pragma pack(pop)
+
+
+	typedef TRTSpectrumHeaderRec* PRTSpectrumHeaderRec;
+
+	#pragma pack(push, 1)
+	struct TRTCalibSettings {
+		int32_t Version;				// Version of record structure, should be '1' at the moment
+		int32_t Element1;
+		char* Line1;
+		double Energy1;
+		int32_t Element2;
+		char* Line2;
+		double Energy2;
+		int32_t MaxTime;				// Maximum time to calibrate in ms, '0' indicates to use a internal statistics to decide to stop
+	#ifdef	BRUKERAPIESPRITH
+		bool ShowProgress;				// Show progress information
+	#endif
+	};
+	#pragma pack(pop)
+
+	typedef TRTCalibSettings* PRTCalibSettings;
+
+	#pragma pack(push, 1)
+	struct TRTCalibResults {
+		int32_t Version;
+		double CalibLin, CalibAbs, FWHM, Fano;
+	};
+	#pragma pack(pop)
+
+
+	typedef TRTCalibResults* PRTCalibResults;
+
+	#pragma pack(push, 1)
+	struct TRTDetectorStatus {
+		int32_t Version;					// Version of structure, useful for later extensions
+		int32_t Status;						// -1=not present, 0=present but inactive, 1=active
+		uint32_t CountRate;			// Current input count rate in cps
+		int32_t Temperature;				// Current temperature in °C
+		uint32_t CoolingMode;		// Cooling mode (0=off, 1=on, 2=max. 3=heating, 4=unknown)
+	};
+	#pragma pack(pop)
+
+
+	#pragma pack(push, 1)
+	struct TRTSpectrometerStatus {
+		int32_t Version;					// Version of structure, useful for later extensions
+		TRTDetectorStatus DetectorStatus[4/*# range 0..3*/];// Detector information
+		uint32_t Status;			// 0=not detected, 1=standby, 2=interlock, 3=stopped, 4=running
+		bool Ready;
+	};
+	#pragma pack(pop)
+
+
+	#pragma pack(push, 1)
+	struct TRTDetectorRanges {
+		int32_t MaxEnergy[8/*# range 0..7*/];
+		int32_t PulseThroughPut[8/*# range 0..7*/];
+		int32_t EnergyIndexCount;
+		int32_t PulseIndexCount;
+	};
+	#pragma pack(pop)
+
+
+	typedef TRTDetectorRanges* PRTDetectorRanges;
+
+	#pragma pack(push, 1)
+	struct TRTHardwareConfiguration {
+		int32_t Detector[4];				// [0..3] is SPU
+		bool EBSD;
+		bool Raster;
+		int32_t XrayTube;
+	};
+	#pragma pack(pop)
+
+
+	typedef TRTHardwareConfiguration* PRTHardwareConfiguration;
+
+
+	#pragma pack(push, 1)
+	struct TOpenClientOptions {
+		int32_t Version;
+		int32_t GUIMode;
+		bool StartNew;
+		uint8_t IdentifierLength;
+		char TCPHost[64];		// from version 2
+		uint16_t TCPPort;     	// from version 2
+	};
+	#pragma pack(pop)
+
+	typedef TOpenClientOptions* POpenClientOptions;
+
+	enum TAPILogType {
+		allError,
+		allWarning,
+		allInfo
+	};
+
+	// noch zu klären
+	// TAPILogTypes = set of TAPILogType;
+
+	typedef TPoint TPointArray[];
+	typedef TPointArray* PPointArray;
+
+	typedef void* TPointerArray[];
+	typedef void** PPointerArray;
+
+	// Error constants generated from client program
+
+	const int32_t IFC_ERROR_IN_EXECUTION = -1;
+	const int32_t IFC_ERROR_WRONG_PARAMETER = -2;
+	const int32_t IFC_ERROR_SPECTRUM_BUFFER_EMPTY = -3;
+	const int32_t IFC_ERROR_PARAMETER_MISSED = -4;
+	const int32_t IFC_ERROR_TOO_MANY_PARAMETERS = -5;
+	const int32_t IFC_ERROR_USER_TERMINATED = -6;
+	const int32_t IFC_ERROR_TIMEOUT = -7;
+	const int32_t IFC_ERROR_UNKNOWN_VALUE_NAME = -8;
+	const int32_t IFC_ERROR_WRONG_VALUE_TYPE = -9;
+	const int32_t IFC_ERROR_WRONG_LICENCE = -10;
+	const int32_t IFC_ERROR_RESULT_BUFFER_INSUFFICIENT = -11;
+	const int32_t IFC_ERROR_HARDWARE_LOCKED = -12;
+	const int32_t IFC_ERROR_SEQUENCE = -13;
+	const int32_t IFC_WARNING_WRONG_ELEMENT = 1;
+	const int32_t IFS_ERROR_PARAMETER_MISSED = -51;				// returned by RTIFCServer.dll   24.2.2011 '11' -> '51'
+	const int32_t IFS_ERROR_FUNCTION_NOT_IMPLEMENTED = -52;		// returned by RTIFCServer.dll   24.2.2011 '11' -> '52'
+	const int32_t IFS_ERROR_FUNTION_EXCEPTED = -53;
+
+	// Errors coming from OpenClient()
+	const int32_t CONN_ERROR_UNKNOWN = -21;
+	const int32_t CONN_ERROR_INTERFACE_NOT_CONNECTED = -22;
+	const int32_t CONN_ERROR_PARAMETER_MISSED = -23;
+	const int32_t CONN_ERROR_ANSWER_TIMEOUT = -24;
+	const int32_t CONN_ERROR_SERVER_NOT_RESPONDING = -25;
+	const int32_t CONN_ERROR_RESULT_MISSED = -26;
+	const int32_t CONN_ERROR_NO_INTERFACE = -27;
+	const int32_t CONN_ERROR_INVALID_LOGIN = -28;
+	const int32_t CONN_ERROR_NO_CONNECTION_TO_SERVER = -29;
+	const int32_t CONN_ERROR_SERVER = -30;
+	const int32_t CONN_ERROR_ACTION_ABORTED = -31;
+
+	// Error constants generated from Bruker.API.*.dll
+	const int32_t ERROR_WRONG_PARAMETER = -101;
+	const int32_t ERROR_FILE_NOT_EXIST = -102;
+	const int32_t ERROR_NO_CONNECTION = -103;
+	const int32_t ERROR_NO_ANSWER = -104;
+	const int32_t ERROR_CAN_NOT_START_PROCESS = -105;
+	const int32_t ERROR_INVALID_RESULT_DATA = -106;
+	const int32_t ERROR_SETTINGS_NOT_FOUND = -107;
+	const int32_t ERROR_NO_SERVER_CONNECTION = -108;  // no direct call to server possible (used in '..Direct' calls
+	const int32_t ERROR_IN_EXECUTION = -109;
+	const int32_t ERROR_IFC_BUSY = -110;
+
+	// State constants generated from Bruker.API.*.dll
+	const int32_t STATE_WAS_RUNNING_BEFORE = -201;
+
+	bool LoadCommonFunctions(const LPCTSTR LibFile);
+
+	// Convert int32_t to String
+	std::string IntToString(int32_t number);
+
+	// Convert Double to String
+	std::string DoubleToString(double number);
+
+	//----------------------------------------------------------------------------------
+	// Interface functions of Bruker.API.*.DLL
+	//----------------------------------------------------------------------------------
+
+	/// <summary>Set active language for interface</summary>
+	/// <param name="Language">Language identifier, 'ge' for german, any other for english</param>
+	int32_t  SetLanguage(char* Language);
+
+	/// <summary>Query all known servers which can be used by API</summary>
+	/// <param name="pServerList">Buffer for list of available server names</param>
+	/// <param name = "BufSize">Initial size of this buffer</param>
+	int32_t QueryServers(char* pServerList, int32_t BufSize);
+
+	/// <summary>Query all running client programs for a given server</summary>
+	/// <param name="pServer">name of the server to be queried</param>
+	/// <param name = "pClientBuf">Buffer for list of available clients</param>
+	/// <param name = "BufSize">Initial size of this buffer</param>
+	int32_t QueryUser(char* pServer, char* pClientBuf, int32_t BufSize);
+
+	/// <summary>Start Esprit and login automatically. Connection is done via Windows messaging, so Esprit must be installed on the same computer</summary>
+	/// <param name="Password">Password of user with UserName</param>
+	/// <param name="GUI">Whether to start the user interface or not</param>
+	/// <param name="CID">Reference connection identifier, which must be used in all following API calls</param>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t OpenClient(char* pServer, char* pUser, char* pPassword, bool StartNew, bool GUI, uint32_t& CID);
+
+	/// <summary>Start Esprit and login automatically. Connection is done via Windows messaging, so Esprit must be installed on the same computer</summary>
+	/// <param name="Password">Password of user with UserName</param>
+	/// <param name="Options">Structure with connection options</param>
+	/// <param name="CID">Reference connection identifier, which must be used in all following API calls</param>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t OpenClientEx(char* pServer, char* pUser, char* pPassword, const TOpenClientOptions& Options, uint32_t& CID);
+
+	/// <summary>Login to a running Esprit. Connection is done via TCP, so Esprit can be installed on any computer which is accessible via TCP/IP</summary>
+	/// <param name="Password">Password of user with UserName</param>
+	/// <param name="Host">IP address of the computer with Esprit</param>
+	/// <param name="Port">IP port used by Esprit (default port is 5328), Esprit must be running before one can use this function</param>
+	/// <param name="Options">Structure with connection options</param>
+	/// <param name="CID">Reference connection identifier, which must be used in all following API calls</param>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t OpenClientTCP(char* pServer, char* pUser, char* pPassword, char* pHost, uint16_t Port, const TOpenClientOptions Options, uint32_t& CID);
+
+	/// <summary>Query some information about a specific connection</summary>
+	/// <param name="pInfo">pointer to string to be filled from API with some useful information</param>
+	/// <param name="BufSize">Size of this buffer</param>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t QueryInfo(uint32_t CID, char* pInfo, int32_t BufSize);
+
+	/// <summary>Close corrent API connection, Esprit remains running, CID cannot be used anymore after this call</summary>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t CloseConnection(uint32_t CID);
+
+	/// <summary>Shutdown Esprit, CID cannot be used anymore after this call</summary>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t CloseClient(uint32_t CID);
+
+	/// <summary>Returns description string for error values</summary>
+	/// <param name="aError">error value returned from an API call</param>
+	/// <param name="pErrorStr">buffer to string provided by caller, to be filled from API</param>
+	/// <param name="BufSize">in: Size of this buffer, out: size used</param>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t GetDebugErrorString(uint32_t CID, int32_t aError, char* pErrorStr, int32_t& BufSize);
+
+	/// <summary>Writes description string for error values to log</summary>
+	/// <param name="aError">Error value returned from an API call</param>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t WriteDebugErrorStringToLog(uint32_t CID, int32_t aError);
+
+	/// <summary>Is a specific client connection ok?</summary>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t  CheckConnection(uint32_t CID);
+
+	/// <summary>Combines output of several spectrometers into one virtual spectrometer (to increase pulse rate for example)</summary>
+	/// <param name="Devices">bit combination of spectrometers to combine</param>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t CombineSpectrometer(uint32_t CID, int32_t Devices);
+
+	/// <summary></summary>
+	/// <param name="SPU">Number of spectrometer (1 in most cases)</param>
+	/// <param name="Status">Structure with status information from spectrometers and connected detectors</param>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t GetSpectrometerStatus(uint32_t CID, int32_t SPU, TRTSpectrometerStatus& Status);
+
+	/// <summary></summary>
+	/// <param name="SPU">Number of spectrometer (1 in most cases)</param>
+	/// <param name="Det">Number of detector (1 in most cases)</param>
+	/// <param name="aCoolingMode">Cooling mode (0=off, 1=on, 2=max. 3=heating, 4=unknown)</param>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t SetDetectorCoolingMode(uint32_t CID, int32_t SPU, int32_t Det, int32_t aCoolingMode);
+
+	/// <summary></summary>
+	/// <param name="SPU">Number of spectrometer (1 in most cases)</param>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t ResetSpectrometerInterlock(uint32_t CID, int32_t SPU);
+
+	/// <summary></summary>
+	/// <param name="Device">Number of spectrometer (1 in most cases)</param>
+	/// <param name="RealTime">Measure time in ms (0 means endless measurement)</param>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t StartSpectrumMeasurement(uint32_t CID, int32_t Device, uint32_t RealTime);
+
+	/// <summary></summary>
+	/// <param name="Device">Number of spectrometer (1 in most cases)</param>
+	/// <param name="LifeTime">Life time in ms (>0)</param>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t StartSpectrumLifeTimeMeasurement(uint32_t CID, int32_t Device, uint32_t LifeTime);
+
+	/// <summary></summary>
+	/// <param name="Device">Number of spectrometer (1 in most cases)</param>
+	/// <param name="StartEnergy">Lower spectrum region borders for counter measurement (in keV)</param>
+	/// <param name="EndEnergy">Higher spectrum region borders for counter measurement (in keV)</param>
+	/// <param name="Counts">Counter value for automatic measurement stop</param>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t StartSpectrumCounterMeasurement(uint32_t CID, int32_t SPU, double StartEnergy, double EndEnergy, uint32_t Counts);
+
+	/// <summary></summary>
+	/// <param name="Device">Number of spectrometer (1 in most cases)</param>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t StopSpectrumMeasurement(uint32_t CID, int32_t Device);
+
+	/// <summary>Read status of ongoing spectrum aquisition</summary>
+	/// <param name="Device">Number of spectrometer (1 in most cases)</param>
+	/// <param name="Running">Aquisition active or not</param>
+	/// <param name="State">State of aquisition in % (100 % means ready)</param>
+	/// <param name="PulseRate">
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t GetSpectrumMeasureState(uint32_t CID, int32_t Device, bool& Running, double& State, double& PulseRate);
+
+	/// <summary>Read status of ongoing spectrum aquisition</summary>
+	/// <param name="Device">Number of spectrometer (1 in most cases)</param>
+	/// <param name="Running">Aquisition active or not</param>
+	/// <param name="State">State of aquisition in % (100 % means ready)</param>
+	/// <param name="PulseRate">current input pulse rate in cps</param>
+	/// <param name="RealTime">current measure time in ms</param>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t GetSpectrumMeasureStateEx(uint32_t CID, int32_t Device, bool& Running, double& State, double& PulseRate, int32_t& RealTime);
+
+	/// <summary>Read current spectrum from spectrometer to buffer</summary>
+	/// <param name="Device">Number of spectrometer (1 in most cases)</param>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t ReadSpectrum(uint32_t CID, int32_t Device);
+
+	/// <summary>Read current spectrometer configuration</summary>
+	/// <param name="SPU">Number of spectrometer (1 in most cases)</param>
+	/// <param name="MaxEnergyIndex">Index of selected max energy setting</param>
+	/// <param name="PulseThroughputIndex">Index of selected max throughput setting</param>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t GetSpectrometerConfiguration(uint32_t CID, int32_t SPU, uint32_t& MaxEnergyIndex, uint32_t& PulseThroughputIndex);
+
+	/// <summary>Read current detector configuration</summary>
+	/// <param name="SPU">Number of spectrometer (1 in most cases)</param>
+	/// <param name="Det">Number of detector (1 in most cases)</param>
+	/// <param name="MaxEnergyIndex">Index of selected max energy setting</param>
+	/// <param name="PulseThroughputIndex">Index of selected max throughput setting</param>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t GetSpectrometerConfigurationEx(uint32_t CID, int32_t SPU, int32_t Det, uint32_t& MaxEnergyIndex, uint32_t& PulseThroughputIndex);
+
+	/// <summary>Set configuration for a given detector</summary>
+	/// <param name="SPU">Number of spectrometer (1 in most cases)</param>
+	/// <param name="Det">Number of detector (1 in most cases)</param>
+	/// <param name="MaxEnergyIndex">Index of selected max energy setting</param>
+	/// <param name="PulseThroughputIndex">Index of selected max throughput setting</param>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t SetSpectrometerConfiguration(uint32_t CID, int32_t SPU, int32_t Det, const uint32_t MaxEnergyIndex, const uint32_t PulseThroughputIndex);
+
+	/// <summary>Switch detectors into 'active' mode for a given spectrometer</summary>
+	/// <param name="SPU">Number of spectrometer (1 in most cases)</param>
+	/// <param name="Detectors">Active Detectors as bitmask (1 shl 0, etc.)</param>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t SetActiveDetectors(uint32_t CID, int32_t SPU, const uint32_t Detectors);
+
+	/// <summary>Read active detectors of a given spectrometer</summary>
+	/// <param name="SPU">Number of spectrometer (1 in most cases)</param>
+	/// <param name="Detectors">Active Detectors as bitmask (1 shl 0, etc.)</param>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t GetActiveDetectors(uint32_t CID, int32_t SPU, uint32_t& Detectors);
+
+	/// <summary></summary>
+	/// <param name="SPU">Number of spectrometer (1 in most cases)</param>
+	/// <param name="Detectors">Available Detectors as bitmask (1 shl 0, etc.)</param>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t GetAvailableDetectors(uint32_t CID, int32_t SPU, uint32_t& Detectors);
+
+	/// <summary>Ask for available WDS detetcors</summary>
+	/// <param name="SPU">Number of spectrometer (1 in most cases)</param>
+	/// <param name="Detectors">Available WDS detectors as bitmask (1 shl 0, etc.)
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t GetAvailableWDSDetectors(uint32_t CID, int32_t SPU, uint32_t& Detectors);
+
+	/// <summary></summary>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t GetHardwareConfiguration(uint32_t CID, TRTHardwareConfiguration& aHardwareConfiguration);
+
+	/// <summary>Perform spectrometer eneryg/channel calibration</summary>
+	/// <param name="Device">Number of spectrometer (1 in most cases)</param>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t CalibrateSpectrometer(uint32_t CID, int32_t Device, bool ShowProgress, PRTCalibSettings Settings, PRTCalibResults Results);
+
+	/// <summary>Read a named parameter from spectrometer</summary>
+	/// <param name="Device">Number of spectrometer (1 in most cases)</param></param>
+	/// <param name="ParamName   : Name of the parameter to read</param>
+	//                 Current implemented names: 'MaxEnergy', 'PulseThroughput', 'DetectorTemperature' as 'Integer' or 'Double'</param>
+	/// <param name="ParamType">Type of the parameter to read (Byte,Boolean,Word,Integer,Double,Memory)</param>
+	/// <param name="Buffer">Pointer to variable of that type</param>
+	/// <param name="BufSize">if ParamType is Memory than BufSize if size of the memory block described by 'Buffer'</param>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t GetSpectrometerParam(uint32_t CID, int32_t Device, char* ParamName, char* ParamType, void* Buffer, int32_t BufSize);
+
+	/// <summary>Reads the amount of available spectrometers</summary>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t GetSpectrometerCount(uint32_t CID, int32_t& Value);
+
+	/// <summary>Gets SpectrometerRanges (Pulserate and EnergyRange)</summary>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t GetSpectrometerRanges(uint32_t CID, int32_t SPU, int32_t Det, TRTDetectorRanges& aDetectorSettings);
+
+	/// <summary>Read full parameter block of current spectrometer params (needed to create full Bruker spectrum)</summary>
+	int32_t GetSpectrometerParams(uint32_t CID, int32_t SPU, void* Buffer, int32_t& BufSize);
+
+	/// <summary></summary>
+	/// <param name="Buffer">Number of buffer (1..n for spectrometer, 0 for loaded spectrum)
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t GetSpectrum(uint32_t CID, int32_t Buffer, PRTSpectrumHeaderRec pSpectrumBuf, int32_t BufSize);
+
+	/// <summary>Quantify spectrum in given buffer, returns</summary>
+	/// <param name="Buffer">Number of buffer (1..n for spectrometer, 0 for loaded spectrum)</param>
+	/// </param name="pMethodName">Name of the method file, this file must exist</param>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t QuantifySpectrum(uint32_t CID, int32_t Buffer, char* pMethodName, char* pParams, char* pResultBuf, int32_t ResultBufSize);
+
+	/// <summary>Sends a RCL 2.2 command to spectrometer and returns the answer (see RCL 2.2 description of commands)</summary>
+	/// <param name="Device">Number of spectrometer (1 in most cases)</param></param>
+	/// <param name="Command">Pointer to zero terminated command string</param>
+	/// <param name="Answer">Pointer buffer for zero terminated answer string</param>
+	/// <param name="AnswerBufSize">Size of this buffer</param>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t SendRCLCommand(uint32_t CID, int32_t Device, char* pCommand, char* pAnswer, int32_t AnswerBufSize);
+
+	/// <summary>Sends a RCL 2.2 command to spectrometer, does not wait for answer (see RCL 2.2 description of commands)</summary>
+	/// <param name="Device">Number of spectrometer (1 in most cases)</param></param>
+	/// <param name="Command">Pointer to zero terminated command string</param>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t SendRCLCommandOnly(uint32_t CID, int32_t Device, char* Command);
+
+	/// <summary>Receives the answer of the above function</summary>
+	/// <param name="Device">Number of spectrometer (1 in most cases)</param>
+	/// <param name="Answer">Pointer buffer for zero terminated answer string</param>
+	/// <param name="AnswerBufSize">Size of this buffer</param>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t ReceiveRCLAnswer(uint32_t CID, int32_t Device, char* Answer, int32_t AnswerBufSize);
+
+	/// <summary>Interupts hardware communication to specified device until 'UnlockSpectrometer' is called</summary>
+	/// <param name="Device">Number of spectrometer (1 in most cases)
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t LockSpectrometer(uint32_t CID, int32_t Device);
+
+	/// <summary></summary>
+	/// <param name="Device">Number of spectrometer (1 in most cases)</param>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t UnlockSpectrometer(uint32_t CID, int32_t Device);
+
+	/// <summary>Load spectrum from file to buffer</summary>
+	/// <param name="pFilename">Complete filename for spectrum (normally with *.spx extension)</param>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t LoadSpectrum(uint32_t CID, char* pFileName);
+
+	/// <summary>Send spectrum back to 'loaded' buffer</summary>
+	/// <param name="Spectrum">Bruker spectrum buffer</param>
+	/// <param name="BufferSize">size of spectrum buffer</param>
+	// Remarks     : if one wants to use that function one has to build a complete Bruker spectrum with
+	//               functions 'GetSpectrum', 'GetSpectrometerParams' and 'CreateSpectrum'
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t PutSpectrum(uint32_t CID, void* Spectrum, int32_t BufSize);
+
+	/// <summary>Save spectrum buffer to file</summary>
+	/// <param name="pFilename">Complete filename for spectrum (normally with *.spx extension)</param>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t SaveSpectrum(uint32_t CID, int32_t Buffer, char* pFileName);
+
+	/// <summary>Create a complete Bruker spectrum from</summary>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t CreateSpectrum(char* SpectrometerParams, PRTSpectrumHeaderRec SpectrumData, char* ResultData, int32_t& ResultSize);
+
+	/// <summary></summary>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t GetCorrectedSpectrum(char* SpectrometerParams, PRTSpectrumHeaderRec Spectrum, double* ResultData);
+
+	/// <summary>Show spectrum in Esprit UI</summary>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t ShowSpectrum(uint32_t CID, int32_t Buffer, char* Name);
+
+	/// <summary>Delete spectrum from presentation in UI</summary>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t DeleteSpectrum(uint32_t CID, char* aName);
+
+	/// <summary>Create and return a graphic for spectrum presentation</summary>
+	/// <param name="Buffer">Buffer index (0 for loaded spectrum buffer, > 0 for spectrometer buffers)</param>
+	/// <param name="Width">Requested graphic width</param>
+	/// <param name="Height">Requested graphic Height</param>
+	/// <param name="Format">Requested grapghic format (bmp, png, jpeg, tif)</param>
+	/// <param name="ResultBuf">should be able to save the whole image</param>
+	/// <param name="ResultBufSize">input is maximum, output is really used</param>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t GetSpectrumGraphic(uint32_t CID, int32_t Buffer, int32_t Width, int32_t Height, char* Format, void* ResultBuf, uint32_t& ResultBufSize);
+
+	/// <summary>Get a list of avaliable hardware profiles from client</summary>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t GetHardwareProfiles(uint32_t CID, char* pProfiles, int32_t BufSize);
+
+	/// <summary>Set a specific hardware profile</summary>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t SetHardwareProfile(uint32_t CID, char* pProfile);
+
+	/// <summary>Get a list of avaliable quantification methods</summary>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t GetQuantificationMethods(uint32_t CID, bool AutomaticOnly, char* pMethods, int32_t BufSize);
+
+	/// <summary>Get a list of predefined elements from a given quant method</summary>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t GetQuantificationMethodElements(uint32_t CID, char* MethodName, char* ElementBuffer, int32_t BufSize);
+
+	/// <summary>Call method editor for a given quant method</summary>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t EditQuantificationMethod(uint32_t CID, char* MethodName);
+
+	/// <summary>Loads a method and saves it again. purpose: rename, conversion from mtd into mtdx</summary>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t CopyQuantificationMethod(uint32_t CID, char* MethodName, char* TargetName, bool ToProfile);
+
+	/// <summary>Get a channel region for desired element and X ray line</summary>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t GetRegionForElement(uint32_t CID, int32_t Buffer, char* Params, char* ResultBuf, int32_t ResultBufSize);
+
+	// Xray tube functions
+
+	/// <summary></summary>
+	/// <param name="HighVoltage">tube voltate [Volt]</param>
+	/// <param name="Current">tube current [µA]</param>
+	/// <param name="FilterIndex">index of selected filter</param>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t XRayTubeSetConfiguration(uint32_t CID, int32_t Tube, uint32_t HighVoltage, uint32_t Current, uint32_t FilterIndex);
+
+	/// <summary></summary>
+	/// <param name="HighVoltage">tube voltate [Volt]</param>
+	/// <param name="Current">tube current [µA]</param>
+	/// <param name="FilterIndex">index of selected filter</param>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t XRayTubeGetState(uint32_t CID, int32_t Tube, uint32_t& HighVoltage, uint32_t& Current, uint32_t& FilterIndex, bool& ShutterOpen);
+
+	/// <summary></summary>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t XRayTubeOpenShutter(uint32_t CID, int32_t Tube);
+
+	/// <summary></summary>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t XRayTubeCloseShutter(uint32_t CID, int32_t Tube);
+
+	/// <summary></summary>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t XRayTubeHVOn(uint32_t CID, int32_t Tube, int32_t DestHV, int32_t DestCurrent, bool HVOn);
+
+	/// <summary></summary>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t XRaySetActiveTube(uint32_t CID, int32_t Tube);
+
+	/// <summary></summary>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t XRayGetActiveTube(uint32_t CID, int32_t& Tube);
+
+	/// <summary></summary>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t SetImageExportParameter(uint32_t CID, int32_t ExportImageWidth, bool ExportWithOverlay);
+
+	// Hypermap functions, function 'HyMapStart' is specific for Esprit/M4
+
+	/// <summary></summary>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t HyMapStop(uint32_t CID, bool WaitForFrameEnd);
+
+	/// <summary></summary>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t HyMapClearDatabase(uint32_t CID);
+
+	/// <summary>Query status of a hypermap measurement</summary>
+	/// <param name="Running">acquisition active or not</param>
+	/// <param name="MeasureState">state of acquisition in %</param>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t HyMapGetState(uint32_t CID, bool& Running, double& MeasureState);
+
+	/// <summary>Query status of a hypermap measurement</summary>
+	/// <param name="Running">acquisition active or not</param>
+	/// <param name="MeasureState">state of acquisition in %</param>
+	/// <param name="CurrentLine">line which is currently scanned (0...map height-1)</param>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t HyMapGetStateEx(uint32_t CID, bool& Running, double& MeasureState, int32_t& CurrentLine);
+
+	/// <summary>Query spectrum from a specific X/Y location in the map</summary>
+	/// <param name="X">X coordinate</param>
+	/// <param name="Y">Y coordinate</param>
+	/// <param name="Corrected">Correct the spectrum for detector artefacts or not</param>
+	/// <param name="SpectrumBuffer">pointer to memory, must have space for one full spectrum</param>
+	/// <param name="BufferSize">preallocated size of the spectrum buffer, recommended is a size of 64kB</param>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t HyMapGetXYSpectrum(uint32_t CID, int32_t X, int32_t Y, bool Corrected, PRTSpectrumHeaderRec SpectrumBuffer, int32_t BufferSize);
+
+	/// <summary>Query spectra from a specific location in the map</summary>
+	/// <param name="X">X coordinate</param>
+	/// <param name="Y">Y coordinate</param>
+	/// <param name="Count">Number of spectra with increasing X coordinate on line Y</param>
+	/// <param name="Corrected">Correct the spectrum for detector artefacts or not</param>
+	/// <param name="SpectrumBuffer">pointer to array of pointers for spectra, must have space for 'Count' pointers, each with allocated space for a full spectrum</param>
+	/// <param name="BufferSize">preallocated size of the spectrum buffer</param>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t HyMapGetLineSpectra(uint32_t CID, int32_t X, int32_t Y, int32_t Count, bool Corrected, PPointerArray SpectrumBuffer, int32_t BufferSize);
+
+	/// <summary>Query spectra from a specific location in the map, spectra are transmitted compressed internally. Funcction is much faster than "HyMapGetLineSpectra"</summary>
+	/// <param name="X">X coordinate</param>
+	/// <param name="Y">Y coordinate</param>
+	/// <param name="Count">Number of spectra with increasing X coordinate on line Y</param>
+	/// <param name="Corrected">Correct the spectrum for detector artefacts or not</param>
+	/// <param name="SpectrumBuffer">pointer to array of pointers for spectra, must have space for 'Count' pointers, each with allocated space for a full spectrum</param>
+	/// <param name="BufferSize">preallocated size of the spectrum buffer</param>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t HyMapGetCompressedLineSpectra(uint32_t CID, int32_t X, int32_t Y, int32_t Count, bool Corrected, PPointerArray SpectrumBuffer, int32_t BufferSize);
+
+	/// <summary></summary>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t HyMapQuantifySpectra(uint32_t CID, PPointArray Points, int32_t PointCount, int32_t Binning, char* MethodName, char* Params, char* ResultBuf, int32_t ResultBufSize);
+
+	/// <summary></summary>
+	/// <param name="aFileName">file name</param>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t HyMapSaveToFile(uint32_t CID, char* aFileName);
+
+	/// <summary>Load a hypermap file (*.bcf)</summary>
+	/// <param name="aFileName">file name</param>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t HyMapLoadFromFile(unsigned _int32 CID, char* aFileName, int32_t& Width, int32_t& Height, int32_t& DetCount, int32_t& ImgCount);
+
+	/// <summary></summary>
+	/// <param name="SpectrumBuffer">pointer to memory, must have space for one full spectrum</param>
+	/// <param name="BufferSize">size of the above buffer</param>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t HyMapGetMaxPixelSpectrum(uint32_t CID, PRTSpectrumHeaderRec SpectrumBuffer, int32_t BufferSize);
+
+	#ifdef	BRUKERAPIESPRITH
+	int32_t HyMapQuantifyMaxPixelSpectrum(uint32_t CID, char* MethodName, char* Params, char* ResultBuf, int32_t ResultBufSize);
+	#endif
+
+	/// <summary></summary>
+	/// <param name="pMethodName">name of method to be used</param>
+	/// <param name="pElementBuffer">buffer to get a list of atomic numbers as result of element identification</param>
+	/// <param name="ElementBufSize">size of element buffer</param>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t HyMapAutoIdent(uint32_t CID, char* pMethodName, char* pElementBuffer, int32_t ElementBufSize);
+
+	/// <summary></summary>
+	/// <param name="Format">Requested graphic format (bmp, png, jpeg, tif)</param>
+	/// <param name="ImgChannel">the plane to be shown</param>
+	/// <param name="Buffer">should be able to save the whole image</param>
+	/// <param name="Buffersize">input is maximum, output is really used</param>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t HyMapGetImage(uint32_t CID, char* Format, int32_t ImgChannel, void* Buffer, uint32_t& BufferSize);
+
+	/// <summary></summary>
+	/// <param name="ElementIndex">index of the elemen to be shown</param>
+	/// <param name="Buffer">should be able to save the whole image</param>
+	/// <param name="Buffersiz">input is maximum, output is really used</param>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t HyMapGetElementData(uint32_t CID, int32_t ElementIndex, void* Buffer, uint32_t& BufferSize);
+
+	/// <summary></summary>
+	/// <param name="Format">Requested graphic format (bmp, png, jpeg, tif)</param>
+	/// <param name="ElementIndex">the plane to be shown</param>
+	/// <param name="Buffer">should be able to save the whole image</param>
+	/// <param name="Buffersize">input is maximum, output is really used</param>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t HyMapGetElementImage(uint32_t CID, char* Format, int32_t ElementIndex, void* Buffer, uint32_t& BufferSize);
+
+	/// <summary></summary>
+	/// <param name="Format">Requested graphic format (bmp, png, jpeg, tif)</param>
+	/// <param name="Buffer">should be able to save the whole image</param>
+	/// <param name="Buffersize">input is maximum, output is really used</param>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t HyMapGetMixedMapImage(uint32_t CID, char* Format, void* Buffer, uint32_t& BufferSize);
+
+	/// <summary></summary>
+	/// <param name="ImgChannel">Image channel</param>
+	/// <param name="aFileName">file name</param>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t HyMapSaveImage(uint32_t CID, int32_t ImgChannel, char* aFileName);
+
+	/// <summary></summary>
+	/// <param name="ElementIndex">Plane to be shown</param>
+	/// <param name="aFileName">file name</param>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t HyMapSaveElementImage(uint32_t CID, int32_t ElementIndex, char* aFileName);
+
+	/// <summary></summary>
+	/// <param name="aFileName">file name</param>
+	/// <returns>Function call sucessful or not (0 = success, otherwise error)</returns>
+	int32_t HyMapSaveMixedMapImage(uint32_t CID, char* aFileName);
+}
+
+	#endif //  BrukerAPICommonFunctionsH

+ 90 - 0
OTSCPP/OTSControl/Bruker/Bruker.API.CommonStructures.h

@@ -0,0 +1,90 @@
+/*
+Bruker.API.Common-Structures.h
+Header File for common used structures (esprit and dataimport)
+
+Microsoft Visual Studio 2015
+*/
+namespace BrukerDll
+{
+
+
+	#ifndef BRUKERAPICOMMONSTRUCTURESH
+	#define BRUKERAPICOMMONSTRUCTURESH
+
+	#include <stdint.h>
+
+	#pragma pack(push, 1)
+		struct TMultiPoints {
+			uint32_t X;
+			uint32_t Y;
+		};
+	#pragma pack(pop)
+
+		// typedef TSegment TSegmentList[8192/*# range 0..8191*/];
+		typedef TMultiPoints TMultiPointList[65536];
+		typedef TMultiPoints* PMultiPointList;
+
+
+	#pragma pack(push, 1)
+		struct TSegment {
+			uint32_t Y;
+			uint32_t XStart;
+			int32_t XCount;
+		};
+	#pragma pack(pop)
+
+
+		// typedef TSegment TSegmentList[8192/*# range 0..8191*/];
+		typedef TSegment TSegmentList[65536];
+		typedef TSegment* PSegmentList;
+
+	#pragma pack(push, 1)
+		struct TRTElementRegion {
+			int32_t Element;
+			unsigned __int8 IdentifierLength;
+			char Line[10];					// can be ‘K? ‘KA? ‘LA??
+			double Energy;					// set element=0 if you want to use a specific energy, if you use element and line it can be ??	double Width;					// this is factor to enlarge/shrink the region
+			unsigned char R, G, B;			//
+		};
+	#pragma pack(pop)
+
+
+	#pragma pack(push, 1)
+		struct TRTHyMapProfileSettings {
+			int32_t Version;				// Version of structure, useful for later extensions, =1 at the moment
+											//Element settings
+			int32_t ElementCount;
+			TRTElementRegion ElementRegions[51/*# range 0..50*/];
+			// Map-Options
+			int32_t ImageFilter;			// 0=none, 1=smooth, 2=sharpen
+			int32_t MapFilter;				// 0=none, 1=average, 2=smooth, 3=automatic
+			int32_t MapFilterWidth;			// filter with in pixel 3?9
+			int32_t ColorMixMethod;			// 0=standard, 1=enhanced
+			double Brightness;				// -1..1
+			double Gamma;					// 0..2
+			double ColorSaturation;			// 0..2, default should be ??	bool AbsoluteScaling;
+			bool Normalization;
+			bool Deconvolution;
+		};
+	#pragma pack(pop)
+
+		//typedef TPoint * PPointArray;
+
+	#pragma pack(push, 1)
+		struct TEBSDIndexingResult {
+			int32_t MapX, MapY;
+			int32_t RadonBandCount;
+			int32_t nIndexedBands;
+			int32_t phase;
+			double phi1;
+			double phi;
+			double phi2;
+			double RadonQuality;
+			double MAD;
+		};
+	#pragma pack(pop)
+		typedef TEBSDIndexingResult* PEBSDIndexingResultArray;
+
+
+	#endif // BRUKERAPICOMMONSTRUCTURESH
+}

+ 1223 - 0
OTSCPP/OTSControl/Bruker/Bruker.API.Esprit.cpp

@@ -0,0 +1,1223 @@
+/*
+Bruker.API.Esprit.cpp
+Implementation for Bruker Esprit-Interface
+
+Microsoft Visual Studio 2015
+*/
+#include "stdafx.h"
+#include <windows.h>
+#include <stdio.h>
+#include "Bruker.API.Esprit.h"
+#include "Bruker.API.CommonFunctions.h"
+namespace BrukerDll
+{
+	// type definitions for callback functions
+	typedef int32_t (WINAPI *PHardwareConnectionGetStatus)(uint32_t CID, int32_t& Status, boolean& WasInterrupted, int32_t& TimeLeftForReconnection);
+	typedef int32_t (WINAPI *PHardwareConnectionResetErrorFlag)(uint32_t CID);
+	typedef int32_t (WINAPI *PHardwareConnectionReset)(uint32_t CID);
+	typedef int32_t (WINAPI *PImageReset)(uint32_t CID);
+
+	typedef int32_t (WINAPI *PImageGetConfiguration)(uint32_t CID, uint32_t& Width, uint32_t& Height, uint32_t& Average, bool& Ch1, bool& Ch2);
+	typedef int32_t (WINAPI *PImageSetConfiguration)(uint32_t CID, uint32_t Width, uint32_t Height, uint32_t Average, bool Ch1, bool Ch2);
+	typedef int32_t (WINAPI *PImageSetExternalScan)(uint32_t CID, bool UseExternalScan);
+	typedef int32_t (WINAPI *PImageAquireImage)(uint32_t CID, int32_t Ch, bool ShowProgress, void* Buffer, int32_t& BufSize, PRTImageInfoEx ImgInfo);
+	typedef int32_t (WINAPI *PImageAquireImageEx)(uint32_t CID, int32_t Ch, void* Buffer, uint32_t Options, int32_t& BufSize, PRTImageInfoEx ImgInfo);
+	typedef int32_t (WINAPI *PImageGetFieldWidth)(uint32_t CID, double& FieldWidth);
+	typedef int32_t (WINAPI *PImageSetExternalDriftCorrection)(uint32_t CID, double ShiftX, double ShiftY);
+	typedef int32_t (WINAPI *PImageGetDriftCorrectionActive)(uint32_t CID, bool& Active);
+	typedef int32_t (WINAPI *PImageGetLatestKnownScanPosition)(uint32_t CID, int& X, int& Y);
+	typedef int32_t (WINAPI *PImageGetScannedSegmentsCount)(uint32_t CID, __int64& aCount);
+	typedef int32_t (WINAPI *PImageSetPoint)(uint32_t CID, uint32_t X, uint32_t Y);
+	typedef int32_t (WINAPI *PStartPointListMeasurement)(uint32_t CID, int32_t SPU, uint32_t SegmentCount, PSegmentList LineSegments, uint32_t RealTime);
+	typedef int32_t (WINAPI *PGetPointListSpectrum)(uint32_t CID, int32_t Index, PRTSpectrumHeaderRec SpectrumBuf, int32_t BufSize);
+	typedef int32_t (WINAPI *PQuantifyPointListSpectrum)(uint32_t CID, int32_t Index, char* MethodName, char* Params, char* ResultBuf, int32_t ResultBufSize, PRTSpectrumHeaderRec SpectrumBuf, int32_t BufSize);
+	typedef int32_t (WINAPI *PSavePointListSpectrum)(uint32_t CID, int32_t Buffer, char* FileName);
+	typedef int32_t (WINAPI *PStartFeatureListMeasurement)(uint32_t CID, int32_t SPU, uint32_t FeatureCount, PFeatureDataList Features, __int16** PixelTimes);
+	typedef int32_t (WINAPI *PGetFeatureListSpectrum)(uint32_t CID, int32_t Index, PRTSpectrumHeaderRec SpectrumBuf, int32_t BufSize);
+	typedef int32_t (WINAPI *PQuantifyFeatureListSpectrum)(uint32_t CID, int32_t Index, char* MethodName, char* Params, char* ResultBuf, int32_t ResultBufSize, PRTSpectrumHeaderRec SpectrumBuf, int32_t BufSize);
+	typedef int32_t (WINAPI *PSaveFeatureListSpectrum)(uint32_t CID, int32_t Buffer, char* FileName);
+	typedef int32_t (WINAPI *PSetSEMData)(uint32_t CID, double Magnification, double HighVoltage, double WorkingDistance);
+	typedef int32_t (WINAPI *PGetSEMData)(uint32_t CID, double& Magnification, double& HighVoltage, double& WorkingDistance);
+	typedef int32_t (WINAPI *PSetSEMParameter)(uint32_t CID, char* Params, char* ValueIDs, double* Values);
+	typedef int32_t (WINAPI *PGetSEMParameter)(uint32_t CID, char* Params, char* ValueIDs, double* Values);
+	typedef int32_t (WINAPI *PGetSEMBCData)(uint32_t CID, double& Brightness, double& Contrast);
+	typedef int32_t (WINAPI *PSetSEMBCData)(uint32_t CID, double Brightness, double Contrast);
+	typedef int32_t (WINAPI *PGetSEMProbeCurrent)(uint32_t CID, double& ProbeCurrent);
+	typedef int32_t (WINAPI *PSetSEMProbeCurrent)(uint32_t CID, double ProbeCurrent);
+	typedef int32_t (WINAPI *PGetSEMSpotSize)(uint32_t CID, double& SpotSize);
+	typedef int32_t (WINAPI *PSetSEMSpotSize)(uint32_t CID, double SpotSize);
+	typedef int32_t (WINAPI *PSetSEMDetector)(uint32_t CID, int Channel, char* DetectorName);
+	typedef int32_t (WINAPI *PGetSEMDetector)(uint32_t CID, int Channel, char* DetectorName, int32_t BufSize);
+	typedef int32_t (WINAPI *PSetSEMStageData)(uint32_t CID, double XPos, double YPos, double ZPos, double Tilt, double Rotation);
+	typedef int32_t (WINAPI *PGetSEMStageData)(uint32_t CID, double& XPos, double& YPos, double& ZPos, double& Tilt, double& Rotation);
+	typedef int32_t (WINAPI *PGetSEMStageRange)(uint32_t CID, double& Xmin, double& Xmax, double& Ymin, double& Ymax, double& Zmin, double& Zmax, double& Tmin, double& Tmax, double& Rmin, double& Rmax);
+	typedef int32_t (WINAPI *PGetSEMStageState)(uint32_t CID, int32_t& State);
+	typedef int32_t (WINAPI *PGetSEMCapabilities)(uint32_t CID, char* Capabilities, int32_t BufSize);
+	typedef int32_t (WINAPI *PGetSEMInfo)(uint32_t CID, char* Info, int32_t BufSize);
+	typedef int32_t (WINAPI *PSetSEMExternalOn)(uint32_t CID);
+	typedef int32_t (WINAPI *PSetSEMExternalOff)(uint32_t CID);
+	typedef int32_t (WINAPI *PResetSEMCommunication)(uint32_t CID);
+	typedef int32_t (WINAPI *PSwitchSEMOff)(uint32_t CID, bool HVOff, bool BeamCurrentOff, bool BeamBlank);
+	typedef int32_t (WINAPI *PEDSSetDetectorPosition)(uint32_t CID, int32_t Detector, int32_t Position);
+	typedef int32_t (WINAPI *PEDSGetDetectorPosition)(uint32_t CID, int32_t Detector, int32_t& Position);
+	typedef int32_t (WINAPI *PHyMapStart)(uint32_t CID, int32_t SPU, uint32_t PixelTime, uint32_t RealTime);
+	typedef int32_t (WINAPI *PHyMapStartEx)(uint32_t CID, int32_t SPU, uint32_t PixelTime, uint32_t RealTime, TFeatureData Region);
+	typedef int32_t (WINAPI *PHyMapStartWithProfile)(uint32_t CID, int32_t SPU, uint32_t PixelTime, TFeatureData Region, char* Profile);
+	typedef int32_t (WINAPI *PHyMapCreateProfile)(const TRTHyMapProfileSettings& MapSettings, char* Profile, int32_t& BufSize);
+	typedef int32_t (WINAPI *PSetDataAndProfileToUI)(uint32_t CID, char* DataFileName, char* Profile);
+	typedef int32_t (WINAPI *PHyMapQuantifyMaxPixelSpectrum)(uint32_t CID, char* MethodName, char* Params, char* ResultBuf, int ResultBufSize);
+	typedef int32_t (WINAPI *PEBSDGetAcquisitionProfiles)(uint32_t CID, char* Profiles, int32_t BufSize);
+	typedef int32_t (WINAPI *PEBSDSelectAcquisitionProfile)(uint32_t CID, char* Profile);
+	typedef int32_t (WINAPI *PEBSDStartAcquisition)(uint32_t CID);
+	typedef int32_t (WINAPI *PEBSDStartAcquisitionWithProfile)(uint32_t CID, char* Profile);
+	typedef int32_t (WINAPI *PEBSDStopAcquisition)(uint32_t CID);
+	typedef int32_t (WINAPI *PEBSDGetAcquisitionState)(uint32_t CID, int32_t& CurrentLine, int32_t& PercentReady, int32_t& IndexingPercentReady, bool& AcquisitionRunning, bool& IndexingRunning);
+	typedef int32_t (WINAPI *PEBSDSaveToFile)(uint32_t CID, char* FileName, bool WithEdx, bool WithPatterns);
+	typedef int32_t (WINAPI *PEBSDExportData)(uint32_t CID, char* BaseFileName, int32_t ExportOptions);
+	typedef int32_t (WINAPI *PEBSDExportDataBuffer)(uint32_t CID, void* Buffer, int& BufferSize, int ExportOptions);
+	typedef int32_t (WINAPI *PEBSDExportResults)(uint32_t CID, char* BaseFileName);
+	typedef int32_t (WINAPI *PEBSDGetDetectorPosition)(uint32_t CID, double& Position);
+	typedef int32_t (WINAPI *PEBSDSetDetectorPosition)(uint32_t CID, double Position, double Speed);
+	typedef int32_t (WINAPI *PEBSDImageAcquireEx)(uint32_t CID, void* Buffer, int& BufSize, int PosX, int PosY);
+	typedef int32_t (WINAPI *PEBSDImageAcquireWithPC)(uint32_t CID, void* Buffer, int& BufSize, int PosX, int PosY, int NFrameAvg, double& PCX, double& PCY, double& PCL);
+	typedef int32_t (WINAPI *PEBSDImageAcquireRawDataFromPosition)(uint32_t CID, void* Buffer, int& BufSize, int PosX, int PosY, int& Width, int& Height, int& PixelBytes);
+	typedef int32_t (WINAPI *PEBSDImageAcquireRawDataFromPositionWithPC)(uint32_t CID, void* Buffer, int& BufSize, int PosX, int PosY, int NFrameAvg, double& PCX, double& PCY, double& PCL, int& Width, int& Height, int& PixelBytes);
+	typedef int32_t (WINAPI *PEBSDPointListImageAcquireWithPC)(uint32_t CID, void* Buffer, int& BufSize, uint32_t PointCount, PMultiPointList Points, int NFrameAvg, double& PCX, double& PCY, double& PCL, int& Width, int& Height, int& PixelBytes);
+	typedef int32_t (WINAPI *PEBSDPointListImageAcquireRawDataWithPC)(uint32_t CID, void* Buffer, int& BufSize, uint32_t PointCount, PMultiPointList Points, int NFrameAvg, double& PCX, double& PCY, double& PCL, int& Width, int& Height, int& PixelBytes);
+	typedef int32_t (WINAPI *PEBSDStartCalibration)(uint32_t CID, PRTEBSDCalibSettings Settings);
+	typedef int32_t (WINAPI *PEBSDStopCalibration)(uint32_t CID);
+	typedef int32_t (WINAPI *PEBSDGetCalibrationState)(uint32_t CID, int32_t& CurrentLine, int32_t& PercentReady, bool& Running);
+	typedef int32_t (WINAPI *PEBSDSaveEBSPImageFromPosition)(uint32_t CID, char* aBaseFilename, int32_t X, int32_t Y);
+	typedef int32_t (WINAPI *PEBSDSetExposureTime)(uint32_t CID, int32_t ExposureTime);
+	typedef int32_t (WINAPI *PEBSDGetExposureTime)(uint32_t CID, int32_t& ExposureTime);
+	typedef int32_t (WINAPI *PEBSDGetImageConfiguration)(uint32_t CID, int32_t& Width, int32_t& Height);
+	typedef int32_t (WINAPI *PEBSDSetGain)(uint32_t CID, int32_t Value);
+	typedef int32_t (WINAPI *PEBSDGetGain)(uint32_t CID, int32_t& Value);
+	typedef int32_t (WINAPI *PEBSDGetTilt)(uint32_t CID, double& Value);
+	typedef int32_t (WINAPI *PEBSDGetAvailablePatternFormatCount)(uint32_t CID, int32_t& Count);
+	typedef int32_t (WINAPI *PEBSDGetAvailablePatternFormat)(uint32_t CID, const int32_t FormatIndex, int32_t& Width, int32_t& Height);
+	typedef int32_t (WINAPI *PEBSDSetPatternFormat)(uint32_t CID, const int32_t FormatIndex);
+	typedef int32_t (WINAPI *PEBSDSetPattern16bitMode)(uint32_t CID, const bool Value);
+	typedef int32_t (WINAPI *PEBSDGetEstimatedMappingTime)(uint32_t CID, int32_t& Time);
+	typedef int32_t (WINAPI *PEBSDStartAcquisitionFromPointList)(uint32_t CID, PPointArray PointList, int32_t pointcount);
+	typedef int32_t (WINAPI *PEBSDGetPointResults)(uint32_t CID, PEBSDIndexingResultArray PointResults, int32_t & pointcount);
+
+	// DLL Handle
+	HMODULE hEspritDllBaseAddress;
+
+	// global callback function pointers
+	PHardwareConnectionGetStatus pHardwareConnectionGetStatus = NULL;
+	PHardwareConnectionResetErrorFlag pHardwareConnectionResetErrorFlag = NULL;
+	PHardwareConnectionReset pHardwareConnectionReset = NULL;
+	PImageReset pImageReset = NULL;
+
+	PImageGetConfiguration pImageGetConfiguration = NULL;
+	PImageSetConfiguration pImageSetConfiguration = NULL;
+	PImageSetExternalScan pImageSetExternalScan = NULL;
+	PImageAquireImage pImageAquireImage = NULL;
+	PImageAquireImageEx pImageAquireImageEx = NULL;
+	PImageGetFieldWidth pImageGetFieldWidth = NULL;
+	PImageSetExternalDriftCorrection pImageSetExternalDriftCorrection = NULL;
+	PImageGetDriftCorrectionActive pImageGetDriftCorrectionActive = NULL;
+	PImageGetLatestKnownScanPosition pImageGetLatestKnownScanPosition = NULL;
+	PImageGetScannedSegmentsCount pImageGetScannedSegmentsCount = NULL;
+	PImageSetPoint pImageSetPoint = NULL;
+	PStartPointListMeasurement pStartPointListMeasurement = NULL;
+	PGetPointListSpectrum pGetPointListSpectrum = NULL;
+	PQuantifyPointListSpectrum pQuantifyPointListSpectrum = NULL;
+	PSavePointListSpectrum pSavePointListSpectrum = NULL;
+	PStartFeatureListMeasurement pStartFeatureListMeasurement = NULL;
+	PGetFeatureListSpectrum pGetFeatureListSpectrum = NULL;
+	PQuantifyFeatureListSpectrum pQuantifyFeatureListSpectrum = NULL;
+	PSaveFeatureListSpectrum pSaveFeatureListSpectrum = NULL;
+	PSetSEMData pSetSEMData = NULL;
+	PGetSEMData pGetSEMData = NULL;
+	PSetSEMParameter pSetSEMParameter = NULL;
+	PGetSEMParameter pGetSEMParameter = NULL;
+	PGetSEMBCData pGetSEMBCData = NULL;
+	PSetSEMBCData pSetSEMBCData = NULL;
+	PGetSEMProbeCurrent pGetSEMProbeCurrent = NULL;
+	PSetSEMProbeCurrent pSetSEMProbeCurrent = NULL;
+	PGetSEMSpotSize pGetSEMSpotSize = NULL;
+	PSetSEMSpotSize pSetSEMSpotSize = NULL;
+	PSetSEMDetector pSetSEMDetector = NULL;
+	PGetSEMDetector pGetSEMDetector = NULL;
+	PSetSEMStageData pSetSEMStageData = NULL;
+	PGetSEMStageData pGetSEMStageData = NULL;
+	PGetSEMStageRange pGetSEMStageRange = NULL;
+	PGetSEMStageState pGetSEMStageState = NULL;
+	PGetSEMCapabilities pGetSEMCapabilities = NULL;
+	PGetSEMInfo pGetSEMInfo = NULL;
+	PSetSEMExternalOn pSetSEMExternalOn = NULL;
+	PSetSEMExternalOff pSetSEMExternalOff = NULL;
+	PResetSEMCommunication pResetSEMCommunication = NULL;
+	PSwitchSEMOff pSwitchSEMOff = NULL;
+	PEDSSetDetectorPosition pEDSSetDetectorPosition = NULL;
+	PEDSGetDetectorPosition pEDSGetDetectorPosition = NULL;
+	PHyMapStart pHyMapStart = NULL;
+	PHyMapStartEx pHyMapStartEx = NULL;
+	PHyMapStartWithProfile pHyMapStartWithProfile = NULL;
+	PHyMapCreateProfile pHyMapCreateProfile = NULL;
+	PSetDataAndProfileToUI pSetDataAndProfileToUI = NULL;
+	PHyMapQuantifyMaxPixelSpectrum pHyMapQuantifyMaxPixelSpectrum = NULL;
+	PEBSDGetAcquisitionProfiles pEBSDGetAcquisitionProfiles = NULL;
+	PEBSDSelectAcquisitionProfile pEBSDSelectAcquisitionProfile = NULL;
+	PEBSDStartAcquisition pEBSDStartAcquisition = NULL;
+	PEBSDStartAcquisitionWithProfile pEBSDStartAcquisitionWithProfile = NULL;
+	PEBSDStopAcquisition pEBSDStopAcquisition = NULL;
+	PEBSDGetAcquisitionState pEBSDGetAcquisitionState = NULL;
+	PEBSDSaveToFile pEBSDSaveToFile = NULL;
+	PEBSDExportData pEBSDExportData = NULL;
+	PEBSDExportDataBuffer pEBSDExportDataBuffer = NULL;
+	PEBSDExportResults pEBSDExportResults = NULL;
+	PEBSDGetDetectorPosition pEBSDGetDetectorPosition = NULL;
+	PEBSDSetDetectorPosition pEBSDSetDetectorPosition = NULL;
+	PEBSDImageAcquireEx pEBSDImageAcquireEx = NULL;
+	PEBSDImageAcquireWithPC pEBSDImageAcquireWithPC = NULL;
+	PEBSDImageAcquireRawDataFromPosition pEBSDImageAcquireRawDataFromPosition = NULL;
+	PEBSDImageAcquireRawDataFromPositionWithPC pEBSDImageAcquireRawDataFromPositionWithPC = NULL;
+	PEBSDPointListImageAcquireWithPC pEBSDPointListImageAcquireWithPC = NULL;
+	PEBSDPointListImageAcquireRawDataWithPC pEBSDPointListImageAcquireRawDataWithPC = NULL;
+	PEBSDStartCalibration pEBSDStartCalibration = NULL;
+	PEBSDStopCalibration pEBSDStopCalibration = NULL;
+	PEBSDGetCalibrationState pEBSDGetCalibrationState = NULL;
+	PEBSDSaveEBSPImageFromPosition pEBSDSaveEBSPImageFromPosition = NULL;
+	PEBSDSetExposureTime pEBSDSetExposureTime = NULL;
+	PEBSDGetExposureTime pEBSDGetExposureTime = NULL;
+	PEBSDGetImageConfiguration pEBSDGetImageConfiguration = NULL;
+	PEBSDSetGain pEBSDSetGain = NULL;
+	PEBSDGetGain pEBSDGetGain = NULL;
+	PEBSDGetTilt pEBSDGetTilt = NULL;
+	PEBSDGetAvailablePatternFormatCount pEBSDGetAvailablePatternFormatCount = NULL;
+	PEBSDGetAvailablePatternFormat pEBSDGetAvailablePatternFormat = NULL;
+	PEBSDSetPatternFormat pEBSDSetPatternFormat = NULL;
+	PEBSDSetPattern16bitMode pEBSDSetPattern16bitMode = NULL;
+	PEBSDGetEstimatedMappingTime pEBSDGetEstimatedMappingTime = NULL;
+	PEBSDStartAcquisitionFromPointList pEBSDStartAcquisitionFromPointList = NULL;
+	PEBSDGetPointResults pEBSDGetPointResults = NULL;
+
+	bool LoadEspritAPI(char* csAPILibFile)
+	{
+	/*#ifdef _WIN64
+	   const wchar_t* csAPILibFile = L"Bruker.API.Esprit2.4.DLL";
+	#else
+	   const wchar_t* csAPILibFile = L"Bruker.API.Esprit.DLL";
+	#endif*/
+
+	   LoadCommonFunctions(csAPILibFile);
+		hEspritDllBaseAddress = LoadLibrary(csAPILibFile);
+		if (!hEspritDllBaseAddress)
+		{ 
+			DWORD lastError = GetLastError();
+			TCHAR buf[100];
+			int j = _stprintf_s(buf, 100, _T("Esprit.cpp: Failed to load DLL %s \n"), csAPILibFile);
+			j += _stprintf_s(buf + j, 100-j, _T("Esprit.cpp: ErrorCode: %d \n"), lastError);
+			OutputDebugString(buf);
+			return false;
+		}
+
+		pHardwareConnectionGetStatus = (PHardwareConnectionGetStatus)GetProcAddress(hEspritDllBaseAddress, "HardwareConnectionGetStatus");
+		if (!pHardwareConnectionGetStatus) OutputDebugString(_T("Failed to load DLL function HardwareConnectionGetStatus\n"));
+
+		pHardwareConnectionResetErrorFlag = (PHardwareConnectionResetErrorFlag)GetProcAddress(hEspritDllBaseAddress, "HardwareConnectionResetErrorFlag");
+		if (!pHardwareConnectionResetErrorFlag) OutputDebugString(_T("Failed to load DLL function HardwareConnectionResetErrorFlag\n"));
+
+		pHardwareConnectionReset = (PHardwareConnectionReset)GetProcAddress(hEspritDllBaseAddress, "HardwareConnectionReset");
+		if (!pHardwareConnectionReset) OutputDebugString(_T("Failed to load DLL function HardwareConnectionReset\n"));
+
+		pImageReset = (PImageReset)GetProcAddress(hEspritDllBaseAddress, "ImageReset");
+		if (!pImageReset) OutputDebugString(_T("Failed to load DLL function ImageReset\n"));
+
+		pImageGetConfiguration = (PImageGetConfiguration)GetProcAddress(hEspritDllBaseAddress, "ImageGetConfiguration");
+		if (!pImageGetConfiguration) OutputDebugString(_T("Failed to load DLL function ImageGetConfiguration\n"));
+
+		pImageSetConfiguration = (PImageSetConfiguration)GetProcAddress(hEspritDllBaseAddress, "ImageSetConfiguration");
+		if (!pImageSetConfiguration) OutputDebugString(_T("Failed to load DLL function ImageSetConfiguration\n"));
+
+		pImageSetExternalScan = (PImageSetExternalScan)GetProcAddress(hEspritDllBaseAddress, "ImageSetExternalScan");
+		if (!pImageSetExternalScan) OutputDebugString(_T("Failed to load DLL function ImageSetExternalScan\n"));
+
+		pImageAquireImage = (PImageAquireImage)GetProcAddress(hEspritDllBaseAddress, "ImageAquireImage");
+		if (!pImageAquireImage) OutputDebugString(_T("Failed to load DLL function ImageAquireImage\n"));
+
+		pImageAquireImageEx = (PImageAquireImageEx)GetProcAddress(hEspritDllBaseAddress, "ImageAquireImageEx");
+		if (!pImageAquireImageEx) OutputDebugString(_T("Failed to load DLL function ImageAquireImageEx\n"));
+
+		pImageGetFieldWidth = (PImageGetFieldWidth)GetProcAddress(hEspritDllBaseAddress, "ImageGetFieldWidth");
+		if (!pImageGetFieldWidth) OutputDebugString(_T("Failed to load DLL function ImageGetFieldWidth\n"));
+
+		pImageSetExternalDriftCorrection = (PImageSetExternalDriftCorrection)GetProcAddress(hEspritDllBaseAddress, "ImageSetExternalDriftCorrection");
+		if (!pImageSetExternalDriftCorrection) OutputDebugString(_T("Failed to load DLL function ImageSetExternalDriftCorrection\n"));
+
+		pImageGetDriftCorrectionActive = (PImageGetDriftCorrectionActive)GetProcAddress(hEspritDllBaseAddress, "ImageGetDriftCorrectionActive");
+		if (!pImageGetDriftCorrectionActive) OutputDebugString(_T("Failed to load DLL function ImageGetDriftCorrectionActive\n"));
+
+		pImageGetLatestKnownScanPosition = (PImageGetLatestKnownScanPosition)GetProcAddress(hEspritDllBaseAddress, "ImageGetLatestKnownScanPosition");
+		if (!pImageGetLatestKnownScanPosition) OutputDebugString(_T("Failed to load DLL function ImageGetLatestKnownScanPosition\n"));
+
+		pImageGetScannedSegmentsCount = (PImageGetScannedSegmentsCount)GetProcAddress(hEspritDllBaseAddress, "ImageGetScannedSegmentsCount");
+		if (!pImageGetScannedSegmentsCount) OutputDebugString(_T("Failed to load DLL function ImageGetScannedSegmentsCount\n"));
+
+		pImageSetPoint = (PImageSetPoint)GetProcAddress(hEspritDllBaseAddress, "ImageSetPoint");
+		if (!pImageSetPoint) OutputDebugString(_T("Failed to load DLL function ImageSetPoint\n"));
+
+		pStartPointListMeasurement = (PStartPointListMeasurement)GetProcAddress(hEspritDllBaseAddress, "StartPointListMeasurement");
+		if (!pStartPointListMeasurement) OutputDebugString(_T("Failed to load DLL function StartPointListMeasurement\n"));
+	
+		pGetPointListSpectrum = (PGetPointListSpectrum)GetProcAddress(hEspritDllBaseAddress, "GetPointListSpectrum");
+		if (!pGetPointListSpectrum) OutputDebugString(_T("Failed to load DLL function GetPointListSpectrum\n"));
+
+		pQuantifyPointListSpectrum = (PQuantifyPointListSpectrum)GetProcAddress(hEspritDllBaseAddress, "QuantifyPointListSpectrum");
+		if (!pQuantifyPointListSpectrum) OutputDebugString(_T("Failed to load DLL function QuantifyPointListSpectrum\n"));
+
+		pSavePointListSpectrum = (PSavePointListSpectrum)GetProcAddress(hEspritDllBaseAddress, "SavePointListSpectrum");
+		if (!pSavePointListSpectrum) OutputDebugString(_T("Failed to load DLL function SavePointListSpectrum\n"));
+
+		pStartFeatureListMeasurement = (PStartFeatureListMeasurement)GetProcAddress(hEspritDllBaseAddress, "StartFeatureListMeasurement");
+		if (!pStartFeatureListMeasurement) OutputDebugString(_T("Failed to load DLL function StartFeatureListMeasurement\n"));
+
+		pGetFeatureListSpectrum = (PGetFeatureListSpectrum)GetProcAddress(hEspritDllBaseAddress, "GetFeatureListSpectrum");
+		if (!pGetFeatureListSpectrum) OutputDebugString(_T("Failed to load DLL function GetFeatureListSpectrum\n"));
+
+		pQuantifyFeatureListSpectrum = (PQuantifyFeatureListSpectrum)GetProcAddress(hEspritDllBaseAddress, "QuantifyFeatureListSpectrum");
+		if (!pQuantifyFeatureListSpectrum) OutputDebugString(_T("Failed to load DLL function QuantifyFeatureListSpectrum\n"));
+
+		pSaveFeatureListSpectrum = (PSaveFeatureListSpectrum)GetProcAddress(hEspritDllBaseAddress, "SaveFeatureListSpectrum");
+		if (!pSaveFeatureListSpectrum) OutputDebugString(_T("Failed to load DLL function SaveFeatureListSpectrum\n"));
+
+		pSetSEMData = (PSetSEMData)GetProcAddress(hEspritDllBaseAddress, "SetSEMData");
+		if (!pSetSEMData) OutputDebugString(_T("Failed to load DLL function SetSEMData\n"));
+
+		pGetSEMData = (PGetSEMData)GetProcAddress(hEspritDllBaseAddress, "GetSEMData");
+		if (!pGetSEMData) OutputDebugString(_T("Failed to load DLL function GetSEMData\n"));
+
+		pSetSEMParameter = (PSetSEMParameter)GetProcAddress(hEspritDllBaseAddress, "SetSEMParameter");
+		if (!pSetSEMParameter) OutputDebugString(_T("Failed to load DLL function SetSEMParameter\n"));
+
+		pGetSEMParameter = (PGetSEMParameter)GetProcAddress(hEspritDllBaseAddress, "GetSEMParameter");
+		if (!pGetSEMParameter) OutputDebugString(_T("Failed to load DLL function GetSEMParameter\n"));
+
+		pGetSEMBCData = (PGetSEMBCData)GetProcAddress(hEspritDllBaseAddress, "GetSEMBCData");
+		if (!pGetSEMBCData) OutputDebugString(_T("Failed to load DLL function GetSEMBCData\n"));
+
+		pSetSEMBCData = (PSetSEMBCData)GetProcAddress(hEspritDllBaseAddress, "SetSEMBCData");
+		if (!pSetSEMBCData) OutputDebugString(_T("Failed to load DLL function SetSEMBCData\n"));
+
+		pGetSEMProbeCurrent = (PGetSEMProbeCurrent)GetProcAddress(hEspritDllBaseAddress, "GetSEMProbeCurrent");
+		if (!pGetSEMProbeCurrent) OutputDebugString(_T("Failed to load DLL function GetSEMProbeCurrent\n"));
+
+		pSetSEMProbeCurrent = (PSetSEMProbeCurrent)GetProcAddress(hEspritDllBaseAddress, "SetSEMProbeCurrent");
+		if (!pSetSEMProbeCurrent) OutputDebugString(_T("Failed to load DLL function SetSEMProbeCurrent\n"));
+
+		pGetSEMSpotSize = (PGetSEMSpotSize)GetProcAddress(hEspritDllBaseAddress, "GetSEMSpotSize");
+		if (!pGetSEMSpotSize) OutputDebugString(_T("Failed to load DLL function GetSEMSpotSize\n"));
+
+		pSetSEMSpotSize = (PSetSEMSpotSize)GetProcAddress(hEspritDllBaseAddress, "SetSEMSpotSize");
+		if (!pSetSEMSpotSize) OutputDebugString(_T("Failed to load DLL function SetSEMSpotSize\n"));
+
+		pSetSEMDetector = (PSetSEMDetector)GetProcAddress(hEspritDllBaseAddress, "SetSEMDetector");
+		if (!pSetSEMDetector) OutputDebugString(_T("Failed to load DLL function SetSEMDetector\n"));
+
+		pGetSEMDetector = (PGetSEMDetector)GetProcAddress(hEspritDllBaseAddress, "GetSEMDetector");
+		if (!pGetSEMDetector) OutputDebugString(_T("Failed to load DLL function GetSEMDetector\n"));
+
+		pSetSEMStageData = (PSetSEMStageData)GetProcAddress(hEspritDllBaseAddress, "SetSEMStageData");
+		if (!pSetSEMStageData) OutputDebugString(_T("Failed to load DLL function SetSEMStageData\n"));
+
+		pGetSEMStageData = (PGetSEMStageData)GetProcAddress(hEspritDllBaseAddress, "GetSEMStageData");
+		if (!pGetSEMStageData) OutputDebugString(_T("Failed to load DLL function GetSEMStageData\n"));
+
+		pGetSEMStageRange = (PGetSEMStageRange)GetProcAddress(hEspritDllBaseAddress, "GetSEMStageRange");
+		if (!pGetSEMStageRange) OutputDebugString(_T("Failed to load DLL function GetSEMStageRange\n"));
+
+		pGetSEMStageState = (PGetSEMStageState)GetProcAddress(hEspritDllBaseAddress, "GetSEMStageState");
+		if (!pGetSEMStageState) OutputDebugString(_T("Failed to load DLL function GetSEMStageState\n"));
+
+		pGetSEMCapabilities = (PGetSEMCapabilities)GetProcAddress(hEspritDllBaseAddress, "GetSEMCapabilities");
+		if (!pGetSEMCapabilities) OutputDebugString(_T("Failed to load DLL function GetSEMCapabilities\n"));
+
+		pGetSEMInfo = (PGetSEMInfo)GetProcAddress(hEspritDllBaseAddress, "GetSEMInfo");
+		if (!pGetSEMInfo) OutputDebugString(_T("Failed to load DLL function GetSEMInfo\n"));
+
+		pSetSEMExternalOn = (PSetSEMExternalOn)GetProcAddress(hEspritDllBaseAddress, "SetSEMExternalOn");
+		if (!pSetSEMExternalOn) OutputDebugString(_T("Failed to load DLL function SetSEMExternalOn\n"));
+
+		pSetSEMExternalOff = (PSetSEMExternalOff)GetProcAddress(hEspritDllBaseAddress, "SetSEMExternalOff");
+		if (!pSetSEMExternalOff) OutputDebugString(_T("Failed to load DLL function SetSEMExternalOff\n"));
+
+		pResetSEMCommunication = (PResetSEMCommunication)GetProcAddress(hEspritDllBaseAddress, "ResetSEMCommunication");
+		if (!pResetSEMCommunication) OutputDebugString(_T("Failed to load DLL function ResetSEMCommunication\n"));
+
+		pSwitchSEMOff = (PSwitchSEMOff)GetProcAddress(hEspritDllBaseAddress, "SwitchSEMOff");
+		if (!pSwitchSEMOff) OutputDebugString(_T("Failed to load DLL function SwitchSEMOff\n"));
+
+		pEDSSetDetectorPosition = (PEDSSetDetectorPosition)GetProcAddress(hEspritDllBaseAddress, "EDSSetDetectorPosition");
+		if (!pEDSSetDetectorPosition) OutputDebugString(_T("Failed to load DLL function EDSSetDetectorPosition\n"));
+
+		pEDSGetDetectorPosition = (PEDSGetDetectorPosition)GetProcAddress(hEspritDllBaseAddress, "EDSGetDetectorPosition");
+		if (!pEDSGetDetectorPosition) OutputDebugString(_T("Failed to load DLL function EDSGetDetectorPosition\n"));
+
+		pHyMapStart = (PHyMapStart)GetProcAddress(hEspritDllBaseAddress, "HyMapStart");
+		if (!pHyMapStart) OutputDebugString(_T("Failed to load DLL function HyMapStart\n"));
+
+		pHyMapStartEx = (PHyMapStartEx)GetProcAddress(hEspritDllBaseAddress, "HyMapStartEx");
+		if (!pHyMapStartEx) OutputDebugString(_T ("Failed to load DLL function HyMapStartEx\n"));
+
+		pHyMapStartWithProfile = (PHyMapStartWithProfile)GetProcAddress(hEspritDllBaseAddress, "HyMapStartWithProfile");
+		if (!pHyMapStartWithProfile) OutputDebugString(_T("Failed to load DLL function HyMapStartWithProfile\n"));
+
+		pHyMapCreateProfile = (PHyMapCreateProfile)GetProcAddress(hEspritDllBaseAddress, "HyMapCreateProfile");
+		if (!pHyMapCreateProfile) OutputDebugString(_T("Failed to load DLL function HyMapCreateProfile\n"));
+
+		pSetDataAndProfileToUI = (PSetDataAndProfileToUI)GetProcAddress(hEspritDllBaseAddress, "SetDataAndProfileToUI");
+		if (!pSetDataAndProfileToUI) OutputDebugString(_T("Failed to load DLL function SetDataAndProfileToUI\n"));
+
+		pHyMapQuantifyMaxPixelSpectrum = (PHyMapQuantifyMaxPixelSpectrum)GetProcAddress(hEspritDllBaseAddress, "HyMapQuantifyMaxPixelSpectrum");
+		if (!pHyMapQuantifyMaxPixelSpectrum) OutputDebugString(_T("Failed to load DLL function HyMapQuantifyMaxPixelSpectrum\n"));
+
+		pEBSDGetAcquisitionProfiles = (PEBSDGetAcquisitionProfiles)GetProcAddress(hEspritDllBaseAddress, "EBSDGetAcquisitionProfiles");
+		if (!pEBSDGetAcquisitionProfiles) OutputDebugString(_T("Failed to load DLL function EBSDGetAcquisitionProfiles\n"));
+
+		pEBSDSelectAcquisitionProfile = (PEBSDSelectAcquisitionProfile)GetProcAddress(hEspritDllBaseAddress, "EBSDSelectAcquisitionProfile");
+		if (!pEBSDSelectAcquisitionProfile) OutputDebugString(_T("Failed to load DLL function EBSDSelectAcquisitionProfile\n"));
+
+		pEBSDStartAcquisition = (PEBSDStartAcquisition)GetProcAddress(hEspritDllBaseAddress, "EBSDStartAcquisition");
+		if (!pEBSDStartAcquisition) OutputDebugString(_T("Failed to load DLL function EBSDStartAcquisition\n"));
+	
+		pEBSDStartAcquisitionWithProfile = (PEBSDStartAcquisitionWithProfile)GetProcAddress(hEspritDllBaseAddress, "EBSDStartAcquisitionWithProfile");
+		if (!pEBSDStartAcquisitionWithProfile) OutputDebugString(_T("Failed to load DLL function EBSDStartAcquisitionWithProfile\n"));
+
+		pEBSDStopAcquisition = (PEBSDStopAcquisition)GetProcAddress(hEspritDllBaseAddress, "EBSDStopAcquisition");
+		if (!pEBSDStopAcquisition) OutputDebugString(_T("Failed to load DLL function EBSDStopAcquisition\n"));
+
+		pEBSDGetAcquisitionState = (PEBSDGetAcquisitionState)GetProcAddress(hEspritDllBaseAddress, "EBSDGetAcquisitionState");
+		if (!pEBSDGetAcquisitionState) OutputDebugString(_T("Failed to load DLL function EBSDGetAcquisitionState\n"));
+
+		pEBSDSaveToFile = (PEBSDSaveToFile)GetProcAddress(hEspritDllBaseAddress, "EBSDSaveToFile");
+		if (!pEBSDSaveToFile) OutputDebugString(_T("Failed to load DLL function EBSDSaveToFile\n"));
+
+		pEBSDExportData = (PEBSDExportData)GetProcAddress(hEspritDllBaseAddress, "EBSDExportData");
+		if (!pEBSDExportData) OutputDebugString(_T("Failed to load DLL function EBSDExportData\n"));
+
+		pEBSDExportDataBuffer = (PEBSDExportDataBuffer)GetProcAddress(hEspritDllBaseAddress, "EBSDExportDataBuffer");
+		if (!pEBSDExportDataBuffer) OutputDebugString(_T("Failed to load DLL function EBSDExportDataBuffer\n"));
+
+		pEBSDExportResults = (PEBSDExportResults)GetProcAddress(hEspritDllBaseAddress, "EBSDExportResults");
+		if (!pEBSDExportResults) OutputDebugString(_T("Failed to load DLL function EBSDExportResults\n"));
+
+		pEBSDGetDetectorPosition = (PEBSDGetDetectorPosition)GetProcAddress(hEspritDllBaseAddress, "EBSDGetDetectorPosition");
+		if (!pEBSDGetDetectorPosition) OutputDebugString(_T("Failed to load DLL function EBSDGetDetectorPosition\n"));
+
+		pEBSDSetDetectorPosition = (PEBSDSetDetectorPosition)GetProcAddress(hEspritDllBaseAddress, "EBSDSetDetectorPosition");
+		if (!pEBSDSetDetectorPosition) OutputDebugString(_T("Failed to load DLL function EBSDSetDetectorPosition\n"));
+
+		pEBSDImageAcquireEx = (PEBSDImageAcquireEx)GetProcAddress(hEspritDllBaseAddress, "EBSDImageAcquireEx");
+		if (!pEBSDImageAcquireEx) OutputDebugString(_T("Failed to load DLL function EBSDImageAcquireEx\n"));
+
+		pEBSDImageAcquireWithPC = (PEBSDImageAcquireWithPC)GetProcAddress(hEspritDllBaseAddress, "EBSDImageAcquireWithPC");
+		if (!pEBSDImageAcquireWithPC) OutputDebugString(_T("Failed to load DLL function EBSDImageAcquireWithPC\n"));
+
+		pEBSDImageAcquireRawDataFromPosition = (PEBSDImageAcquireRawDataFromPosition)GetProcAddress(hEspritDllBaseAddress, "EBSDImageAcquireRawDataFromPosition");
+		if (!pEBSDImageAcquireRawDataFromPosition) OutputDebugString(_T("Failed to load DLL function EBSDImageAcquireRawDataFromPosition\n"));
+
+		pEBSDImageAcquireRawDataFromPositionWithPC = (PEBSDImageAcquireRawDataFromPositionWithPC)GetProcAddress(hEspritDllBaseAddress, "EBSDImageAcquireRawDataFromPositionWithPC");
+		if (!pEBSDImageAcquireRawDataFromPositionWithPC) OutputDebugString(_T("Failed to load DLL function EBSDImageAcquireRawDataFromPositionWithPC\n"));
+
+		pEBSDPointListImageAcquireWithPC = (PEBSDPointListImageAcquireWithPC)GetProcAddress(hEspritDllBaseAddress, "EBSDPointListImageAcquireWithPC");
+		if (!pEBSDPointListImageAcquireWithPC) OutputDebugString(_T("Failed to load DLL function EBSDPointListImageAcquireWithPC\n"));
+
+		pEBSDPointListImageAcquireRawDataWithPC = (PEBSDPointListImageAcquireRawDataWithPC)GetProcAddress(hEspritDllBaseAddress, "EBSDPointListImageAcquireRawDataWithPC");
+		if (!pEBSDPointListImageAcquireRawDataWithPC) OutputDebugString(_T("Failed to load DLL function EBSDPointListImageAcquireRawDataWithPC\n"));
+
+		pEBSDStartCalibration = (PEBSDStartCalibration)GetProcAddress(hEspritDllBaseAddress, "EBSDStartCalibration");
+		if (!pEBSDStartCalibration) OutputDebugString(_T("Failed to load DLL function EBSDStartCalibration\n"));
+
+		pEBSDStopCalibration = (PEBSDStopCalibration)GetProcAddress(hEspritDllBaseAddress, "EBSDStopCalibration");
+		if (!pEBSDStopCalibration) OutputDebugString(_T("Failed to load DLL function EBSDStopCalibration\n"));
+
+		pEBSDGetCalibrationState = (PEBSDGetCalibrationState)GetProcAddress(hEspritDllBaseAddress, "EBSDGetCalibrationState");
+		if (!pEBSDGetCalibrationState) OutputDebugString(_T("Failed to load DLL function EBSDGetCalibrationState\n"));
+
+		pEBSDSaveEBSPImageFromPosition = (PEBSDSaveEBSPImageFromPosition)GetProcAddress(hEspritDllBaseAddress, "EBSDSaveEBSPImageFromPosition");
+		if (!pEBSDSaveEBSPImageFromPosition) OutputDebugString(_T("Failed to load DLL function EBSDSaveEBSPImageFromPosition\n"));
+
+		pEBSDSetExposureTime = (PEBSDSetExposureTime)GetProcAddress(hEspritDllBaseAddress, "EBSDSetExposureTime");
+		if (!pEBSDSetExposureTime) OutputDebugString(_T("Failed to load DLL function EBSDSetExposureTime\n"));
+
+		pEBSDGetExposureTime = (PEBSDGetExposureTime)GetProcAddress(hEspritDllBaseAddress, "EBSDGetExposureTime");
+		if (!pEBSDGetExposureTime) OutputDebugString(_T("Failed to load DLL function EBSDGetExposureTime\n"));
+
+		pEBSDGetImageConfiguration = (PEBSDGetImageConfiguration)GetProcAddress(hEspritDllBaseAddress, "EBSDGetImageConfiguration");
+		if (!pEBSDGetImageConfiguration) OutputDebugString(_T("Failed to load DLL function EBSDGetImageConfiguration\n"));
+
+		pEBSDSetGain = (PEBSDSetGain)GetProcAddress(hEspritDllBaseAddress, "EBSDSetGain");
+		if (!pEBSDSetGain) OutputDebugString(_T("Failed to load DLL function EBSDSetGain\n"));
+
+		pEBSDGetGain = (PEBSDGetGain)GetProcAddress(hEspritDllBaseAddress, "EBSDGetGain");
+		if (!pEBSDGetGain) OutputDebugString(_T("Failed to load DLL function EBSDGetGain\n"));
+
+		pEBSDGetTilt = (PEBSDGetTilt)GetProcAddress(hEspritDllBaseAddress, "EBSDGetTilt");
+		if (!pEBSDGetTilt) OutputDebugString(_T("Failed to load DLL function EBSDGetTilt\n"));
+
+		pEBSDGetAvailablePatternFormatCount = (PEBSDGetAvailablePatternFormatCount)GetProcAddress(hEspritDllBaseAddress, "EBSDGetAvailablePatternFormatCount");
+		if (!pEBSDGetAvailablePatternFormatCount) OutputDebugString(_T("Failed to load DLL function EBSDGetAvailablePatternFormatCount\n"));
+
+		pEBSDGetAvailablePatternFormat = (PEBSDGetAvailablePatternFormat)GetProcAddress(hEspritDllBaseAddress, "EBSDGetAvailablePatternFormat");
+		if (!pEBSDGetAvailablePatternFormat) OutputDebugString(_T("Failed to load DLL function EBSDGetAvailablePatternFormat\n"));
+
+		pEBSDSetPatternFormat = (PEBSDSetPatternFormat)GetProcAddress(hEspritDllBaseAddress, "EBSDSetPatternFormat");
+		if (!pEBSDSetPatternFormat) OutputDebugString(_T("Failed to load DLL function EBSDSetPatternFormat\n"));
+	
+		pEBSDSetPattern16bitMode = (PEBSDSetPattern16bitMode)GetProcAddress(hEspritDllBaseAddress, "EBSDSetPattern16bitMode");
+		if (!pEBSDSetPattern16bitMode) OutputDebugString(_T("Failed to load DLL function EBSDSetPattern16bitMode\n"));
+
+		pEBSDGetEstimatedMappingTime = (PEBSDGetEstimatedMappingTime)GetProcAddress(hEspritDllBaseAddress, "EBSDGetEstimatedMappingTime");
+		if (!pEBSDGetEstimatedMappingTime) OutputDebugString(_T("Failed to load DLL function EBSDGetEstimatedMappingTime\n"));
+
+		pEBSDStartAcquisitionFromPointList = (PEBSDStartAcquisitionFromPointList)GetProcAddress(hEspritDllBaseAddress, "EBSDStartAcquisitionFromPointList");
+		if (!pEBSDStartAcquisitionFromPointList) OutputDebugString(_T("Failed to load DLL function EBSDStartAcquisitionFromPointList\n"));
+
+		pEBSDGetPointResults = (PEBSDGetPointResults)GetProcAddress(hEspritDllBaseAddress, "EBSDGetPointResults");
+		if (!pEBSDGetPointResults) OutputDebugString(_T("Failed to load DLL function EBSDGetPointResults\n"));
+
+		return true;
+	}
+
+	int32_t HardwareConnectionGetStatus(uint32_t CID, int32_t& Status, boolean& WasInterrupted, int32_t& TimeLeftForReconnection)
+	{
+		if (pHardwareConnectionGetStatus)
+			return pHardwareConnectionGetStatus(CID, Status, WasInterrupted, TimeLeftForReconnection);
+		else return -1;
+	}
+
+	int32_t HardwareConnectionResetErrorFlag(uint32_t CID)
+	{
+		if (pHardwareConnectionResetErrorFlag)
+			return pHardwareConnectionResetErrorFlag(CID);
+		else return -1;
+	}
+
+	// Initialize connection reset procedure, this will trigger a 'watchdogged' hardware reset in SCU/SGU
+	int32_t HardwareConnectionReset(uint32_t CID)
+	{
+		if (pHardwareConnectionReset)
+			return pHardwareConnectionReset(CID);
+		else return -1;
+	}
+
+	// Reset scan hardware, device will have default configuration afterwards, so be sure to re-configure it correctly
+	int32_t ImageReset(uint32_t CID)
+	{
+		if (pImageReset)
+			return pImageReset(CID);
+		else return -1;
+	}
+
+	// Read current image device configuration
+	int32_t ImageGetConfiguration(uint32_t CID, uint32_t& Width, uint32_t& Height, uint32_t& Average, bool& Ch1, bool& Ch2)
+	{
+		if (pImageGetConfiguration)
+			return pImageGetConfiguration(CID, Width, Height, Average, Ch1, Ch2);
+		else return -1;
+	}
+
+	// Write current image device configuration
+	int32_t ImageSetConfiguration(uint32_t CID, uint32_t Width, uint32_t Height, uint32_t Average, bool Ch1, bool Ch2)
+	{
+		if (pImageSetConfiguration)
+			return pImageSetConfiguration(CID, Width, Height, Average, Ch1, Ch2);
+		else return -1;
+	}
+
+	// Use external scan engine which triggers our scan generator trough an external signal
+	int32_t ImageSetExternalScan(uint32_t CID, bool UseExternalScan)
+	{
+		if (pImageSetExternalScan)
+			return pImageSetExternalScan(CID, UseExternalScan);
+		else return -1;
+	}
+
+	// Aquire new image and read image data
+	int32_t ImageAquireImage(uint32_t CID, int32_t Ch, bool ShowProgress, void* Buffer, int32_t& BufSize, PRTImageInfoEx ImgInfo)
+	{
+		if (pImageAquireImage)
+			return pImageAquireImage(CID, Ch, ShowProgress, Buffer, BufSize, ImgInfo);
+		else return -1;
+	}
+
+	// Aquire new image and read image data
+	// Options		: Bit combination of the following values
+	//                cImgAcq_ShowProgress    = 1;
+	//                cImgAcq_UpdateSEMData   = 2;
+	int32_t ImageAquireImageEx(uint32_t CID, int32_t Ch, void* Buffer, uint32_t Options, int32_t& BufSize, PRTImageInfoEx ImgInfo)
+	{
+		if (pImageAquireImageEx)
+			return pImageAquireImageEx(CID, Ch, Buffer, Options, BufSize, ImgInfo);
+		else return -1;
+	}
+
+
+	// Read the image field width from scan settings and SEM magnification, microns unit
+	int32_t ImageGetFieldWidth(uint32_t CID, double& FieldWidth)
+	{
+		if (pImageGetFieldWidth)
+			return pImageGetFieldWidth(CID, FieldWidth);
+		else return -1;
+	}
+
+	// Set drift correction vector
+	int32_t ImageSetExternalDriftCorrection(uint32_t CID, double ShiftX, double ShiftY)
+	{
+		if (pImageSetExternalDriftCorrection)
+			return pImageSetExternalDriftCorrection(CID, ShiftX, ShiftY);
+		else return -1;
+	}
+
+	int32_t ImageGetDriftCorrectionActive(uint32_t CID, bool& Active)
+	{
+		if (pImageGetDriftCorrectionActive)
+			return pImageGetDriftCorrectionActive(CID, Active);
+		else return -1;
+	}
+
+	int32_t ImageGetLatestKnownScanPosition(uint32_t CID, int& X, int& Y)
+	{
+		if (pImageGetLatestKnownScanPosition)
+			return pImageGetLatestKnownScanPosition(CID, X, Y);
+		else return -1;
+	}
+
+	int32_t ImageGetScannedSegmentsCount(uint32_t CID, __int64& aCount)
+	{
+		if (pImageGetScannedSegmentsCount)
+			return pImageGetScannedSegmentsCount(CID, aCount);
+		else return -1;
+	}
+
+	// Set electron beam position in image
+	int32_t ImageSetPoint(uint32_t CID, uint32_t X, uint32_t Y)
+	{
+		if (pImageSetPoint)
+			return pImageSetPoint(CID, X, Y);
+		else return -1;
+	}
+
+	// functions to deal with point lists
+	// CID			: connection identifier
+	// SPU			: spectrometer index (1..n)
+	// SegmentCount,
+	// LineSegments	: description of points to measure
+	// RealTime		: acquisition time in ms
+	int32_t StartPointListMeasurement(uint32_t CID, int32_t SPU, uint32_t SegmentCount,BrukerDll::PSegmentList LineSegments, uint32_t RealTime)
+	{
+		if (pStartPointListMeasurement)
+			return pStartPointListMeasurement(CID, SPU, SegmentCount, LineSegments, RealTime);
+		else return -1;
+	}
+
+
+	// CID			: connection identifier
+	// Index		: spectrum index (1..n)
+	// SpectrumBuf	: buffer to hold complete spectrum with header (around 20kB), must be allocated by caller
+	// BufSize		: size of spectrum buffer
+	int32_t GetPointListSpectrum(uint32_t CID, int32_t Index, PRTSpectrumHeaderRec SpectrumBuf, int32_t BufSize)
+	{
+		if (pGetPointListSpectrum)
+			return pGetPointListSpectrum(CID, Index, SpectrumBuf, BufSize);
+		else return -1;
+	}
+
+	int32_t QuantifyPointListSpectrum(uint32_t CID, int32_t Index, char* MethodName, char* Params, char* ResultBuf, int32_t ResultBufSize, PRTSpectrumHeaderRec SpectrumBuf, int32_t BufSize)
+	{
+		if (pQuantifyPointListSpectrum)
+			return pQuantifyPointListSpectrum(CID, Index, MethodName, Params, ResultBuf, ResultBufSize, SpectrumBuf, BufSize);
+		else return -1;
+	}
+
+	// CID			: connection identifier
+	// Index		: spectrum index (1..n)
+	// FileName		: filename to save to
+	int32_t SavePointListSpectrum(uint32_t CID, int32_t Buffer, char* FileName)
+	{
+		if (pSavePointListSpectrum)
+			return pSavePointListSpectrum(CID, Buffer, FileName);
+		else return -1;
+	}
+
+	///////////////////////////////////////////////////////////
+	// functions to deal with object lists                  ///
+	///////////////////////////////////////////////////////////
+	int32_t StartFeatureListMeasurement(uint32_t CID, int32_t SPU, uint32_t FeatureCount, PFeatureDataList Features, __int16** PixelTimes)
+	{
+		if (pStartFeatureListMeasurement)
+			return pStartFeatureListMeasurement(CID, SPU, FeatureCount, Features, PixelTimes);
+		else return -1;
+	}
+
+	int32_t GetFeatureListSpectrum(uint32_t CID, int32_t Index, PRTSpectrumHeaderRec SpectrumBuf, int32_t BufSize)
+	{
+		if (pGetFeatureListSpectrum)
+			return pGetFeatureListSpectrum(CID, Index, SpectrumBuf, BufSize);
+		else return -1;
+	}
+
+	int32_t QuantifyFeatureListSpectrum(uint32_t CID, int32_t Index, char* MethodName, char* Params, char* ResultBuf, int32_t ResultBufSize, PRTSpectrumHeaderRec SpectrumBuf, int32_t BufSize)
+	{
+		if (pQuantifyFeatureListSpectrum)
+			return pQuantifyFeatureListSpectrum(CID, Index, MethodName, Params, ResultBuf, ResultBufSize, SpectrumBuf, BufSize);
+		else return -1;
+	}
+
+	int32_t SaveFeatureListSpectrum(uint32_t CID, int32_t Buffer, char* FileName)
+	{
+		if (pSaveFeatureListSpectrum)
+			return pSaveFeatureListSpectrum(CID, Buffer, FileName);
+		else return -1;
+	}
+
+	///////////////////////////////////////////////////////////
+	/// functions to communicate with SEM                   ///
+	///////////////////////////////////////////////////////////
+
+	int32_t SetSEMData(uint32_t CID, double Magnification, double HighVoltage, double WorkingDistance)
+	{
+		if (pSetSEMData)
+			return pSetSEMData(CID, Magnification, HighVoltage, WorkingDistance);
+		else return -1;
+	}
+
+	int32_t GetSEMData(uint32_t CID, double& Magnification, double& HighVoltage, double& WorkingDistance)
+	{
+		if (pGetSEMData)
+			return pGetSEMData(CID, Magnification, HighVoltage, WorkingDistance);
+		else return -1;
+	}
+
+	int32_t SetSEMParameter(uint32_t CID, char* Params, char* ValueIDs, double* Values)
+	{
+		if (pSetSEMParameter)
+			return pSetSEMParameter(CID, Params, ValueIDs, Values);
+		else return -1;
+	}
+
+	int32_t GetSEMParameter(uint32_t CID, char* Params, char* ValueIDs, double* Values)
+	{
+		if (pGetSEMParameter)
+			return pGetSEMParameter(CID, Params, ValueIDs, Values);
+		else return -1;
+	}
+
+	int32_t GetSEMBCData(uint32_t CID, double& Brightness, double& Contrast)
+	{
+		if (pGetSEMBCData)
+			return pGetSEMBCData(CID, Brightness, Contrast);
+		else return -1;
+	}
+
+	int32_t SetSEMBCData(uint32_t CID, double Brightness, double Contrast)
+	{
+		if (pSetSEMBCData)
+			return pSetSEMBCData(CID, Brightness, Contrast);
+		else return -1;
+	}
+
+	int32_t GetSEMProbeCurrent(uint32_t CID, double& ProbeCurrent)
+	{
+		if (pGetSEMProbeCurrent)
+			return pGetSEMProbeCurrent(CID, ProbeCurrent);
+		else return -1;
+	}
+
+	int32_t SetSEMProbeCurrent(uint32_t CID, double ProbeCurrent)
+	{
+		if (pSetSEMProbeCurrent)
+			return pSetSEMProbeCurrent(CID, ProbeCurrent);
+		else return -1;
+	}
+
+	int32_t GetSEMSpotSize(uint32_t CID, double& SpotSize)
+	{
+		if (pGetSEMSpotSize)
+			return pGetSEMSpotSize(CID, SpotSize);
+		else return -1;
+	}
+
+	int32_t SetSEMSpotSize(uint32_t CID, double SpotSize)
+	{
+		if (pSetSEMSpotSize)
+			return pSetSEMSpotSize(CID, SpotSize);
+		else return -1;
+	}
+
+	int32_t SetSEMDetector(uint32_t CID, int Channel, char* DetectorName)
+	{
+		if (pSetSEMDetector)
+			return pSetSEMDetector(CID, Channel, DetectorName);
+		else return -1;
+	}
+
+	int32_t GetSEMDetector(uint32_t CID, int Channel, char* DetectorName, int32_t BufSize)
+	{
+		if (pGetSEMDetector)
+			return pGetSEMDetector(CID, Channel, DetectorName, BufSize);
+		else return -1;
+	}
+
+
+	int32_t SetSEMStageData(uint32_t CID, double XPos, double YPos, double ZPos, double Tilt, double Rotation)
+	{
+		if (pSetSEMStageData)
+			return pSetSEMStageData(CID, XPos, YPos, ZPos, Tilt, Rotation);
+		else return -1;
+	}
+
+	int32_t GetSEMStageData(uint32_t CID, double& XPos, double& YPos, double& ZPos, double& Tilt, double& Rotation)
+	{
+		if (pGetSEMStageData)
+			return pGetSEMStageData(CID, XPos, YPos, ZPos, Tilt, Rotation);
+		else return -1;
+	}
+
+	int32_t GetSEMStageRange(uint32_t CID, double& Xmin, double& Xmax, double& Ymin, double& Ymax, double& Zmin, double& Zmax, double& Tmin, double& Tmax, double& Rmin, double& Rmax)
+	{
+		if (pGetSEMStageRange)
+			return pGetSEMStageRange(CID, Xmin, Xmax, Ymin, Ymax, Zmin, Zmax, Tmin, Tmax, Rmin, Rmax);
+		else return -1;
+	}
+
+	int32_t GetSEMStageState(uint32_t CID, int32_t& State)
+	{
+		if (pGetSEMStageState)
+			return pGetSEMStageState(CID, State);
+		else return -1;
+	}
+
+	int32_t GetSEMCapabilities(uint32_t CID, char* Capabilities, int32_t BufSize)
+	{
+		if (pGetSEMCapabilities)
+			return pGetSEMCapabilities(CID, Capabilities, BufSize);
+		else return -1;
+	}
+
+	int32_t GetSEMInfo(uint32_t CID, char* Info, int32_t BufSize)
+	{
+		if (pGetSEMInfo)
+			return pGetSEMInfo(CID, Info, BufSize);
+		else return -1;
+	}
+
+	int32_t SetSEMExternalOn(uint32_t CID)
+	{
+		if (pSetSEMExternalOn)
+			return pSetSEMExternalOn(CID);
+		else return -1;
+	}
+
+	int32_t SetSEMExternalOff(uint32_t CID)
+	{
+		if (pSetSEMExternalOff)
+			return pSetSEMExternalOff(CID);
+		else return -1;
+	}
+
+	int32_t ResetSEMCommunication(uint32_t CID)
+	{
+		if (pResetSEMCommunication)
+			return pResetSEMCommunication(CID);
+		else return -1;
+	}
+
+	int32_t SwitchSEMOff(uint32_t CID, bool HVOff, bool BeamCurrentOff, bool BeamBlank)
+	{
+		if (pSwitchSEMOff)
+			return pSwitchSEMOff(CID, HVOff, BeamCurrentOff, BeamBlank);
+		else return -1;
+	}
+
+	///////////////////////////////////////////////////////////
+	/// Move EDS detector                                   ///
+	///////////////////////////////////////////////////////////
+
+	// Detector		: Detector to be moved ( 1 in most cases )
+	// Position		: Position to move to ( 1 = Park position, 2 = Acquisition position )
+	int32_t EDSSetDetectorPosition(uint32_t CID, int32_t Detector, int32_t Position)
+	{
+		if (pEDSSetDetectorPosition)
+			return pEDSSetDetectorPosition(CID, Detector, Position);
+		else return -1;
+	}
+
+	// Detector		: Detector to ask for position ( 1 in most cases )
+	// Position		: Current position ( 1 = Park position, 2 = Acquisition position )
+	int32_t EDSGetDetectorPosition(uint32_t CID, int32_t Detector, int32_t& Position)
+	{
+		if (pEDSGetDetectorPosition)
+			return pEDSGetDetectorPosition(CID, Detector, Position);
+		else return -1;
+	}
+
+
+	///////////////////////////////////////////////////////////
+	/// Mapping functions                                   ///
+	///////////////////////////////////////////////////////////
+
+	// PixelTime	: Dwell time per Pixel in microseconds
+	// RealTime		: Acquisition time in s, RealTime=0 does exactly 1 scan
+	int32_t HyMapStart(uint32_t CID, int32_t SPU, uint32_t PixelTime, uint32_t RealTime)
+	{
+		if (pHyMapStart)
+			return pHyMapStart(CID, SPU, PixelTime, RealTime);
+		else return -1;
+	}
+
+	// PixelTime	: Dwell time per Pixel in microseconds
+	// RealTime		: Acquisition time in s, RealTime=0 does exactly 1 scan
+	// Region		: Image region to be mapped
+	int32_t HyMapStartEx(uint32_t CID, int32_t SPU, uint32_t PixelTime, uint32_t RealTime, TFeatureData Region)
+	{
+		if (pHyMapStartEx)
+			return pHyMapStartEx(CID, SPU, PixelTime, RealTime, Region);
+		else return -1;
+	}
+
+	// PixelTime   : Dwell time per Pixel in microseconds
+	// RealTime    : Acquisition time in s, RealTime=0 does exactly 1 scan
+	// Region      : Image region to be mapped
+	// Profile     : XML serialized profile
+	int32_t HyMapStartWithProfile(uint32_t CID, int32_t SPU, uint32_t PixelTime, TFeatureData Region, char* Profile)
+	{
+		if (pHyMapStartWithProfile)
+			return pHyMapStartWithProfile(CID, SPU, PixelTime, Region, Profile);
+		else return -1;
+	}
+
+	// MapSettings : Map settings
+	// Profile     : XML serialized profile
+	// BufSize     : Size of buffer
+	int32_t HyMapCreateProfile(const TRTHyMapProfileSettings& MapSettings, char* Profile, int32_t& BufSize)
+	{
+		if (pHyMapCreateProfile)
+			return pHyMapCreateProfile(MapSettings, Profile, BufSize);
+		else return -1;
+	}
+
+	// DataFileName: complete name of existing mapping data file
+	// Profile     : XML serialized EDS map profile
+	int32_t SetDataAndProfileToUI(uint32_t CID, char* DataFileName, char* Profile)
+	{
+		if (pSetDataAndProfileToUI)
+			return pSetDataAndProfileToUI(CID, DataFileName, Profile);
+		else return -1;
+	}
+
+
+	int32_t HyMapQuantifyMaxPixelSpectrum(uint32_t CID, char* MethodName, char* Params, char* ResultBuf, int ResultBufSize)
+	{
+		if (pHyMapQuantifyMaxPixelSpectrum)
+			return pHyMapQuantifyMaxPixelSpectrum(CID, MethodName, Params, ResultBuf, ResultBufSize);
+		else return -1;
+	}
+
+
+	///////////////////////////////////////////////////////////
+	/// EBSD functions                                      ///
+	///////////////////////////////////////////////////////////
+
+	// Retrieve the list of predefined  acquisition setups
+	// Profiles    : buffer to store the list information
+	// BufSize    : Size of buffer
+	int32_t EBSDGetAcquisitionProfiles(uint32_t CID, char* Profiles, int32_t BufSize)
+	{
+		if (pEBSDGetAcquisitionProfiles)
+			return pEBSDGetAcquisitionProfiles(CID, Profiles, BufSize);
+		else return -1;
+	}
+
+	// Load a predefined  acquisition setup
+	// Profile    : buffer with profile name to select
+	int32_t EBSDSelectAcquisitionProfile(uint32_t CID, char* Profile)
+	{
+		if (pEBSDSelectAcquisitionProfile)
+			return pEBSDSelectAcquisitionProfile(CID, Profile);
+		else return -1;
+	}
+
+	// Start EBSD acquisition with selected setup
+	int32_t EBSDStartAcquisition(uint32_t CID)
+	{
+		if (pEBSDStartAcquisition)
+			return pEBSDStartAcquisition(CID);
+		else return -1;
+	}
+
+	// Start EBSD acquisition with defined profile data
+	int32_t EBSDStartAcquisitionWithProfile(uint32_t CID, char* Profile)
+	{
+		if (pEBSDStartAcquisitionWithProfile)
+			return pEBSDStartAcquisitionWithProfile(CID, Profile);
+		else return -1;
+	}
+
+	// Stop EBSD acquisition
+	int32_t EBSDStopAcquisition(uint32_t CID)
+	{
+		if (pEBSDStopAcquisition)
+			return pEBSDStopAcquisition(CID);
+		else return -1;
+	}
+
+	// Retrieve EBSD acquisition state
+	// CurrentLine			: current acquisition Y -position
+	// PercentReady			: Current state of Acquisition in %
+	// IndexingPercentReady : Current State of Indexing in %
+	// AcquisitionRunning	: Is just giving the running state of the Acquisition
+	// IndexingRunning		: Is just giving the running state of the Indexing
+	int32_t EBSDGetAcquisitionState(uint32_t CID, int32_t& CurrentLine, int32_t& PercentReady, int32_t& IndexingPercentReady, bool& AcquisitionRunning, bool& IndexingRunning)
+	{
+		if (pEBSDGetAcquisitionState)
+			return pEBSDGetAcquisitionState(CID, CurrentLine, PercentReady, IndexingPercentReady, AcquisitionRunning, IndexingRunning);
+		else return -1;
+	}
+
+	// Save EBSD acquisition data to file in Bruker format
+	// FileName		: File name for the file to store information (*.bcf)
+	// SaveOptions	: Bit flags to specify which information has to be stored (frames, detected lines?
+	int32_t EBSDSaveToFile(uint32_t CID, char* FileName, bool WithEdx, bool WithPatterns)
+	{
+		if (pEBSDSaveToFile)
+			return pEBSDSaveToFile(CID, FileName, WithEdx, WithPatterns);
+		else return -1;
+	}
+
+	// BaseFileName	: Base file name for the result files to export (map images?
+	// ExportOptions: Integer representation of export options (Phase=2,IPFX=3,IPFY=4,IPFZ=5,Euler=6)
+	int32_t EBSDExportData(uint32_t CID, char* BaseFileName, int32_t ExportOptions)
+	{
+		if (pEBSDExportData)
+			return pEBSDExportData(CID, BaseFileName, ExportOptions);
+		else return -1;
+	}
+
+	// Buffer:Pointer
+	// BufferSize:integer
+	// ExportOptions: longint representation of export options (Phase=2,IPFX=3,IPFY=4,IPFZ=5,Euler=6)
+	int32_t EBSDExportDataBuffer(uint32_t CID, void* Buffer, int& BufferSize, int ExportOptions)
+	{
+		if (pEBSDExportDataBuffer)
+			return pEBSDExportDataBuffer(CID, Buffer, BufferSize, ExportOptions);
+		else return -1;
+	}
+
+	// BaseFileName	: Base file name for the result list (ctf-file) to export
+	int32_t EBSDExportResults(uint32_t CID, char* BaseFileName)
+	{
+		if (pEBSDExportResults)
+			return pEBSDExportResults(CID, BaseFileName);
+		else return -1;
+	}
+
+	// Retrieve EBSD detector position
+	// Position		: Detector position in mm
+	int32_t EBSDGetDetectorPosition(uint32_t CID, double& Position)
+	{
+		if (pEBSDGetDetectorPosition)
+			return pEBSDGetDetectorPosition(CID, Position);
+		else return -1;
+	}
+
+	// Move EBSD detector to specified position
+	// Position		: Detector position in mm
+	// Speed		: Detector speed in mm/s:
+	int32_t EBSDSetDetectorPosition(uint32_t CID, double Position, double Speed)
+	{
+		if (pEBSDSetDetectorPosition)
+			return pEBSDSetDetectorPosition(CID, Position, Speed);
+		else return -1;
+	}
+
+	int32_t EBSDImageAcquireEx(uint32_t CID, void* Buffer, int& BufSize, int PosX, int PosY)
+	{
+		if (pEBSDImageAcquireEx)
+			return pEBSDImageAcquireEx(CID, Buffer, BufSize, PosX, PosY);
+		else return -1;
+	}
+
+	int32_t EBSDImageAcquireWithPC(uint32_t CID, void* Buffer, int& BufSize, int PosX, int PosY, int NFrameAvg, double& PCX, double& PCY, double& PCL)
+	{
+		if (pEBSDImageAcquireWithPC)
+			return pEBSDImageAcquireWithPC(CID, Buffer, BufSize, PosX, PosY, NFrameAvg, PCX, PCY, PCL);
+		else return -1;
+	}
+
+	// Acquire pattern images, Buffer returns raw data
+	int32_t EBSDImageAcquireRawDataFromPosition(uint32_t CID, void* Buffer, int& BufSize, int PosX, int PosY, int& Width, int& Height, int& PixelBytes)
+	{
+		if (pEBSDImageAcquireRawDataFromPosition)
+			return pEBSDImageAcquireRawDataFromPosition(CID, Buffer, BufSize, PosX, PosY, Width, Height, PixelBytes);
+		else return -1;
+	}
+
+	int32_t EBSDImageAcquireRawDataFromPositionWithPC(uint32_t CID, void* Buffer, int& BufSize, int PosX, int PosY, int NFrameAvg, double& PCX, double& PCY, double& PCL, int& Width, int& Height, int& PixelBytes)
+	{
+		if (pEBSDImageAcquireRawDataFromPositionWithPC)
+			return pEBSDImageAcquireRawDataFromPositionWithPC(CID, Buffer, BufSize, PosX, PosY, NFrameAvg, PCX, PCY, PCL, Width, Height, PixelBytes);
+		else return -1;
+	}
+
+	int32_t EBSDPointListImageAcquireWithPC(uint32_t CID, void* Buffer, int& BufSize, uint32_t PointCount, PMultiPointList Points, int NFrameAvg, double& PCX, double& PCY, double& PCL, int& Width, int& Height, int& PixelBytes)
+	{
+		if (pEBSDPointListImageAcquireWithPC)
+			return pEBSDPointListImageAcquireWithPC(CID, Buffer, BufSize, PointCount, Points, NFrameAvg, PCX, PCY, PCL, Width, Height, PixelBytes);
+		else return -1;
+	}
+
+	int32_t EBSDPointListImageAcquireRawDataWithPC(uint32_t CID, void* Buffer, int& BufSize, uint32_t PointCount, PMultiPointList Points, int NFrameAvg, double& PCX, double& PCY, double& PCL, int& Width, int& Height, int& PixelBytes)
+	{
+		if (pEBSDPointListImageAcquireRawDataWithPC)
+			return pEBSDPointListImageAcquireRawDataWithPC(CID, Buffer, BufSize, PointCount, Points, NFrameAvg, PCX, PCY, PCL, Width, Height, PixelBytes);
+		else return -1;
+	}
+
+
+	// Settings include:
+	// TiltAngle of the Detector
+	// TiltAzimuthAngle of the Detector;
+	// ScanRotation
+	// WD
+	// DetectorAxis
+	// DetectorTilt
+	// PhosphorSize
+	int32_t EBSDStartCalibration(uint32_t CID, PRTEBSDCalibSettings Settings)
+	{
+		if (pEBSDStartCalibration)
+			return pEBSDStartCalibration(CID, Settings);
+		else return -1;
+	}
+
+	// Stop EBSD Calibration
+	int32_t  EBSDStopCalibration(uint32_t CID)
+	{
+		if (pEBSDStopCalibration)
+			return pEBSDStopCalibration(CID);
+		else return -1;
+	}
+
+	// CurrentLine	: not yet in use
+	// PercentReady	: Calibration state in %
+	// Running		: Running state of calibration
+	int32_t EBSDGetCalibrationState(uint32_t CID, int32_t& CurrentLine, int32_t& PercentReady, bool& Running)
+	{
+		if (pEBSDGetCalibrationState)
+			return pEBSDGetCalibrationState(CID, CurrentLine, PercentReady, Running);
+		else return -1;
+	}
+
+	int32_t EBSDSaveEBSPImageFromPosition(uint32_t CID, char* aBaseFilename, int32_t X, int32_t Y)
+	{
+		if (pEBSDSaveEBSPImageFromPosition)
+			return pEBSDSaveEBSPImageFromPosition(CID, aBaseFilename, X, Y);
+		else return -1;
+	}
+
+
+	int32_t EBSDSetExposureTime(uint32_t CID, int32_t ExposureTime)
+	{
+		if (pEBSDSetExposureTime)
+			return pEBSDSetExposureTime(CID, ExposureTime);
+		else return -1;
+	}
+
+	int32_t EBSDGetExposureTime(uint32_t CID, int32_t& ExposureTime)
+	{
+		if (pEBSDGetExposureTime)
+			return pEBSDGetExposureTime(CID, ExposureTime);
+		else return -1;
+	}
+
+	// Width:  Current camera width
+	// Height: Current camera height
+	int32_t EBSDGetImageConfiguration(uint32_t CID, int32_t& Width, int32_t& Height)
+	{
+		if (pEBSDGetImageConfiguration)
+			return pEBSDGetImageConfiguration(CID, Width, Height);
+		else return -1;
+	}
+
+	int32_t EBSDSetGain(uint32_t CID, int32_t Value)
+	{
+		if (pEBSDSetGain)
+			return pEBSDSetGain(CID, Value);
+		else return -1;
+	}
+
+	int32_t EBSDGetGain(uint32_t CID, int32_t& Value)
+	{
+		if (pEBSDGetGain)
+			return pEBSDGetGain(CID, Value);
+		else return -1;
+	}
+
+	int32_t EBSDGetTilt(uint32_t CID, double& Value)
+	{
+		if (pEBSDGetTilt)
+			return pEBSDGetTilt(CID, Value);
+		else return -1;
+	}
+
+	//Count : returns the amount of image format (binning)
+	int32_t EBSDGetAvailablePatternFormatCount(uint32_t CID, int32_t& Count)
+	{
+		if (pEBSDGetAvailablePatternFormatCount)
+			return pEBSDGetAvailablePatternFormatCount(CID, Count);
+		else return -1;
+	}
+
+	//FormatIndex: Seletion index of image format
+	//Width:  Camera Width
+	//Height: Camera Height
+	int32_t EBSDGetAvailablePatternFormat(uint32_t CID, const int32_t FormatIndex, int32_t& Width, int32_t& Height)
+	{
+		if (pEBSDGetAvailablePatternFormat)
+			return pEBSDGetAvailablePatternFormat(CID, FormatIndex, Width, Height);
+		else return -1;
+	}
+
+	//FormatIndex: The choosen Index for Camera Format 
+	int32_t EBSDSetPatternFormat(uint32_t CID, const int32_t FormatIndex)
+	{
+		if (pEBSDSetPatternFormat)
+			return pEBSDSetPatternFormat(CID, FormatIndex);
+		else return -1;
+	}
+
+	//Value: true (16bit Mode), false (8 bit Mode)
+	int32_t EBSDSetPattern16bitMode(uint32_t CID, const bool Value)
+	{
+		if (pEBSDSetPattern16bitMode)
+			return pEBSDSetPattern16bitMode(CID, Value);
+		else return -1;
+	}
+
+	int32_t EBSDGetEstimatedMappingTime(uint32_t CID, int32_t& Time)
+	{
+		if (pEBSDGetEstimatedMappingTime)
+			return pEBSDGetEstimatedMappingTime(CID, Time);
+		else return -1;
+	}
+
+	int32_t EBSDStartAcquisitionFromPointList(uint32_t CID, PPointArray PointList, int32_t pointcount)
+	{
+		if(pEBSDStartAcquisitionFromPointList)
+			return pEBSDStartAcquisitionFromPointList(CID, PointList, pointcount);
+		else 
+			return -1;
+	}
+
+	int32_t EBSDGetPointResults(uint32_t CID, PEBSDIndexingResultArray PointResults, int32_t & pointcount)
+	{
+		if(pEBSDGetPointResults)
+			return pEBSDGetPointResults(CID, PointResults, pointcount);
+		else
+			return -1;
+	}
+}

+ 368 - 0
OTSCPP/OTSControl/Bruker/Bruker.API.Esprit.h

@@ -0,0 +1,368 @@
+/*
+Bruker.API.Esprit.h
+Header File for Bruker Esprit-Interface 
+
+Microsoft Visual Studio 2015
+*/
+
+#pragma once
+
+#include <stddef.h>
+#include <tchar.h>
+#include "Bruker.API.CommonFunctions.h"
+#include "Bruker.API.CommonStructures.h"
+namespace BrukerDll
+{
+
+	struct TFeatureData;
+	struct TRTEBSDCalibSettings;
+	struct TRTElementRegion;
+	struct TRTHyMapProfileSettings;
+	struct TRTImageInfoEx;
+	struct TSegment;
+
+	#pragma pack(push, 1)
+	struct TRTEBSDCalibSettings {
+		int32_t TiltAngle;
+		int32_t TiltAzimuthAngle;
+		int32_t ScanRotation;
+		int32_t WD;
+		int32_t DetectorAxis;
+		int32_t DetectorTilt;
+		int32_t PhosphorSize;
+	};
+	#pragma pack(pop)
+
+	typedef TRTEBSDCalibSettings* PRTEBSDCalibSettings;
+
+	#pragma pack(push, 1)
+	struct TRTImageInfoEx {
+		int32_t Magnification;
+		double PixelSizeX;					// µm per Pixel
+		double PixelSizeY;
+		double HighVoltage;					// kV
+		double WorkingDistance;				// mm
+	};
+	#pragma pack(pop)
+
+	typedef TRTImageInfoEx* PRTImageInfoEx;
+
+	#pragma pack(push, 1)					// describes 1 scan feature
+	struct TFeatureData {
+		int32_t SegmentCount;
+		PSegmentList Segments;
+	};
+	#pragma pack(pop)
+
+	typedef TFeatureData* PFeatureDataList;
+
+	bool LoadEspritAPI(char* csAPILibFile);
+
+	//----------------------------------------------------------------------------------
+	// Interface functions of Bruker.API.Esprit.DLL
+	//----------------------------------------------------------------------------------
+
+	// Ask for SGU/SCU/SBU device connection status
+	// Status: 0 = connected, 1 = wait for reconnection, 2 = reconnecting
+	// TimeLeftForReconnection in ms
+	int32_t HardwareConnectionGetStatus(uint32_t CID, int32_t& Status, boolean& WasInterrupted, int32_t& TimeLeftForReconnection);
+
+	// Reset connection error flag 'WasInterrupted' from above once detected
+	int32_t HardwareConnectionResetErrorFlag(uint32_t CID);
+
+	// Initialize connection reset procedure, this will trigger a 'watchdogged' hardware reset in SCU/SGU
+	int32_t HardwareConnectionReset(uint32_t CID);
+
+	// Reset scan hardware, device will have default configuration afterwards, so be sure to re-configure it correctly
+	int32_t ImageReset(uint32_t CID);
+
+	// Read current image device configuration
+	int32_t ImageGetConfiguration(uint32_t CID, uint32_t& Width, uint32_t& Height, uint32_t& Average, bool& Ch1, bool& Ch2);
+
+	// Write current image device configuration
+	int32_t ImageSetConfiguration(uint32_t CID, uint32_t Width, uint32_t Height, uint32_t Average, bool Ch1, bool Ch2);
+
+	// Use external scan engine which triggers our scan generator trough an external signal
+	int32_t ImageSetExternalScan(uint32_t CID, bool UseExternalScan);
+
+	// Aquire new image and read image data
+	int32_t ImageAquireImage(uint32_t CID, int32_t Ch, bool ShowProgress, void* Buffer, int32_t& BufSize, PRTImageInfoEx ImgInfo);
+
+	// Aquire new image and read image data
+	// Options  : Bit combination of the following values
+	//                cImgAcq_ShowProgress    = 1;
+	//                cImgAcq_UpdateSEMData   = 2;
+	int32_t ImageAquireImageEx(uint32_t CID, int32_t Ch, void* Buffer, uint32_t Options, int32_t& BufSize, PRTImageInfoEx ImgInfo);
+
+	// Read the image field width from scan settings and SEM magnification, microns unit
+	int32_t ImageGetFieldWidth(uint32_t CID, double& FieldWidth);
+
+	// Set drift correction vector
+	int32_t ImageSetExternalDriftCorrection(uint32_t CID, double ShiftX, double ShiftY);
+
+	int32_t ImageGetDriftCorrectionActive(uint32_t CID, bool& Active);
+
+	int32_t ImageGetLatestKnownScanPosition(uint32_t CID, int& X, int& Y);
+
+	int32_t ImageGetScannedSegmentsCount(uint32_t CID, __int64& aCount);
+
+	// Set electron beam position in image
+	int32_t ImageSetPoint(uint32_t CID, uint32_t X, uint32_t Y);
+
+	// functions to deal with point lists
+	// CID           : connection identifier
+	// SPU           : spectrometer index (1..n)
+	// SegmentCount,
+	// LineSegments  : description of points to measure
+	// RealTime:     : acquisition time in ms
+	int32_t StartPointListMeasurement(uint32_t CID, int32_t SPU, uint32_t SegmentCount, PSegmentList LineSegments, uint32_t RealTime);
+
+	//    CID         : connection identifier
+	//    Index       : spectrum index (1..n)
+	//    SpectrumBuf : buffer to hold complete spectrum with header (around 20kB), must be allocated by caller
+	//    BufSize     : size of spectrum buffer
+	int32_t GetPointListSpectrum(uint32_t CID, int32_t Index, PRTSpectrumHeaderRec SpectrumBuf, int32_t BufSize);
+
+	int32_t QuantifyPointListSpectrum(uint32_t CID, int32_t Index, char* MethodName, char* Params, char* ResultBuf, int32_t ResultBufSize, PRTSpectrumHeaderRec SpectrumBuf, int32_t BufSize);
+
+	// CID        : connection identifier
+	// Index      : spectrum index (1..n)
+	// FileName   : filename to save to
+	int32_t SavePointListSpectrum(uint32_t CID, int32_t Buffer, char* FileName);
+
+	///////////////////////////////////////////////////////////
+	// functions to deal with object lists                  ///
+	///////////////////////////////////////////////////////////
+	int32_t StartFeatureListMeasurement(uint32_t CID, int32_t SPU, uint32_t FeatureCount, PFeatureDataList Features, __int16** PixelTimes);
+
+	int32_t GetFeatureListSpectrum(uint32_t CID, int32_t Index, PRTSpectrumHeaderRec SpectrumBuf, int32_t BufSize);
+
+	int32_t QuantifyFeatureListSpectrum(uint32_t CID, int32_t Index, char* MethodName, char* Params, char* ResultBuf, int32_t ResultBufSize, PRTSpectrumHeaderRec SpectrumBuf, int32_t BufSize);
+
+	int32_t SaveFeatureListSpectrum(uint32_t CID, int32_t Buffer, char* FileName);
+
+	///////////////////////////////////////////////////////////
+	/// functions to communicate with SEM                   ///
+	///////////////////////////////////////////////////////////
+
+	int32_t SetSEMData(uint32_t CID, double Magnification, double HighVoltage, double WorkingDistance);
+
+	int32_t GetSEMData(uint32_t CID, double& Magnification, double& HighVoltage, double& WorkingDistance);
+
+	int32_t SetSEMParameter(uint32_t CID, char* Params, char* ValueIDs, double* Values);
+
+	int32_t GetSEMParameter(uint32_t CID, char* Params, char* ValueIDs, double* Values);
+
+	int32_t GetSEMBCData(uint32_t CID, double& Brightness, double& Contrast);
+
+	int32_t SetSEMBCData(uint32_t CID, double Brightness, double Contrast);
+
+	int32_t GetSEMProbeCurrent(uint32_t CID, double& ProbeCurrent);
+
+	int32_t SetSEMProbeCurrent(uint32_t CID, double ProbeCurrent);
+
+	int32_t GetSEMSpotSize(uint32_t CID, double& SpotSize);
+
+	int32_t SetSEMSpotSize(uint32_t CID, double SpotSize);
+
+	int32_t SetSEMDetector(uint32_t CID, int Channel, char* DetectorName);
+
+	int32_t GetSEMDetector(uint32_t CID, int Channel, char* DetectorName, int32_t BufSize);
+
+	int32_t SetSEMStageData(uint32_t CID, double XPos, double YPos, double ZPos, double Tilt, double Rotation);
+
+	int32_t GetSEMStageData(uint32_t CID, double& XPos, double& YPos, double& ZPos, double& Tilt, double& Rotation);
+
+	int32_t GetSEMStageRange(uint32_t CID, double& Xmin, double& Xmax, double& Ymin, double& Ymax, double& Zmin, double& Zmax, double& Tmin, double& Tmax, double& Rmin, double& Rmax);
+
+	int32_t GetSEMStageState(uint32_t CID, int32_t& State);
+
+	int32_t GetSEMCapabilities(uint32_t CID, char* Capabilities, int32_t BufSize);
+
+	int32_t GetSEMInfo(uint32_t CID, char* Info, int32_t BufSize);
+
+	int32_t SetSEMExternalOn(uint32_t CID);
+
+	int32_t SetSEMExternalOff(uint32_t CID);
+
+	int32_t ResetSEMCommunication(uint32_t CID);
+
+	int32_t SwitchSEMOff(uint32_t CID, bool HVOff, bool BeamCurrentOff, bool BeamBlank);
+
+	///////////////////////////////////////////////////////////
+	/// Move EDS detector                                   ///
+	///////////////////////////////////////////////////////////
+
+	// Detector : Detector to be moved ( 1 in most cases )
+	// Position : Position to move to ( 1 = Park position, 2 = Acquisition position )
+	int32_t EDSSetDetectorPosition(uint32_t CID, int32_t Detector, int32_t Position);
+
+	// Detector : Detector to ask for position ( 1 in most cases )
+	// Position : Current position ( 1 = Park position, 2 = Acquisition position )
+	int32_t EDSGetDetectorPosition(uint32_t CID, int32_t Detector, int32_t& Position);
+
+	///////////////////////////////////////////////////////////
+	/// Mapping functions                                   ///
+	///////////////////////////////////////////////////////////
+
+	// PixelTime   : Dwell time per Pixel in microseconds
+	// RealTime    : Acquisition time in s, RealTime=0 does exactly 1 scan
+	int32_t HyMapStart(uint32_t CID, int32_t SPU, uint32_t PixelTime, uint32_t RealTime);
+
+	// PixelTime   : Dwell time per Pixel in microseconds
+	// RealTime    : Acquisition time in s, RealTime=0 does exactly 1 scan
+	// Region      : Image region to be mapped   
+	int32_t HyMapStartEx(uint32_t CID, int32_t SPU, uint32_t PixelTime, uint32_t RealTime, TFeatureData Region);
+
+	// PixelTime   : Dwell time per Pixel in microseconds
+	// RealTime    : Acquisition time in s, RealTime=0 does exactly 1 scan
+	// Region      : Image region to be mapped
+	// Profile     : XML serialized profile
+	int32_t HyMapStartWithProfile(uint32_t CID, int32_t SPU, uint32_t PixelTime,  TFeatureData Region, char* Profile);
+
+	// MapSettings : Map settings
+	// Profile     : XML serialized profile
+	// BufSize     : Size of buffer
+	int32_t HyMapCreateProfile(const TRTHyMapProfileSettings& MapSettings, char* Profile, int32_t& BufSize);
+
+	// DataFileName: complete name of existing mapping data file
+	// Profile     : XML serialized EDS map profile
+	int32_t SetDataAndProfileToUI(uint32_t CID, char* DataFileName, char* Profile);
+
+
+	///////////////////////////////////////////////////////////
+	/// EBSD functions                                      ///
+	///////////////////////////////////////////////////////////
+
+	// Retrieve the list of predefined  acquisition setups
+	// Profiles    : buffer to store the list information
+	// BufSize    : Size of buffer
+	int32_t EBSDGetAcquisitionProfiles(uint32_t CID, char* Profiles, int32_t BufSize);
+
+	// Load a predefined  acquisition setup
+	// Profile    : buffer with profile name to select
+	int32_t EBSDSelectAcquisitionProfile(uint32_t CID, char* Profile);
+
+	// Start EBSD acquisition with selected setup
+	int32_t EBSDStartAcquisition(uint32_t CID);
+
+	// Start EBSD acquisition with defined profile data
+	int32_t EBSDStartAcquisitionWithProfile(uint32_t CID, char* Profile);
+
+	// Stop EBSD acquisition
+	int32_t EBSDStopAcquisition(uint32_t CID);
+
+	// Retrieve EBSD acquisition state
+	// CurrentLine    : current acquisition Y -position
+	// PercentReady: Current state of Acquisition in %
+	// IndexingPercentReady : Current State of Indexing in %
+	// AcquisitionRunning : Is just giving the running state of the Acquisition
+	// IndexingRunning    : Is just giving the running state of the Indexing
+	int32_t EBSDGetAcquisitionState(uint32_t CID, int32_t& CurrentLine, int32_t& PercentReady, int32_t& IndexingPercentReady, bool& AcquisitionRunning, bool& IndexingRunning);
+
+	// Save EBSD acquisition data to file in Bruker format
+	// FileName    : File name for the file to store information (*.bcf)
+	// WithEdx     : Saves EDX Data
+	// WithPatterns: Saves Patterns
+	int32_t EBSDSaveToFile(uint32_t CID, char* FileName, bool WithEdx, bool WithPatterns);
+
+	// BaseFileName: Base file name for the result files to export (map images?
+	// ExportOptions: Integer representation of export options (Phase=2,IPFX=3,IPFY=4,IPFZ=5,Euler=6)
+	int32_t EBSDExportData(uint32_t CID, char* BaseFileName, int32_t ExportOptions);
+
+	// Buffer:Pointer
+	// BufferSize:integer
+	// ExportOptions: longint representation of export options (Phase=2,IPFX=3,IPFY=4,IPFZ=5,Euler=6)
+	int32_t EBSDExportDataBuffer(uint32_t CID, void* Buffer, int& BufferSize, int ExportOptions);
+
+	// BaseFileName: Base file name for the result list (ctf-file) to export
+	int32_t EBSDExportResults(uint32_t CID, char* BaseFileName);
+
+	// Retrieve EBSD detector position
+	// Position : Detector position in mm
+	int32_t EBSDGetDetectorPosition(uint32_t CID, double& Position);
+
+	// Move EBSD detector to specified position
+	// Position : Detector position in mm
+	// Speed    : Detector speed in mm/s:
+	int32_t EBSDSetDetectorPosition(uint32_t CID, double Position, double Speed);
+
+	// Acquire pattern images, Buffer returns bitmap stream structure
+	int32_t EBSDImageAcquireEx(uint32_t CID, void* Buffer, int& BufSize, int PosX, int PosY);
+
+	int32_t EBSDImageAcquireWithPC(uint32_t CID, void* Buffer, int& BufSize, int PosX, int PosY, int NFrameAvg, double& PCX, double& PCY, double& PCL);
+
+
+	// Acquire pattern images, Buffer returns raw data
+	int32_t EBSDImageAcquireRawDataFromPosition(uint32_t CID, void* Buffer, int& BufSize, int PosX, int PosY, int& Width, int& Height, int& PixelBytes);
+
+	int32_t EBSDImageAcquireRawDataFromPositionWithPC(uint32_t CID, void* Buffer, int& BufSize, int PosX, int PosY, int NFrameAvg, double& PCX, double& PCY, double& PCL, int& Width, int& Height, int& PixelBytes);
+
+	// Acquire pattern images for multiple points, Buffer returns Bitmap image buffer
+
+	int32_t EBSDPointListImageAcquireWithPC(uint32_t CID, void* Buffer, int& BufSize, uint32_t PointCount, PMultiPointList Points, int NFrameAvg, double& PCX, double& PCY, double& PCL, int& Width, int& Height, int& PixelBytes);
+
+	// Acquire pattern images for multiple points, Buffer returns raw data buffer
+
+	int32_t EBSDPointListImageAcquireRawDataWithPC(uint32_t CID, void* Buffer, int& BufSize, uint32_t PointCount, PMultiPointList Points, int NFrameAvg, double& PCX, double& PCY, double& PCL, int& Width, int& Height, int& PixelBytes);
+
+
+	// Settings include:
+	// TiltAngle of the Detector
+	// TiltAzimuthAngle of the Detector;
+	// ScanRotation
+	// WD
+	// DetectorAxis
+	// DetectorTilt
+	// PhosphorSize
+	int32_t EBSDStartCalibration(uint32_t CID, PRTEBSDCalibSettings Settings);
+
+	// Stop EBSD Calibration   
+	int32_t  EBSDStopCalibration(uint32_t CID);
+
+	//CurrentLine  : not yet in use
+	//PercentReady : Calibration state in %
+	//Running      : Running state of calibration
+	int32_t EBSDGetCalibrationState(uint32_t CID, int32_t& CurrentLine, int32_t& PercentReady, bool& Running);
+
+	int32_t EBSDSaveEBSPImageFromPosition(uint32_t CID, char* aBaseFilename, int32_t X, int32_t Y);
+
+	int32_t EBSDSetExposureTime(uint32_t CID, int32_t ExposureTime);
+
+	int32_t EBSDGetExposureTime(uint32_t CID, int32_t& ExposureTime);
+
+	//Width:  Current camera width
+	//Height: Current camera height 
+	int32_t EBSDGetImageConfiguration(uint32_t CID, int32_t& Width, int32_t& Height);
+
+	int32_t EBSDSetGain(uint32_t CID, int32_t Value);
+
+	int32_t EBSDGetGain(uint32_t CID, int32_t& Value);
+
+	int32_t EBSDGetTilt(uint32_t CID, double& Value);
+
+	//Count : returns the amount of image format (binning)
+	int32_t EBSDGetAvailablePatternFormatCount(uint32_t CID, int32_t& Count);
+
+	//FormatIndex: Seletion index of image format
+	//Width:  Camera Width
+	//Height: Camera Height
+	int32_t EBSDGetAvailablePatternFormat(uint32_t CID, const int32_t FormatIndex, int32_t& Width, int32_t& Height);
+
+	//FormatIndex: The choosen Index for Camera Format 
+	int32_t EBSDSetPatternFormat(uint32_t CID, const int32_t FormatIndex);
+
+	//Value: true (16bit Mode), false (8 bit Mode)
+	int32_t EBSDSetPattern16bitMode(uint32_t CID, const bool Value);
+
+	int32_t EBSDGetEstimatedMappingTime(uint32_t CID, int32_t& Time);
+
+	//PointList: array of points to be measured
+	//PointCount: number of points to be measured
+	int32_t EBSDStartAcquisitionFromPointList(uint32_t CID, PPointArray PointList, int32_t pointcount);
+
+	//PointResults: all results of the measured map
+	//pointcount: number of available results
+	//Call with PointResults == NULL and pointcount==0 to get number of results (for reserving sufficient space)
+	int32_t EBSDGetPointResults(uint32_t CID, PEBSDIndexingResultArray PointResults, int32_t & pointcount);
+}

+ 280 - 0
OTSCPP/OTSControl/CFindPeaks.cpp

@@ -0,0 +1,280 @@
+#pragma once
+#include "stdafx.h"
+#include "CFindPeaks.h"
+#include <algorithm>
+namespace CPeak
+{
+	const long ATOMIC_NUMBER_MIN = 1;
+	const long ATOMIC_NUMBER_MAX = 103;
+	const CString theElementNameList{ _T("H,He")
+	_T(",Li,Be,B,C,N,O,F,Ne")
+	_T(",Na,Mg,Al,Si,P,S,Cl,Ar")
+	_T(",K,Ca,Sc,Ti,V,Cr,Mn,Fe,Co,Ni,Cu,Zn,Ga,Ge,As,Se,Br,Kr")
+	_T(",Rb,Sr,Y,Zr,Nb,Mo,Tc,Ru,Rh,Pd,Ag,Cd,In,Sn,Sb,Te,I,Xe")
+	_T(",Cs,Ba,La")
+	_T(",Ce,Pr,Nd,Pm,Sm,Eu,Gd,Tb,Dy,Ho,Er,Tm,Yb,Lu")
+	_T(",Hf,Ta,W,Re,Os,Ir,Pt,Au,Hg,Tl,Pb,Bi,Po,At,Rn")
+	_T(",Fr,Ra,Ac")
+	_T(",Th,Pa,U,Np,Pu,Am,Cm,Bk,Cf,Es,Fm,Md,No,Lr") };
+	const CString ELEMENT_NAMES[ATOMIC_NUMBER_MAX] =
+	{ _T("H"),_T("He"),
+		_T("Li"),_T("Be"),_T("B"),_T("C"),_T("N"),_T("O"),_T("F"),_T("Ne"),
+		_T("Na"),_T("Mg"),_T("Al"),_T("Si"),_T("P"),_T("S"),_T("Cl"),_T("Ar"),
+		_T("K"),_T("Ca"),_T("Sc"),_T("Ti"),_T("V"),_T("Cr"),_T("Mn"),_T("Fe"),_T("Co"),_T("Ni"),_T("Cu"),_T("Zn"),_T("Ga"),_T("Ge"),_T("As"),_T("Se"),_T("Br"),_T("Kr"),
+		_T("Rb"),_T("Sr"),_T("Y"),_T("Zr"),_T("Nb"),_T("Mo"),_T("Tc"),_T("Ru"),_T("Rh"),_T("Pd"),_T("Ag"),_T("Cd"),_T("In"),_T("Sn"),_T("Sb"),_T("Te"),_T("I"),_T("Xe"),
+		_T("Cs"),_T("Ba"),_T("La"),
+		_T("Ce"),_T("Pr"),_T("Nd"),_T("Pm"),_T("Sm"),_T("Eu"),_T("Gd"),_T("Tb"),_T("Dy"),_T("Ho"),_T("Er"),_T("Tm"),_T("Yb"),_T("Lu"),
+		_T("Hf"),_T("Ta"),_T("W"),_T("Re"),_T("Os"),_T("Ir"),_T("Pt"),_T("Au"),_T("Hg"),_T("Tl"),_T("Pb"),_T("Bi"),_T("Po"),_T("At"),_T("Rn"),
+		_T("Fr"),_T("Ra"),_T("Ac"),
+		_T("Th"),_T("Pa"),_T("U"),_T("Np"),_T("Pu"),_T("Am"),_T("Cm"),_T("Bk"),_T("Cf"),_T("Es"),_T("Fm"),_T("Md"),_T("No"),_T("Lr"),
+	};
+
+	const double ELEMENT_ATOMIC_WEIGHT_VALUES[ATOMIC_NUMBER_MAX] =
+	{
+		1.008,4.003,
+		6.941,9.012,10.811,12.011,14.007,15.999,18.998,20.180,
+		22.990,24.305,26.982,28.086,30.974,32.066,35.453,39.948,
+		39.098,40.08,44.956,47.88,50.942,51.996,54.938,55.847,58.933,58.70,63.546,65.39,69.72,72.61,74.922,78.96,79.904,83.80,
+		85.468,87.62,88.906,91.22,92.906,95.94,98.00,101.07,102.906,106.42,107.868,112.41,114.82,118.71,121.76,127.60,126.905,131.29,
+		132.905,137.33,138.906,
+		140.12,140.908,144.24,145.0,150.36,151.97,157.25,158.925,162.50,64.93,167.26,168.934,173.04,174.967,
+		178.49,180.948,183.85,186.207,190.20,192.22,195.08,196.967,200.59,204.38,207.2,208.980,209.00,210.00,222.00,
+		223.00,226.025,227.028,
+		232.038,231.036,238.029,237.048,244.00,243.00,247.00,247.00,251.00,252.00,257.00,258.00,259.00,260.00
+	};
+
+	const double ELEMENT_ENERGY_VALUES_K[ATOMIC_NUMBER_MAX] =
+	{
+		0.0,0.0,
+		0.0,0.108,0.185,0.277,0.392,0.523,0.677,0.848,
+		1.040,1.254,1.486,1.740,2.013,2.307,2.622,2.957,
+		2.313,3.691,4.090,4.510,4.952,5.414,5.898,6.403,6.929,7.477,8.040,8.637,9.250,9.885,10.542,11.220,11.922,12.649,
+		13.393,14.163,14.955,15.776,16.617,17.481,18.368,19.282,20.217,21.180,22.166,23.175,24.209,25.272,26.359,27.471,28.615,29.779,
+		30.971,32.196,33.441,
+		34.717,36.031,37.358,38.725,40.118,41.534,42.992,44.476,45.997,47.534,49.100,50.730,52.362,54.078,
+		55.801,57.450,59.305,61.122,62.989,64.906,66.834,68.804,70.806,72.769,74.989,77.091,79.272,81.513,83.771,
+		86.098,88.480,90.880,
+		93.382,95.886,98.434,100.800,103.320,105.970,109.737,111.676,114.776,0.0,0.0,0.0,0.0,0.0
+	};
+
+	const double ELEMENT_ENERGY_VALUES_L[ATOMIC_NUMBER_MAX] =
+	{
+		0.0,0.0,
+		0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,
+		0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,
+		0.0,0.341,0.395,0.452,0.511,0.573,0.637,0.705,0.776,0.851,0.930,1.012,1.098,1.188,1.282,1.379,1.480,1.586,
+		1.694,1.806,1.922,2.042,2.166,2.293,2.424,2.558,2.696,2.838,2.984,3.133,3.286,3.443,3.604,3.768,3.937,4.109,
+		4.286,4.465,4.650,
+		4.839,5.033,5.229,5.432,5.636,5.845,6.056,6.272,6.494,6.719,6.947,7.179,7.414,7.654,
+		7.898,8.145,8.396,8.651,8.910,9.174,9.441,9.712,9.987,10.256,10.550,10.837,11.129,11.425,11.725,
+		12.029,12.338,12.650,
+		12.967,13.288,13.612,13.941,14.275,14.615,14.961,15.309,15.661,16.018,0.0,0.0,0.0,0.0
+	};
+
+	const double ELEMENT_ENERGY_VALUES_M[ATOMIC_NUMBER_MAX] =
+	{
+		0.0,0.0,
+		0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,
+		0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,
+		0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,
+		0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,
+		0.0,0.779,0.833,
+		0.883,0.929,0.978,1.032,1.081,1.137,1.185,1.240,1.293,1.347,1.405,1.462,1.521,1.581,
+		1.644,1.709,1.774,1.842,1.910,1.978,2.048,2.120,2.191,2.268,2.342,2.419,2.505,2.585,2.665,
+		2.747,2.830,2.915,
+		2.991,3.077,3.165,3.253,3.344,3.435,3.539,3.634,3.731,3.829,0.0,0.0,0.0,0.0
+	};
+	const double ENERGY_VALUE_INVALID = -1.0;
+	const long GENERALXRAYCHANNELS = 2000;
+	
+	double GetEnergyValueK(long a_nAtomNum)
+	{
+		double dEnergyValueK = ENERGY_VALUE_INVALID;
+		if (a_nAtomNum < 0 || a_nAtomNum >= ATOMIC_NUMBER_MAX)
+		{
+			return dEnergyValueK;
+		}
+		dEnergyValueK = ELEMENT_ENERGY_VALUES_K[a_nAtomNum - 1];
+		return dEnergyValueK;
+	}
+	double GetEnergyValueL(long a_nAtomNum)
+	{
+		double dEnergyValueL = ENERGY_VALUE_INVALID;
+		if (a_nAtomNum < 0 || a_nAtomNum >= ATOMIC_NUMBER_MAX)
+		{
+			return dEnergyValueL;
+		}
+		dEnergyValueL = ELEMENT_ENERGY_VALUES_L[a_nAtomNum - 1];
+		return dEnergyValueL;
+	}
+	double GetEnergyValueM(long a_nAtomNum)
+	{
+		double dEnergyValueM = ENERGY_VALUE_INVALID;
+		if (a_nAtomNum < 0 || a_nAtomNum >= ATOMIC_NUMBER_MAX)
+		{
+			return dEnergyValueM;
+		}
+		dEnergyValueM = ELEMENT_ENERGY_VALUES_M[a_nAtomNum - 1];
+		return dEnergyValueM;
+	}
+	std::vector<double>GetEnergyValues(long a_nAtomNum)
+	{
+		std::vector<double> vEnergyValues;
+		if (a_nAtomNum < 0 || a_nAtomNum >= ATOMIC_NUMBER_MAX)
+		{
+			return vEnergyValues;
+		}
+		double dEnergyValue = ELEMENT_ENERGY_VALUES_K[a_nAtomNum - 1];
+		vEnergyValues.push_back(dEnergyValue);
+		dEnergyValue = ELEMENT_ENERGY_VALUES_L[a_nAtomNum - 1];
+		vEnergyValues.push_back(dEnergyValue);
+		dEnergyValue = ELEMENT_ENERGY_VALUES_M[a_nAtomNum - 1];
+		vEnergyValues.push_back(dEnergyValue);
+		return vEnergyValues;
+	}
+	bool IsValidAtomNum(long a_nAtomNum)
+	{
+		 return a_nAtomNum >= ATOMIC_NUMBER_MIN && a_nAtomNum <= ATOMIC_NUMBER_MAX; 
+	}
+	void  GetAllElementsEnergyK(float fEnergy, float fDelt, std::vector<CString>& vecstr)
+	{
+		float fResult = 0;
+		CString str = _T("");
+		vecstr.clear();
+
+		fDelt = (fDelt < 0) ? -fDelt : fDelt;
+
+		for (int i = 0; i < ATOMIC_NUMBER_MAX; i++)
+		{
+			fResult = (float)ELEMENT_ENERGY_VALUES_K[i] - fEnergy;
+			str = _T("");
+
+			// 左侧
+			if (fResult >= -fDelt && fResult < 0)
+			{
+				str.Format(_T("%.3f: %s"), fResult, ELEMENT_NAMES[i]);
+				vecstr.push_back(str);
+			}
+			// 右侧
+			else if (fResult <= fDelt && fResult >= 0)
+			{
+				str.Format(_T("+%.3f: %s"), fResult, ELEMENT_NAMES[i]);
+				vecstr.push_back(str);
+			}
+			else
+			{
+			}
+		}
+	}
+	void SplitCString(const CString& str, const char* separator, int sep_number, vector<CString>& strArray)
+	{
+		strArray.clear();
+		int index = -1;
+		const int MAX_COUNT = 1000000; //最大分割长度
+		int smallIndex = MAX_COUNT;
+		CString szLeft;
+		CString szRight = str;
+
+		for (int i = 0; i < sep_number; i++)
+		{
+			index = szRight.Find(separator[i]);
+			if (index >= 0 && index < smallIndex)
+			{
+				smallIndex = index; //遍历获得所有的分割符的最小Index
+			}
+
+			if (i == sep_number - 1 && smallIndex != MAX_COUNT) //遍历全部分割符之后
+			{
+				szLeft = szRight.Left(smallIndex);
+				szLeft.Trim(); //去除空格
+				if (!szLeft.IsEmpty()) strArray.push_back(szLeft);
+
+				szRight = szRight.Right(szRight.GetLength() - smallIndex - 1);
+				szRight.Trim();
+				if (szRight.GetLength() > 0)
+				{
+					i = -1;
+					smallIndex = MAX_COUNT;
+				}
+				else break;
+			}
+			else if (i == sep_number - 1)
+			{
+				szRight.Trim();
+				if (!szRight.IsEmpty()) strArray.push_back(szRight);
+			}
+		}
+
+		/*return strArray.size();*/
+	}
+
+	bool cmp(const pair<int, int>& x, const pair<int, int>& y)
+	{
+		return x.second > y.second;
+	}
+
+	void SortMapByValue( map<int,int>& tMap, vector<pair<int, int>>& tVector)
+	{
+		for (map<int, int>::iterator curr = tMap.begin(); curr != tMap.end(); curr++)
+			tVector.push_back(make_pair(curr->first, curr->second));
+
+		std::sort(tVector.begin(), tVector.end(), cmp);
+	}
+
+	
+
+	BOOL FindPeaks(DWORD* nChannelData, vector<CString>& eleList)
+	{
+		//获取Peaks
+		DWORD m_nXrayData[GENERALXRAYCHANNELS];
+		memcpy(m_nXrayData, nChannelData, sizeof(DWORD) * GENERALXRAYCHANNELS);
+		map<int, int> tMap;
+		int countMap = 0;
+		for (size_t i = 0; i < GENERALXRAYCHANNELS; i++)
+		{
+			tMap.insert(pair<int, int>(i, m_nXrayData[i]));
+			countMap += m_nXrayData[i];
+		}
+		vector<pair<int, int>> tVector;
+		SortMapByValue(tMap, tVector);
+		vector<CString> nameList;
+		for (size_t i = 0; i < GENERALXRAYCHANNELS; i++)
+		{
+			if (tVector[i].second > countMap * 0.002)
+			{
+				std::vector<CString> vecstr;
+				GetAllElementsEnergyK((float)tVector[i].first / 100, 0.1f, vecstr);
+				if (vecstr.size() != 0)
+				{
+					LogErrorTrace(__FILE__, __LINE__, _T((vecstr[0])));
+					std::vector<CString> vecstrSplit;
+					SplitCString(vecstr[0], ":", 2, vecstrSplit);
+					if (std::find(nameList.begin(), nameList.end(), vecstrSplit[1]) == nameList.end())
+					{
+						nameList.push_back(vecstrSplit[1]);
+					}
+				}
+			}
+		}
+		//判断Peaks是否存在
+		for each (CString var in nameList)
+		{
+			if (std::find(eleList.begin(), eleList.end(), var) == eleList.end())
+			{
+
+			}
+			else
+			{
+				return TRUE;
+			}
+		}
+
+		return FALSE;
+	}
+
+
+
+
+}
+
+

+ 23 - 0
OTSCPP/OTSControl/CFindPeaks.h

@@ -0,0 +1,23 @@
+#pragma once
+#include "stdafx.h"
+
+namespace CPeak
+{
+	using namespace std;
+
+	
+	 double GetEnergyValueK(long a_nAtomNum);
+	 double GetEnergyValueL(long a_nAtomNum);
+	 double GetEnergyValueM(long a_nAtomNum);
+	 std::vector<double> GetEnergyValues(long a_nAtomNum);
+	// atomic number validation
+	 bool IsValidAtomNum(long a_nAtomNum);
+
+	
+	
+	 void GetAllElementsEnergyK(float fEnergy, float fDelt, std::vector<CString>& vecstr);
+void SplitCString(const CString& str, const char* separator, int sep_number, vector<CString>& strArray);
+bool cmp(const pair<int, int>& x, const pair<int, int>& y);
+void SortMapByValue(std::map<int,int>& tMap, vector<pair<int, int>>& tVector);
+BOOL FindPeaks(DWORD* nChannelData, vector<CString>& eleList);
+}