From 44461afdc4e36880cdc3d5bbb2d23231a42b0260 Mon Sep 17 00:00:00 2001 From: Hane Date: Fri, 11 Aug 2023 21:35:48 +0200 Subject: [PATCH] template and fixed guid obtaining --- src/back/backlasses.cpp | 37 +++++++++++++++++++++++++------------ src/debug.h | 14 +++++++++++++- src/global.h | 1 + 3 files changed, 39 insertions(+), 13 deletions(-) diff --git a/src/back/backlasses.cpp b/src/back/backlasses.cpp index 1cf1006..1a6f463 100644 --- a/src/back/backlasses.cpp +++ b/src/back/backlasses.cpp @@ -144,7 +144,8 @@ Endpoint::~Endpoint(){ void Overseer::initCOMLibrary(){ - if(FAILED(CoInitializeEx(NULL, COINIT_APARTMENTTHREADED))) { log_debugcpp("si"); }; + if(FAILED(CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE))) { + log_debugcpp("si"); }; //Retrieving endpoint enumerator @@ -154,17 +155,29 @@ void Overseer::initCOMLibrary(){ (void**)&deviceEnumerator)) ) { log_debugcpp("si"); }; - /* - * LPGUID tempGuid = nullptr; - * if(FAILED(CoCreateGuid(tempGuid))) { log_debugcpp("Failed to obtain GUID"); }; - * - * this->guid.data1 = tempGuid->Data1; - * this->guid.data2 = tempGuid->Data2; - * this->guid.data3 = tempGuid->Data3; - * for (int i = 0; i < 8; i++){ - * this->guid.data4[i] = tempGuid->Data4[i]; - * } - */ + + GUID tempGuid; + /* + * HRESULT her = CoCreateGuid(&tempGuid); + * std::bitset<32> bon(her); + * //if (hr == EPT_S_CANT_CREATE) + * log_debugcpp("Failed to obtain GUID: " /\*<< std::hex *\/<< her << std::dec << " " << bon); + */ + if(FAILED(CoCreateGuid(&tempGuid))) { log_debugcpp("Failed to obtain GUID: " ); }; + + + this->guid.data1 = tempGuid.Data1; + this->guid.data2 = tempGuid.Data2; + this->guid.data3 = tempGuid.Data3; + for (int i = 0; i < 8; i++){ + this->guid.data4[i] = tempGuid.Data4[i]; + log_debugcpp("GUID DATA4 BYTE " << i << ": "); + log_debugcpp(print_as_binary(8, uint32_t, this->guid.data4[i])); + } + log_debugcpp("GUID DATA1: " << this->guid.data1); + log_debugcpp("GUID DATA2: " << this->guid.data2); + log_debugcpp("GUID DATA3: " << this->guid.data3); + //TODO: Release lpguid? } diff --git a/src/debug.h b/src/debug.h index 6e4baa8..78cb19c 100644 --- a/src/debug.h +++ b/src/debug.h @@ -2,10 +2,22 @@ #if defined (QT_DEBUG) || defined (DEBUG) || defined (_DEBUG) +template +std::bitset varToBitset(T info) { + std::bitset content(info); + return content; +} + #define log_debugcpp(str) do { \ std::cout << "[DEBUG]" << "(" << __FILE__ << ":" << __LINE__ << "): " << str << std::endl; \ } while (0) + +#define print_as_binary(len, type, info) varToBitset(info) + #else -#define log_debugcpp(str) +#define log_debugcpp(str) +#define print_as_binary(len, info) #endif + + diff --git a/src/global.h b/src/global.h index 6b949b6..eaf2968 100644 --- a/src/global.h +++ b/src/global.h @@ -3,6 +3,7 @@ #include #include #include +#include #include "debug.h"