template and fixed guid obtaining

This commit is contained in:
Hane 2023-08-11 21:35:48 +02:00
commit 7e741f3bca
3 changed files with 39 additions and 13 deletions

View file

@ -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?
}

View file

@ -2,10 +2,22 @@
#if defined (QT_DEBUG) || defined (DEBUG) || defined (_DEBUG)
template<size_t Y, typename T>
std::bitset<Y> varToBitset(T info) {
std::bitset<Y> 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<len, type>(info)
#else
#define log_debugcpp(str)
#define print_as_binary(len, info)
#endif

View file

@ -3,6 +3,7 @@
#include <vector>
#include <iostream>
#include <string>
#include <bitset>
#include "debug.h"