//  // // # # ### # # -= Nuclex Project =-  // // ## # # # ## ## DirectInput8Plugin.cpp - DirectInput8 extension  // // ### # # ###  // // # ### # ### Registers the extension module  // // # ## # # ## ##  // // # # ### # # R8 (C)2002 Markus Ewald -> License.txt  // //  // #include "DirectInput8Plugin/DirectInput8Plugin.h" #include "DirectInput8Plugin/Input/DirectInput8InputDevice.h" #include "Nuclex/Input/InputServer.h" #include "Nuclex/Kernel.h" using namespace Nuclex; using namespace Nuclex::Input; namespace { IDirectInput8 *g_pDirectInput8 = NULL; //  // //  DirectInput8InitTerm  // //  // /// DirectInput8 global initialization class /** Initializes global DLL data. Currently includes loading D3D8.dll (which is required only once per process) and searching for the function pointer to create the main DirectInput8 interface. */ class DirectInput8InitTerm { public: /// Constructor /** Initializes global data when the dll enters a process */ DirectInput8InitTerm() { HRESULT hResult = DirectInput8Create( GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, reinterpret_cast(&g_pDirectInput8), NULL ); if(FAILED(hResult)) { Kernel::logMessage( Kernel::MT_WARNING, "DirectInput8 failed to initialize. DirectInput8 support disabled." ); return; } Kernel::logMessage( Kernel::MT_INFO, "DirectInput8 is available." ); } /// Destructor /** Destroys global data when the dll leaves a process */ ~DirectInput8InitTerm() { if(g_pDirectInput8) { g_pDirectInput8->Release(); g_pDirectInput8 = NULL; } } } _DirectInput8InitTerm; // ############################################################################################# // // # addInputDeviceToKernel() # // // ############################################################################################# // BOOL CALLBACK addInputDeviceToKernel(LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef) { Kernel &TheKernel = *static_cast(pvRef); /* shared_ptr spDevice( new DirectInput8InputDevice(lpddi->guidInstance) ); TheKernel.getInputServer()->addDevice(spDevice->getName(), spDevice); */ return true; } } // ############################################################################################# // // # Nuclex::Input::getDirectInput8() # // // ############################################################################################# // DIRECTINPUT8PLUGIN_API IDirectInput8 *Nuclex::Input::getDirectInput8() { return g_pDirectInput8; } // ############################################################################################# // // # NuclexVersion() # // // ############################################################################################# // /** Retrieve the version number of the nuclex framework the plugin was compiled against @return The framework version against which the plugin was compiled */ extern "C" DIRECTINPUT8PLUGIN_API int nuclexPluginVersion() { return NUCLEX_VERSION; } // ############################################################################################# // // # NuclexRegister() # // // ############################################################################################# // /** Register the plugin to a nuclex kernel instance @param pKernel Kernel to register to */ extern "C" DIRECTINPUT8PLUGIN_API void nuclexPluginRegister(Kernel *pKernel) { HRESULT hResult = getDirectInput8()->EnumDevices( DI8DEVCLASS_ALL, addInputDeviceToKernel, pKernel, 0 ); if(FAILED(hResult)) Kernel::logMessage( Kernel::MT_WARNING, string("Device enumeration failed, cause: ") + DXGetErrorString9A(hResult) ); } // ############################################################################################# // // # NuclexUnregister() # // // ############################################################################################# // /** Unregister the plugin from a nuclex kernel instance @param pKernel Kernel to unregister from */ extern "C" DIRECTINPUT8PLUGIN_API void nuclexPluginUnregister(Kernel *pKernel) { }