mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
Add CWindowsComLifecycle
RAII wrapper for Windows COM library
This commit is contained in:
parent
4fc6a5b924
commit
37cadc5c09
|
@ -65,6 +65,7 @@
|
|||
|
||||
#include <cerrno>
|
||||
#include <io.h>
|
||||
#include <objbase.h>
|
||||
#include <process.h>
|
||||
#include <share.h>
|
||||
#include <shellapi.h>
|
||||
|
@ -4199,6 +4200,17 @@ int net_socket_read_wait(NETSOCKET sock, std::chrono::nanoseconds nanoseconds)
|
|||
return ::net_socket_read_wait(sock, (nanoseconds / std::chrono::nanoseconds(1us).count()).count());
|
||||
}
|
||||
|
||||
#if defined(CONF_FAMILY_WINDOWS)
|
||||
CWindowsComLifecycle::CWindowsComLifecycle()
|
||||
{
|
||||
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
|
||||
}
|
||||
CWindowsComLifecycle::~CWindowsComLifecycle()
|
||||
{
|
||||
CoUninitialize();
|
||||
}
|
||||
#endif
|
||||
|
||||
size_t std::hash<NETADDR>::operator()(const NETADDR &Addr) const noexcept
|
||||
{
|
||||
return std::hash<std::string_view>{}(std::string_view((const char *)&Addr, sizeof(Addr)));
|
||||
|
|
|
@ -2515,6 +2515,19 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
#if defined(CONF_FAMILY_WINDOWS)
|
||||
/**
|
||||
* This is a RAII wrapper to initialize/uninitialize the Windows COM library,
|
||||
* which may be necessary for using the open_file and open_link functions.
|
||||
*/
|
||||
class CWindowsComLifecycle
|
||||
{
|
||||
public:
|
||||
CWindowsComLifecycle();
|
||||
~CWindowsComLifecycle();
|
||||
};
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Copies a string to a fixed-size array of chars.
|
||||
*
|
||||
|
|
|
@ -4561,6 +4561,8 @@ int main(int argc, const char **argv)
|
|||
{
|
||||
#if defined(CONF_PLATFORM_ANDROID)
|
||||
const char **argv = const_cast<const char **>(argv2);
|
||||
#elif defined(CONF_FAMILY_WINDOWS)
|
||||
CWindowsComLifecycle WindowsComLifecycle;
|
||||
#endif
|
||||
CCmdlineFix CmdlineFix(&argc, &argv);
|
||||
bool Silent = false;
|
||||
|
|
Loading…
Reference in a new issue