MCPcopy Create free account
hub / github.com/BYVoid/OpenCC / GetCurrentLibraryDirectory

Function GetCurrentLibraryDirectory

src/PluginSegmentation.cpp:128–149  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

126using internal::WideFromUtf8;
127
128std::string GetCurrentLibraryDirectory() {
129 HMODULE module = nullptr;
130 if (!GetModuleHandleExW(
131 GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
132 GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
133 reinterpret_cast<LPCWSTR>(&GetCurrentLibraryDirectory), &module)) {
134 return "";
135 }
136 std::wstring buffer(MAX_PATH, L'\0');
137 for (;;) {
138 const DWORD copied = GetModuleFileNameW(module, buffer.data(),
139 static_cast<DWORD>(buffer.size()));
140 if (copied == 0) {
141 return "";
142 }
143 if (copied < buffer.size() - 1) {
144 buffer.resize(copied);
145 return DirName(Utf8FromWide(buffer));
146 }
147 buffer.resize(buffer.size() * 2);
148 }
149}
150#else
151std::string GetCurrentLibraryDirectory() {
152 Dl_info info;

Callers 1

BuildSearchDirsMethod · 0.85

Calls 5

DirNameFunction · 0.85
Utf8FromWideFunction · 0.85
dataMethod · 0.45
sizeMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected