From 7d8a5248f01c2b77a7d99f939b312262a5727239 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20H=C3=B6glinger-Stelzer?= Date: Tue, 16 Apr 2019 18:10:50 +0200 Subject: [PATCH] Added tester console application Typo fixes Fixed a bug where bus handle wasn't checked correctly --- ViGEmClient.sln | 51 +++++++++ app/Tester/Tester.cpp | 47 ++++++++ app/Tester/Tester.vcxproj | 176 ++++++++++++++++++++++++++++++ app/Tester/Tester.vcxproj.filters | 22 ++++ src/ViGEmClient.cpp | 49 +++++---- 5 files changed, 325 insertions(+), 20 deletions(-) create mode 100644 app/Tester/Tester.cpp create mode 100644 app/Tester/Tester.vcxproj create mode 100644 app/Tester/Tester.vcxproj.filters diff --git a/ViGEmClient.sln b/ViGEmClient.sln index 44670ff..acd5cb8 100644 --- a/ViGEmClient.sln +++ b/ViGEmClient.sln @@ -7,16 +7,24 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ViGEmClient", "src\ViGEmCli EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "_build", "build\_build.csproj", "{A11CD588-F74A-41B5-9E5B-E60937052009}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "App", "App", "{8169FFB3-60F9-4A0C-B172-8E26B982B45F}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Tester", "app\Tester\Tester.vcxproj", "{2F4ED0AB-0B51-4506-91AA-1984C5D44B85}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug_DLL|x64 = Debug_DLL|x64 Debug_DLL|x86 = Debug_DLL|x86 Debug_LIB|x64 = Debug_LIB|x64 Debug_LIB|x86 = Debug_LIB|x86 + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 Release_DLL|x64 = Release_DLL|x64 Release_DLL|x86 = Release_DLL|x86 Release_LIB|x64 = Release_LIB|x64 Release_LIB|x86 = Release_LIB|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {7DB06674-1F4F-464B-8E1C-172E9587F9DC}.Debug_DLL|x64.ActiveCfg = Debug_DLL|x64 @@ -27,6 +35,10 @@ Global {7DB06674-1F4F-464B-8E1C-172E9587F9DC}.Debug_LIB|x64.Build.0 = Debug_LIB|x64 {7DB06674-1F4F-464B-8E1C-172E9587F9DC}.Debug_LIB|x86.ActiveCfg = Debug_LIB|Win32 {7DB06674-1F4F-464B-8E1C-172E9587F9DC}.Debug_LIB|x86.Build.0 = Debug_LIB|Win32 + {7DB06674-1F4F-464B-8E1C-172E9587F9DC}.Debug|x64.ActiveCfg = Debug_LIB|x64 + {7DB06674-1F4F-464B-8E1C-172E9587F9DC}.Debug|x64.Build.0 = Debug_LIB|x64 + {7DB06674-1F4F-464B-8E1C-172E9587F9DC}.Debug|x86.ActiveCfg = Debug_LIB|Win32 + {7DB06674-1F4F-464B-8E1C-172E9587F9DC}.Debug|x86.Build.0 = Debug_LIB|Win32 {7DB06674-1F4F-464B-8E1C-172E9587F9DC}.Release_DLL|x64.ActiveCfg = Release_DLL|x64 {7DB06674-1F4F-464B-8E1C-172E9587F9DC}.Release_DLL|x64.Build.0 = Release_DLL|x64 {7DB06674-1F4F-464B-8E1C-172E9587F9DC}.Release_DLL|x86.ActiveCfg = Release_DLL|Win32 @@ -35,6 +47,10 @@ Global {7DB06674-1F4F-464B-8E1C-172E9587F9DC}.Release_LIB|x64.Build.0 = Release_LIB|x64 {7DB06674-1F4F-464B-8E1C-172E9587F9DC}.Release_LIB|x86.ActiveCfg = Release_LIB|Win32 {7DB06674-1F4F-464B-8E1C-172E9587F9DC}.Release_LIB|x86.Build.0 = Release_LIB|Win32 + {7DB06674-1F4F-464B-8E1C-172E9587F9DC}.Release|x64.ActiveCfg = Release_LIB|x64 + {7DB06674-1F4F-464B-8E1C-172E9587F9DC}.Release|x64.Build.0 = Release_LIB|x64 + {7DB06674-1F4F-464B-8E1C-172E9587F9DC}.Release|x86.ActiveCfg = Release_LIB|Win32 + {7DB06674-1F4F-464B-8E1C-172E9587F9DC}.Release|x86.Build.0 = Release_LIB|Win32 {A11CD588-F74A-41B5-9E5B-E60937052009}.Debug_DLL|x64.ActiveCfg = Debug|Any CPU {A11CD588-F74A-41B5-9E5B-E60937052009}.Debug_DLL|x64.Build.0 = Debug|Any CPU {A11CD588-F74A-41B5-9E5B-E60937052009}.Debug_DLL|x86.ActiveCfg = Debug|Any CPU @@ -43,6 +59,10 @@ Global {A11CD588-F74A-41B5-9E5B-E60937052009}.Debug_LIB|x64.Build.0 = Debug|Any CPU {A11CD588-F74A-41B5-9E5B-E60937052009}.Debug_LIB|x86.ActiveCfg = Debug|Any CPU {A11CD588-F74A-41B5-9E5B-E60937052009}.Debug_LIB|x86.Build.0 = Debug|Any CPU + {A11CD588-F74A-41B5-9E5B-E60937052009}.Debug|x64.ActiveCfg = Debug|Any CPU + {A11CD588-F74A-41B5-9E5B-E60937052009}.Debug|x64.Build.0 = Debug|Any CPU + {A11CD588-F74A-41B5-9E5B-E60937052009}.Debug|x86.ActiveCfg = Debug|Any CPU + {A11CD588-F74A-41B5-9E5B-E60937052009}.Debug|x86.Build.0 = Debug|Any CPU {A11CD588-F74A-41B5-9E5B-E60937052009}.Release_DLL|x64.ActiveCfg = Release|Any CPU {A11CD588-F74A-41B5-9E5B-E60937052009}.Release_DLL|x64.Build.0 = Release|Any CPU {A11CD588-F74A-41B5-9E5B-E60937052009}.Release_DLL|x86.ActiveCfg = Release|Any CPU @@ -51,10 +71,41 @@ Global {A11CD588-F74A-41B5-9E5B-E60937052009}.Release_LIB|x64.Build.0 = Release|Any CPU {A11CD588-F74A-41B5-9E5B-E60937052009}.Release_LIB|x86.ActiveCfg = Release|Any CPU {A11CD588-F74A-41B5-9E5B-E60937052009}.Release_LIB|x86.Build.0 = Release|Any CPU + {A11CD588-F74A-41B5-9E5B-E60937052009}.Release|x64.ActiveCfg = Release|Any CPU + {A11CD588-F74A-41B5-9E5B-E60937052009}.Release|x64.Build.0 = Release|Any CPU + {A11CD588-F74A-41B5-9E5B-E60937052009}.Release|x86.ActiveCfg = Release|Any CPU + {A11CD588-F74A-41B5-9E5B-E60937052009}.Release|x86.Build.0 = Release|Any CPU + {2F4ED0AB-0B51-4506-91AA-1984C5D44B85}.Debug_DLL|x64.ActiveCfg = Debug|x64 + {2F4ED0AB-0B51-4506-91AA-1984C5D44B85}.Debug_DLL|x64.Build.0 = Debug|x64 + {2F4ED0AB-0B51-4506-91AA-1984C5D44B85}.Debug_DLL|x86.ActiveCfg = Debug|Win32 + {2F4ED0AB-0B51-4506-91AA-1984C5D44B85}.Debug_DLL|x86.Build.0 = Debug|Win32 + {2F4ED0AB-0B51-4506-91AA-1984C5D44B85}.Debug_LIB|x64.ActiveCfg = Debug|x64 + {2F4ED0AB-0B51-4506-91AA-1984C5D44B85}.Debug_LIB|x64.Build.0 = Debug|x64 + {2F4ED0AB-0B51-4506-91AA-1984C5D44B85}.Debug_LIB|x86.ActiveCfg = Debug|Win32 + {2F4ED0AB-0B51-4506-91AA-1984C5D44B85}.Debug_LIB|x86.Build.0 = Debug|Win32 + {2F4ED0AB-0B51-4506-91AA-1984C5D44B85}.Debug|x64.ActiveCfg = Debug|x64 + {2F4ED0AB-0B51-4506-91AA-1984C5D44B85}.Debug|x64.Build.0 = Debug|x64 + {2F4ED0AB-0B51-4506-91AA-1984C5D44B85}.Debug|x86.ActiveCfg = Debug|Win32 + {2F4ED0AB-0B51-4506-91AA-1984C5D44B85}.Debug|x86.Build.0 = Debug|Win32 + {2F4ED0AB-0B51-4506-91AA-1984C5D44B85}.Release_DLL|x64.ActiveCfg = Release|x64 + {2F4ED0AB-0B51-4506-91AA-1984C5D44B85}.Release_DLL|x64.Build.0 = Release|x64 + {2F4ED0AB-0B51-4506-91AA-1984C5D44B85}.Release_DLL|x86.ActiveCfg = Release|Win32 + {2F4ED0AB-0B51-4506-91AA-1984C5D44B85}.Release_DLL|x86.Build.0 = Release|Win32 + {2F4ED0AB-0B51-4506-91AA-1984C5D44B85}.Release_LIB|x64.ActiveCfg = Release|x64 + {2F4ED0AB-0B51-4506-91AA-1984C5D44B85}.Release_LIB|x64.Build.0 = Release|x64 + {2F4ED0AB-0B51-4506-91AA-1984C5D44B85}.Release_LIB|x86.ActiveCfg = Release|Win32 + {2F4ED0AB-0B51-4506-91AA-1984C5D44B85}.Release_LIB|x86.Build.0 = Release|Win32 + {2F4ED0AB-0B51-4506-91AA-1984C5D44B85}.Release|x64.ActiveCfg = Release|x64 + {2F4ED0AB-0B51-4506-91AA-1984C5D44B85}.Release|x64.Build.0 = Release|x64 + {2F4ED0AB-0B51-4506-91AA-1984C5D44B85}.Release|x86.ActiveCfg = Release|Win32 + {2F4ED0AB-0B51-4506-91AA-1984C5D44B85}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {2F4ED0AB-0B51-4506-91AA-1984C5D44B85} = {8169FFB3-60F9-4A0C-B172-8E26B982B45F} + EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {D5CD61FD-80BB-4E0E-840C-BAF66ABB1CF0} EndGlobalSection diff --git a/app/Tester/Tester.cpp b/app/Tester/Tester.cpp new file mode 100644 index 0000000..f47ab34 --- /dev/null +++ b/app/Tester/Tester.cpp @@ -0,0 +1,47 @@ +// Tester.cpp : This file contains the 'main' function. Program execution begins and ends there. +// + +#define WIN32_LEAN_AND_MEAN +#include +#include + +#include + +VOID CALLBACK notification( + PVIGEM_CLIENT Client, + PVIGEM_TARGET Target, + UCHAR LargeMotor, + UCHAR SmallMotor, + UCHAR LedNumber +) +{ + std::cout << LargeMotor << " " << SmallMotor << std::endl; +} + +int main() +{ + const auto client = vigem_alloc(); + + const auto x360 = vigem_target_x360_alloc(); + + auto ret = vigem_target_add(client, x360); + + ret = vigem_target_x360_register_notification(client, x360, ¬ification); + + getchar(); + + vigem_target_remove(client, x360); + vigem_target_free(x360); + vigem_free(client); +} + +// Run program: Ctrl + F5 or Debug > Start Without Debugging menu +// Debug program: F5 or Debug > Start Debugging menu + +// Tips for Getting Started: +// 1. Use the Solution Explorer window to add/manage files +// 2. Use the Team Explorer window to connect to source control +// 3. Use the Output window to see build output and other messages +// 4. Use the Error List window to view errors +// 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project +// 6. In the future, to open this project again, go to File > Open > Project and select the .sln file diff --git a/app/Tester/Tester.vcxproj b/app/Tester/Tester.vcxproj new file mode 100644 index 0000000..045ec6d --- /dev/null +++ b/app/Tester/Tester.vcxproj @@ -0,0 +1,176 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {2F4ED0AB-0B51-4506-91AA-1984C5D44B85} + Win32Proj + Tester + 10.0.17763.0 + + + + Application + true + v141 + Unicode + + + Application + false + v141 + true + Unicode + + + Application + true + v141 + Unicode + + + Application + false + v141 + true + Unicode + + + + + + + + + + + + + + + + + + + + + false + $(SolutionDir)include;$(VC_IncludePath);$(WindowsSDK_IncludePath); + + + true + $(SolutionDir)include;$(VC_IncludePath);$(WindowsSDK_IncludePath); + + + true + $(SolutionDir)include;$(VC_IncludePath);$(WindowsSDK_IncludePath); + + + false + $(SolutionDir)include;$(VC_IncludePath);$(WindowsSDK_IncludePath); + + + + + + Level3 + MaxSpeed + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + MultiThreaded + + + Console + true + true + true + setupapi.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + + + + + + + Level3 + Disabled + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + MultiThreadedDebug + + + Console + true + setupapi.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + + + + + + + Level3 + Disabled + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + MultiThreadedDebug + + + Console + true + setupapi.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + + + + + + + Level3 + MaxSpeed + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + MultiThreaded + + + Console + true + true + true + setupapi.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + + + + + + + + {7db06674-1f4f-464b-8e1c-172e9587f9dc} + + + + + + \ No newline at end of file diff --git a/app/Tester/Tester.vcxproj.filters b/app/Tester/Tester.vcxproj.filters new file mode 100644 index 0000000..87da40a --- /dev/null +++ b/app/Tester/Tester.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + \ No newline at end of file diff --git a/src/ViGEmClient.cpp b/src/ViGEmClient.cpp index 1ad6c69..fc9149c 100644 --- a/src/ViGEmClient.cpp +++ b/src/ViGEmClient.cpp @@ -418,7 +418,7 @@ VIGEM_ERROR vigem_target_add(PVIGEM_CLIENT vigem, PVIGEM_TARGET target) if (!target) return VIGEM_ERROR_INVALID_TARGET; - if (vigem->hBusDevice == nullptr) + if (vigem->hBusDevice == INVALID_HANDLE_VALUE) return VIGEM_ERROR_BUS_NOT_FOUND; if (target->State == VIGEM_TARGET_NEW) @@ -472,7 +472,7 @@ VIGEM_ERROR vigem_target_add_async(PVIGEM_CLIENT vigem, PVIGEM_TARGET target, PF if (!target) return VIGEM_ERROR_INVALID_TARGET; - if (vigem->hBusDevice == nullptr) + if (vigem->hBusDevice == INVALID_HANDLE_VALUE) return VIGEM_ERROR_BUS_NOT_FOUND; if (target->State == VIGEM_TARGET_NEW) @@ -486,7 +486,7 @@ VIGEM_ERROR vigem_target_add_async(PVIGEM_CLIENT vigem, PVIGEM_TARGET target, PF PVIGEM_CLIENT _Client, PFN_VIGEM_TARGET_ADD_RESULT _Result) { - DWORD transfered = 0; + DWORD transferred = 0; VIGEM_PLUGIN_TARGET plugin; OVERLAPPED lOverlapped = { 0 }; lOverlapped.hEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr); @@ -498,9 +498,18 @@ VIGEM_ERROR vigem_target_add_async(PVIGEM_CLIENT vigem, PVIGEM_TARGET target, PF plugin.VendorId = _Target->VendorId; plugin.ProductId = _Target->ProductId; - DeviceIoControl(_Client->hBusDevice, IOCTL_VIGEM_PLUGIN_TARGET, &plugin, plugin.Size, nullptr, 0, &transfered, &lOverlapped); + DeviceIoControl( + _Client->hBusDevice, + IOCTL_VIGEM_PLUGIN_TARGET, + &plugin, + plugin.Size, + nullptr, + 0, + &transferred, + &lOverlapped + ); - if (GetOverlappedResult(_Client->hBusDevice, &lOverlapped, &transfered, TRUE) != 0) + if (GetOverlappedResult(_Client->hBusDevice, &lOverlapped, &transferred, TRUE) != 0) { _Target->State = VIGEM_TARGET_CONNECTED; CloseHandle(lOverlapped.hEvent); @@ -532,7 +541,7 @@ VIGEM_ERROR vigem_target_remove(PVIGEM_CLIENT vigem, PVIGEM_TARGET target) if (!target) return VIGEM_ERROR_INVALID_TARGET; - if (vigem->hBusDevice == nullptr) + if (vigem->hBusDevice == INVALID_HANDLE_VALUE) return VIGEM_ERROR_BUS_NOT_FOUND; if (target->State == VIGEM_TARGET_NEW) @@ -584,7 +593,7 @@ VIGEM_ERROR vigem_target_x360_register_notification( if (!target) return VIGEM_ERROR_INVALID_TARGET; - if (vigem->hBusDevice == nullptr) + if (vigem->hBusDevice == INVALID_HANDLE_VALUE) return VIGEM_ERROR_BUS_NOT_FOUND; if (target->SerialNo == 0 || notification == nullptr) @@ -613,7 +622,7 @@ VIGEM_ERROR vigem_target_ds4_register_notification( if (!target) return VIGEM_ERROR_INVALID_TARGET; - if (vigem->hBusDevice == nullptr) + if (vigem->hBusDevice == INVALID_HANDLE_VALUE) return VIGEM_ERROR_BUS_NOT_FOUND; if (target->SerialNo == 0 || notification == nullptr) @@ -726,13 +735,13 @@ VIGEM_ERROR vigem_target_x360_update( if (!target) return VIGEM_ERROR_INVALID_TARGET; - if (vigem->hBusDevice == nullptr) + if (vigem->hBusDevice == INVALID_HANDLE_VALUE) return VIGEM_ERROR_BUS_NOT_FOUND; if (target->SerialNo == 0) return VIGEM_ERROR_INVALID_TARGET; - DWORD transfered = 0; + DWORD transferred = 0; OVERLAPPED lOverlapped = { 0 }; lOverlapped.hEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr); @@ -748,11 +757,11 @@ VIGEM_ERROR vigem_target_x360_update( xsr.Size, nullptr, 0, - &transfered, + &transferred, &lOverlapped ); - if (GetOverlappedResult(vigem->hBusDevice, &lOverlapped, &transfered, TRUE) == 0) + if (GetOverlappedResult(vigem->hBusDevice, &lOverlapped, &transferred, TRUE) == 0) { if (GetLastError() == ERROR_ACCESS_DENIED) { @@ -778,13 +787,13 @@ VIGEM_ERROR vigem_target_ds4_update( if (!target) return VIGEM_ERROR_INVALID_TARGET; - if (vigem->hBusDevice == nullptr) + if (vigem->hBusDevice == INVALID_HANDLE_VALUE) return VIGEM_ERROR_BUS_NOT_FOUND; if (target->SerialNo == 0) return VIGEM_ERROR_INVALID_TARGET; - DWORD transfered = 0; + DWORD transferred = 0; OVERLAPPED lOverlapped = { 0 }; lOverlapped.hEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr); @@ -800,11 +809,11 @@ VIGEM_ERROR vigem_target_ds4_update( dsr.Size, nullptr, 0, - &transfered, + &transferred, &lOverlapped ); - if (GetOverlappedResult(vigem->hBusDevice, &lOverlapped, &transfered, TRUE) == 0) + if (GetOverlappedResult(vigem->hBusDevice, &lOverlapped, &transferred, TRUE) == 0) { if (GetLastError() == ERROR_ACCESS_DENIED) { @@ -845,13 +854,13 @@ VIGEM_ERROR vigem_target_x360_get_user_index( if (!target) return VIGEM_ERROR_INVALID_TARGET; - if (vigem->hBusDevice == nullptr) + if (vigem->hBusDevice == INVALID_HANDLE_VALUE) return VIGEM_ERROR_BUS_NOT_FOUND; if (target->SerialNo == 0 || target->Type != Xbox360Wired) return VIGEM_ERROR_INVALID_TARGET; - DWORD transfered = 0; + DWORD transferred = 0; OVERLAPPED lOverlapped = { 0 }; lOverlapped.hEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr); @@ -865,11 +874,11 @@ VIGEM_ERROR vigem_target_x360_get_user_index( gui.Size, &gui, gui.Size, - &transfered, + &transferred, &lOverlapped ); - if (GetOverlappedResult(vigem->hBusDevice, &lOverlapped, &transfered, TRUE) == 0) + if (GetOverlappedResult(vigem->hBusDevice, &lOverlapped, &transferred, TRUE) == 0) { const auto error = GetLastError();