Skip to content

Commit

Permalink
Added missing namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
nefarius committed Aug 6, 2024
1 parent 9c6605a commit 60c675a
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 45 deletions.
8 changes: 4 additions & 4 deletions src/Devcon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ bool devcon::install_driver(const std::wstring& fullInfPath, bool* rebootRequire
{
el::Logger* logger = el::Loggers::getLogger("default");

Newdev newdev;
nefarius::util::Newdev newdev;
BOOL reboot;

if (!newdev.CallDiInstallDriverW)
Expand Down Expand Up @@ -407,7 +407,7 @@ bool devcon::uninstall_driver(const std::wstring& fullInfPath, bool* rebootRequi
{
el::Logger* logger = el::Loggers::getLogger("default");

Newdev newdev;
nefarius::util::Newdev newdev;
BOOL reboot;

if (!newdev.CallDiUninstallDriverW)
Expand Down Expand Up @@ -669,7 +669,7 @@ inline bool uninstall_device_and_driver(HDEVINFO hDevInfo, PSP_DEVINFO_DATA spDe
DWORD err = ERROR_SUCCESS;
bool ret = false;

Newdev newdev;
nefarius::util::Newdev newdev;

if (!newdev.CallDiUninstallDevice || !newdev.CallDiUninstallDriverW)
{
Expand Down Expand Up @@ -1033,7 +1033,7 @@ bool devcon::inf_default_install(const std::wstring& fullInfPath, bool* rebootRe
}
}

Newdev newdev;
nefarius::util::Newdev newdev;
BOOL reboot = FALSE;

if (!newdev.CallDiInstallDriverW)
Expand Down
85 changes: 44 additions & 41 deletions src/LibraryHelper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,55 @@
#include <newdev.h>
#include <type_traits>

class ProcPtr
namespace nefarius::util
{
public:
explicit ProcPtr(FARPROC ptr) : _ptr(ptr)
class ProcPtr
{
}

template <typename T, typename = std::enable_if_t<std::is_function_v<T>>>
operator T*() const
{
return reinterpret_cast<T*>(_ptr);
}

private:
FARPROC _ptr;
};

class DllHelper
{
public:
explicit DllHelper(LPCTSTR filename) : _module(LoadLibrary(filename))
public:
explicit ProcPtr(FARPROC ptr) : _ptr(ptr)
{
}

template <typename T, typename = std::enable_if_t<std::is_function_v<T>>>
operator T*() const
{
return reinterpret_cast<T*>(_ptr);
}

private:
FARPROC _ptr;
};

class DllHelper
{
}
public:
explicit DllHelper(LPCTSTR filename) : _module(LoadLibrary(filename))
{
}

~DllHelper() { FreeLibrary(_module); }
~DllHelper() { FreeLibrary(_module); }

ProcPtr operator[](LPCSTR proc_name) const
{
return ProcPtr(GetProcAddress(_module, proc_name));
}
ProcPtr operator[](LPCSTR proc_name) const
{
return ProcPtr(GetProcAddress(_module, proc_name));
}

static HMODULE _parent_module;
static HMODULE _parent_module;

private:
HMODULE _module;
};
private:
HMODULE _module;
};

class Newdev
{
private:
DllHelper _dll{L"Newdev.dll"};

public:
decltype(DiUninstallDriverW)* CallDiUninstallDriverW = _dll["DiUninstallDriverW"];
decltype(DiInstallDriverW)* CallDiInstallDriverW = _dll["DiInstallDriverW"];
decltype(DiUninstallDevice)* CallDiUninstallDevice = _dll["DiUninstallDevice"];
decltype(UpdateDriverForPlugAndPlayDevicesW)* CallUpdateDriverForPlugAndPlayDevicesW = _dll[
"UpdateDriverForPlugAndPlayDevicesW"];
};
class Newdev
{
private:
DllHelper _dll{L"Newdev.dll"};

public:
decltype(DiUninstallDriverW)* CallDiUninstallDriverW = _dll["DiUninstallDriverW"];
decltype(DiInstallDriverW)* CallDiInstallDriverW = _dll["DiInstallDriverW"];
decltype(DiUninstallDevice)* CallDiUninstallDevice = _dll["DiUninstallDevice"];
decltype(UpdateDriverForPlugAndPlayDevicesW)* CallUpdateDriverForPlugAndPlayDevicesW = _dll[
"UpdateDriverForPlugAndPlayDevicesW"];
};
}

0 comments on commit 60c675a

Please sign in to comment.