95 lines
2.5 KiB
C++

//======================================================================================================
// Copyright 2016, NaturalPoint Inc.
//======================================================================================================
//
// dllmain.cpp : Defines the entry point for the DLL application.
//
#include "dllcommon.h"
// stl
#include <list>
#include <memory>
using namespace std;
// OptiTrack Peripheral Device API
#include "IDeviceManager.h"
using namespace AnalogSystem;
// local devices
#include "ExampleDevice.h"
using namespace OptiTrackPluginDevices;
int hostVersionMajor, hostVersionMinor, hostVersionRevision;
#ifdef OPTITRACKPERIPHERALEXAMPLE_EXPORTS
#define OPTITRACKPERIPHERALEXAMPLE_API __declspec(dllexport)
#else
#define OPTITRACKPERIPHERALEXAMPLE_API __declspec(dllimport)
#endif
#ifdef __cplusplus
extern "C" {
#endif
// Report version to host
OPTITRACKPERIPHERALEXAMPLE_API void DLLVersion(int hostMajor, int hostMinor, int hostRevision, int& dllMajor, int& dllMinor, int& dllRevision)
{
hostVersionMajor = hostMajor;
hostVersionMajor = hostMinor;
hostVersionMajor = hostRevision;
// report this peripheral device's version to host
dllMajor = 1;
dllMinor = 0;
dllRevision = 0;
}
// Register device factories with host (1 factory per device)
OPTITRACKPERIPHERALEXAMPLE_API int DLLEnumerateDeviceFactories(IDeviceManager* pDeviceManager)
{
unique_ptr<ExampleDeviceFactory> deviceFactory;
// REQUIRED: Device detection - 1 factory for each device
int nDevices = 2;
// device factory / device 1
deviceFactory = unique_ptr<ExampleDeviceFactory>(new ExampleDeviceFactory("MyDevice1"));
pDeviceManager->RegisterDeviceFactory(std::move(deviceFactory)); // transfer ownership to host
// device factory / device 2
deviceFactory = unique_ptr<ExampleDeviceFactory>(new ExampleDeviceFactory("MyDevice2"));
pDeviceManager->RegisterDeviceFactory(std::move(deviceFactory)); // transfer ownership to host
return nDevices;
}
// Cleanup any plugin/DLL resources here.
OPTITRACKPERIPHERALEXAMPLE_API int PluginDLLUnload(IDeviceManager* pDeviceManager)
{
// OPTIONAL: perform device DLL shutdown here
return 0;
}
#ifdef __cplusplus
}
#endif
BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved )
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}