Skip to content

Commit 5075809

Browse files
committed
v1.1 Released. Fixed process stuck on Windows 10, addes error dialog if there is no driver installed
1 parent 46b2fdb commit 5075809

2 files changed

Lines changed: 36 additions & 20 deletions

File tree

XBoxOff.rc

0 Bytes
Binary file not shown.

main.cpp

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
2-
* Copyright (c) 2013, Ighor July, julyighor@gmail.com
2+
* Copyright (c) 2019, Ighor July, julyighor@gmail.com
3+
* https://github.com/JulyIghor/TurnOffXboxController
34
* Donate Bitcoin 1PswUbmymM22Xx7qi7xuMwRKyTc7sf62Zb
45
* All rights reserved.
56
@@ -34,23 +35,38 @@
3435

3536
#pragma comment(lib, "XInput.lib")
3637

37-
int main(int argc, char *argv[])
38+
int main(void)
3839
{
39-
HINSTANCE hXInputDLL = LoadLibraryA("XInput1_3.dll");
40-
if (hXInputDLL == NULL)return 1;
41-
42-
for(short i=0; i<4; ++i)
43-
{
44-
XINPUT_STATE state;
45-
memset(&state, 0, sizeof(XINPUT_STATE));
46-
if(XInputGetState(i,&state)==ERROR_SUCCESS)
47-
{
48-
typedef DWORD (WINAPI* XInputPowerOffController_t)(DWORD i);
49-
XInputPowerOffController_t realXInputPowerOffController=(XInputPowerOffController_t) GetProcAddress(hXInputDLL, (LPCSTR) 103);
50-
realXInputPowerOffController(i);
51-
}
52-
ZeroMemory(&state, sizeof(XINPUT_STATE));
53-
}
54-
FreeLibrary(hXInputDLL);
55-
return 0;
56-
}
40+
HINSTANCE hXInputDLL = LoadLibraryA("XInput1_3.dll");
41+
42+
if (hXInputDLL == NULL)
43+
{
44+
MessageBox(NULL, "Xbox 360 controller driver not found\n\n"
45+
"If your controller is not 360 model, just hold X button to turn it off", "Turn off Xbox 360 controller ",
46+
MB_OK);
47+
return 1;
48+
}
49+
50+
for (short i = 0; i < 4; ++i)
51+
{
52+
XINPUT_STATE state;
53+
memset(&state, 0, sizeof(XINPUT_STATE));
54+
55+
if (XInputGetState(i, &state) == ERROR_SUCCESS)
56+
{
57+
typedef DWORD(WINAPI * XInputPowerOffController_t)(DWORD i);
58+
XInputPowerOffController_t realXInputPowerOffController = (XInputPowerOffController_t)GetProcAddress(hXInputDLL, (LPCSTR)103);
59+
realXInputPowerOffController(i);
60+
}
61+
62+
ZeroMemory(&state, sizeof(XINPUT_STATE));
63+
}
64+
65+
FreeLibrary(hXInputDLL);
66+
67+
//Killing own process since XInput1_3.dll threads stuck and won't exit on Windows 10
68+
//If you know another way to fix it, feel free to send commit here https://github.com/JulyIghor/TurnOffXboxController
69+
TerminateProcess(OpenProcess(SYNCHRONIZE | PROCESS_TERMINATE, TRUE, GetCurrentProcessId()), 0);
70+
71+
return 0;
72+
}

0 commit comments

Comments
 (0)