File: dll.cpp

package info (click to toggle)
libfilezilla 0.52.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,492 kB
  • sloc: cpp: 30,965; sh: 4,241; makefile: 375; xml: 37
file content (54 lines) | stat: -rw-r--r-- 875 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "../libfilezilla/glue/dll.hpp"

#include <objbase.h>

namespace fz {
namespace {
extern "C" {
typedef HRESULT (STDAPICALLTYPE *coinitex_t)(LPVOID, DWORD);
typedef HRESULT (STDAPICALLTYPE *couninit_t)();
}
}

dll::dll(dll && d)
{
	h_ = d.h_;
	d.h_ = nullptr;
}

dll& dll::operator=(dll && d)
{
	if (&d != this) {
		if (h_) {
			FreeLibrary(h_);
		}
		h_ = d.h_;
		d.h_ = nullptr;
	}
	return *this;
}

shdlls::shdlls()
	: shell32_(L"shell32.dll", LOAD_LIBRARY_SEARCH_SYSTEM32)
	, ole32_(L"ole32.dll", LOAD_LIBRARY_SEARCH_SYSTEM32)
{
	auto const coinitex = reinterpret_cast<coinitex_t>(ole32_["CoInitializeEx"]);
	if (coinitex) {
		coinitex(NULL, COINIT_MULTITHREADED);
	}
}

shdlls::~shdlls()
{
	auto const couninit = reinterpret_cast<couninit_t>(ole32_["CoUninitialize"]);
	if (couninit) {
		couninit();
	}
}

shdlls& shdlls::get()
{
	static shdlls d;
	return d;
}
}