forked from riverar/IndirectInput
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexports.cpp
63 lines (53 loc) · 1.78 KB
/
exports.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
#include "common.h"
#include "indirectinput.h"
#pragma warning(disable: 4104) // warning LNK4104: export of symbol 'xxx' should be PRIVATE
static DirectInputCreateAFn g_DirectInputCreateA = nullptr;
static DirectInputCreateWFn g_DirectInputCreateW = nullptr;
static IndirectInput* g_IndirectInput = nullptr;
static HMODULE g_DirectInputModule = nullptr;
void InitializeIfNeeded()
{
if (!g_DirectInputModule)
{
wchar_t directInputPath[MAX_PATH] = LR"(%SystemRoot%\System32\DINPUT.DLL)";
ExpandEnvironmentStringsW(directInputPath, directInputPath, MAX_PATH);
g_DirectInputModule = LoadLibraryW(directInputPath);
if (g_DirectInputModule)
{
g_DirectInputCreateA = reinterpret_cast<DirectInputCreateAFn>(GetProcAddress(g_DirectInputModule, "DirectInputCreateA"));
g_DirectInputCreateW = reinterpret_cast<DirectInputCreateWFn>(GetProcAddress(g_DirectInputModule, "DirectInputCreateW"));
}
}
}
HRESULT WINAPI WrappedDirectInputCreateA(HINSTANCE hinst, DWORD dwVersion, LPDIRECTINPUTA *ppDI, LPUNKNOWN punkOuter)
{
InitializeIfNeeded();
auto hr = g_DirectInputCreateA(hinst, dwVersion, ppDI, punkOuter);
if (SUCCEEDED(hr))
{
g_IndirectInput = new IndirectInput(*ppDI);
*ppDI = g_IndirectInput;
}
return hr;
}
HRESULT WINAPI WrappedDirectInputCreateW(HINSTANCE hinst, DWORD dwVersion, LPDIRECTINPUTW *ppDI, LPUNKNOWN punkOuter)
{
InitializeIfNeeded();
return g_DirectInputCreateW(hinst, dwVersion, ppDI, punkOuter);
}
HRESULT WrappedDllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
{
return E_FAIL;
}
HRESULT WrappedDllCanUnloadNow()
{
return S_FALSE;
}
HRESULT WrappedDllRegisterServer()
{
return S_OK;
}
HRESULT WrappedDllUnregisterServer()
{
return S_OK;
}