-
Notifications
You must be signed in to change notification settings - Fork 3
/
XInput.cpp
67 lines (55 loc) · 1.43 KB
/
XInput.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "nil.h"
#include "nilUtil.h"
#include "nilWindows.h"
# define NIL_LOAD_EXTERNAL_FUNC(x) mFunctions.pfn##x##=(fn##x##)GetProcAddress(mModule,#x)
namespace Nil {
XInput::Functions::Functions(): pfnXInputGetState( nullptr ),
pfnXInputSetState( nullptr ), pfnXInputGetCapabilities( nullptr )
{
}
XInput::XInput(): mVersion( Version_None )
{
}
XInput::InitReturn XInput::initialize()
{
mModule = LoadLibraryW( L"xinput1_4.dll" );
if ( mModule )
mVersion = Version_14;
else
{
mModule = LoadLibraryW( L"xinput1_3.dll" );
if ( mModule )
mVersion = Version_13;
else
{
mModule = LoadLibraryW( L"xinput9_1_0.dll" );
if ( mModule )
mVersion = Version_910;
else
return Initialization_ModuleNotFound;
}
}
NIL_LOAD_EXTERNAL_FUNC( XInputGetState );
NIL_LOAD_EXTERNAL_FUNC( XInputSetState );
NIL_LOAD_EXTERNAL_FUNC( XInputGetCapabilities );
if ( !mFunctions.pfnXInputGetState
|| !mFunctions.pfnXInputSetState
|| !mFunctions.pfnXInputGetCapabilities )
return Initialization_MissingExports;
mInitialized = true;
return Initialization_OK;
}
void XInput::shutdown()
{
if ( mModule )
{
FreeLibrary( mModule );
mModule = NULL;
}
mInitialized = false;
}
XInput::~XInput()
{
shutdown();
}
}