obs-windows.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  1. /******************************************************************************
  2. Copyright (C) 2013 by Hugh Bailey <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ******************************************************************************/
  14. #include "util/windows/win-version.h"
  15. #include "util/platform.h"
  16. #include "util/dstr.h"
  17. #include "obs.h"
  18. #include "obs-internal.h"
  19. #include <windows.h>
  20. static uint32_t win_ver = 0;
  21. const char *get_module_extension(void)
  22. {
  23. return ".dll";
  24. }
  25. #ifdef _WIN64
  26. #define BIT_STRING "64bit"
  27. #else
  28. #define BIT_STRING "32bit"
  29. #endif
  30. static const char *module_bin[] = {
  31. "obs-plugins/" BIT_STRING,
  32. "../../obs-plugins/" BIT_STRING,
  33. };
  34. static const char *module_data[] = {
  35. "data/%module%",
  36. "../../data/obs-plugins/%module%"
  37. };
  38. static const int module_patterns_size =
  39. sizeof(module_bin)/sizeof(module_bin[0]);
  40. void add_default_module_paths(void)
  41. {
  42. for (int i = 0; i < module_patterns_size; i++)
  43. obs_add_module_path(module_bin[i], module_data[i]);
  44. }
  45. /* on windows, points to [base directory]/data/libobs */
  46. char *find_libobs_data_file(const char *file)
  47. {
  48. struct dstr path;
  49. dstr_init(&path);
  50. if (check_path(file, "data/libobs/", &path))
  51. return path.array;
  52. if (check_path(file, "../../data/libobs/", &path))
  53. return path.array;
  54. dstr_free(&path);
  55. return NULL;
  56. }
  57. static void log_processor_info(void)
  58. {
  59. HKEY key;
  60. wchar_t data[1024];
  61. char *str = NULL;
  62. DWORD size, speed;
  63. LSTATUS status;
  64. memset(data, 0, 1024);
  65. status = RegOpenKeyW(HKEY_LOCAL_MACHINE,
  66. L"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0",
  67. &key);
  68. if (status != ERROR_SUCCESS)
  69. return;
  70. size = 1024;
  71. status = RegQueryValueExW(key, L"ProcessorNameString", NULL, NULL,
  72. (LPBYTE)data, &size);
  73. if (status == ERROR_SUCCESS) {
  74. os_wcs_to_utf8_ptr(data, 0, &str);
  75. blog(LOG_INFO, "CPU Name: %s", str);
  76. bfree(str);
  77. }
  78. size = sizeof(speed);
  79. status = RegQueryValueExW(key, L"~MHz", NULL, NULL, (LPBYTE)&speed,
  80. &size);
  81. if (status == ERROR_SUCCESS)
  82. blog(LOG_INFO, "CPU Speed: %ldMHz", speed);
  83. RegCloseKey(key);
  84. }
  85. static DWORD num_logical_cores(ULONG_PTR mask)
  86. {
  87. DWORD left_shift = sizeof(ULONG_PTR) * 8 - 1;
  88. DWORD bit_set_count = 0;
  89. ULONG_PTR bit_test = (ULONG_PTR)1 << left_shift;
  90. for (DWORD i = 0; i <= left_shift; ++i) {
  91. bit_set_count += ((mask & bit_test) ? 1 : 0);
  92. bit_test /= 2;
  93. }
  94. return bit_set_count;
  95. }
  96. static void log_processor_cores(void)
  97. {
  98. PSYSTEM_LOGICAL_PROCESSOR_INFORMATION info = NULL, temp = NULL;
  99. DWORD len = 0;
  100. GetLogicalProcessorInformation(info, &len);
  101. if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
  102. return;
  103. info = malloc(len);
  104. if (GetLogicalProcessorInformation(info, &len)) {
  105. DWORD num = len / sizeof(*info);
  106. int physical_cores = 0;
  107. int logical_cores = 0;
  108. temp = info;
  109. for (DWORD i = 0; i < num; i++) {
  110. if (temp->Relationship == RelationProcessorCore) {
  111. ULONG_PTR mask = temp->ProcessorMask;
  112. physical_cores++;
  113. logical_cores += num_logical_cores(mask);
  114. }
  115. temp++;
  116. }
  117. blog(LOG_INFO, "Physical Cores: %d, Logical Cores: %d",
  118. physical_cores, logical_cores);
  119. }
  120. free(info);
  121. }
  122. static void log_available_memory(void)
  123. {
  124. MEMORYSTATUSEX ms;
  125. ms.dwLength = sizeof(ms);
  126. GlobalMemoryStatusEx(&ms);
  127. #ifdef _WIN64
  128. const char *note = "";
  129. #else
  130. const char *note = " (NOTE: 32bit programs cannot use more than 3gb)";
  131. #endif
  132. blog(LOG_INFO, "Physical Memory: %luMB Total, %luMB Free%s",
  133. (DWORD)(ms.ullTotalPhys / 1048576),
  134. (DWORD)(ms.ullAvailPhys / 1048576),
  135. note);
  136. }
  137. static void log_windows_version(void)
  138. {
  139. struct win_version_info ver;
  140. get_win_ver(&ver);
  141. bool b64 = is_64_bit_windows();
  142. const char *windows_bitness = b64 ? "64" : "32";
  143. blog(LOG_INFO, "Windows Version: %d.%d Build %d (revision: %d; %s-bit)",
  144. ver.major, ver.minor, ver.build, ver.revis,
  145. windows_bitness);
  146. }
  147. static void log_admin_status(void)
  148. {
  149. SID_IDENTIFIER_AUTHORITY auth = SECURITY_NT_AUTHORITY;
  150. PSID admin_group;
  151. BOOL success;
  152. success = AllocateAndInitializeSid(&auth, 2,
  153. SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS,
  154. 0, 0, 0, 0, 0, 0, &admin_group);
  155. if (success) {
  156. if (!CheckTokenMembership(NULL, admin_group, &success))
  157. success = false;
  158. FreeSid(admin_group);
  159. }
  160. blog(LOG_INFO, "Running as administrator: %s",
  161. success ? "true" : "false");
  162. }
  163. typedef HRESULT (WINAPI *dwm_is_composition_enabled_t)(BOOL*);
  164. static void log_aero(void)
  165. {
  166. dwm_is_composition_enabled_t composition_enabled = NULL;
  167. const char *aeroMessage = win_ver >= 0x602 ?
  168. " (Aero is always on for windows 8 and above)" : "";
  169. HMODULE dwm = LoadLibraryW(L"dwmapi");
  170. BOOL bComposition = true;
  171. if (!dwm) {
  172. return;
  173. }
  174. composition_enabled = (dwm_is_composition_enabled_t)GetProcAddress(dwm,
  175. "DwmIsCompositionEnabled");
  176. if (!composition_enabled) {
  177. return;
  178. }
  179. composition_enabled(&bComposition);
  180. blog(LOG_INFO, "Aero is %s%s", bComposition ? "Enabled" : "Disabled",
  181. aeroMessage);
  182. }
  183. void log_system_info(void)
  184. {
  185. struct win_version_info ver;
  186. get_win_ver(&ver);
  187. win_ver = (ver.major << 8) | ver.minor;
  188. log_processor_info();
  189. log_processor_cores();
  190. log_available_memory();
  191. log_windows_version();
  192. log_admin_status();
  193. log_aero();
  194. }
  195. struct obs_hotkeys_platform {
  196. int vk_codes[OBS_KEY_LAST_VALUE];
  197. };
  198. static int get_virtual_key(obs_key_t key)
  199. {
  200. switch (key) {
  201. case OBS_KEY_RETURN: return VK_RETURN;
  202. case OBS_KEY_ESCAPE: return VK_ESCAPE;
  203. case OBS_KEY_TAB: return VK_TAB;
  204. case OBS_KEY_BACKTAB: return VK_OEM_BACKTAB;
  205. case OBS_KEY_BACKSPACE: return VK_BACK;
  206. case OBS_KEY_INSERT: return VK_INSERT;
  207. case OBS_KEY_DELETE: return VK_DELETE;
  208. case OBS_KEY_PAUSE: return VK_PAUSE;
  209. case OBS_KEY_PRINT: return VK_SNAPSHOT;
  210. case OBS_KEY_CLEAR: return VK_CLEAR;
  211. case OBS_KEY_HOME: return VK_HOME;
  212. case OBS_KEY_END: return VK_END;
  213. case OBS_KEY_LEFT: return VK_LEFT;
  214. case OBS_KEY_UP: return VK_UP;
  215. case OBS_KEY_RIGHT: return VK_RIGHT;
  216. case OBS_KEY_DOWN: return VK_DOWN;
  217. case OBS_KEY_PAGEUP: return VK_PRIOR;
  218. case OBS_KEY_PAGEDOWN: return VK_NEXT;
  219. case OBS_KEY_SHIFT: return VK_SHIFT;
  220. case OBS_KEY_CONTROL: return VK_CONTROL;
  221. case OBS_KEY_ALT: return VK_MENU;
  222. case OBS_KEY_CAPSLOCK: return VK_CAPITAL;
  223. case OBS_KEY_NUMLOCK: return VK_NUMLOCK;
  224. case OBS_KEY_SCROLLLOCK: return VK_SCROLL;
  225. case OBS_KEY_F1: return VK_F1;
  226. case OBS_KEY_F2: return VK_F2;
  227. case OBS_KEY_F3: return VK_F3;
  228. case OBS_KEY_F4: return VK_F4;
  229. case OBS_KEY_F5: return VK_F5;
  230. case OBS_KEY_F6: return VK_F6;
  231. case OBS_KEY_F7: return VK_F7;
  232. case OBS_KEY_F8: return VK_F8;
  233. case OBS_KEY_F9: return VK_F9;
  234. case OBS_KEY_F10: return VK_F10;
  235. case OBS_KEY_F11: return VK_F11;
  236. case OBS_KEY_F12: return VK_F12;
  237. case OBS_KEY_F13: return VK_F13;
  238. case OBS_KEY_F14: return VK_F14;
  239. case OBS_KEY_F15: return VK_F15;
  240. case OBS_KEY_F16: return VK_F16;
  241. case OBS_KEY_F17: return VK_F17;
  242. case OBS_KEY_F18: return VK_F18;
  243. case OBS_KEY_F19: return VK_F19;
  244. case OBS_KEY_F20: return VK_F20;
  245. case OBS_KEY_F21: return VK_F21;
  246. case OBS_KEY_F22: return VK_F22;
  247. case OBS_KEY_F23: return VK_F23;
  248. case OBS_KEY_F24: return VK_F24;
  249. case OBS_KEY_SPACE: return VK_SPACE;
  250. case OBS_KEY_APOSTROPHE: return VK_OEM_7;
  251. case OBS_KEY_PLUS: return VK_OEM_PLUS;
  252. case OBS_KEY_COMMA: return VK_OEM_COMMA;
  253. case OBS_KEY_MINUS: return VK_OEM_MINUS;
  254. case OBS_KEY_PERIOD: return VK_OEM_PERIOD;
  255. case OBS_KEY_SLASH: return VK_OEM_2;
  256. case OBS_KEY_0: return '0';
  257. case OBS_KEY_1: return '1';
  258. case OBS_KEY_2: return '2';
  259. case OBS_KEY_3: return '3';
  260. case OBS_KEY_4: return '4';
  261. case OBS_KEY_5: return '5';
  262. case OBS_KEY_6: return '6';
  263. case OBS_KEY_7: return '7';
  264. case OBS_KEY_8: return '8';
  265. case OBS_KEY_9: return '9';
  266. case OBS_KEY_NUMASTERISK: return VK_MULTIPLY;
  267. case OBS_KEY_NUMPLUS: return VK_ADD;
  268. case OBS_KEY_NUMMINUS: return VK_SUBTRACT;
  269. case OBS_KEY_NUMPERIOD: return VK_DECIMAL;
  270. case OBS_KEY_NUMSLASH: return VK_DIVIDE;
  271. case OBS_KEY_NUM0: return VK_NUMPAD0;
  272. case OBS_KEY_NUM1: return VK_NUMPAD1;
  273. case OBS_KEY_NUM2: return VK_NUMPAD2;
  274. case OBS_KEY_NUM3: return VK_NUMPAD3;
  275. case OBS_KEY_NUM4: return VK_NUMPAD4;
  276. case OBS_KEY_NUM5: return VK_NUMPAD5;
  277. case OBS_KEY_NUM6: return VK_NUMPAD6;
  278. case OBS_KEY_NUM7: return VK_NUMPAD7;
  279. case OBS_KEY_NUM8: return VK_NUMPAD8;
  280. case OBS_KEY_NUM9: return VK_NUMPAD9;
  281. case OBS_KEY_SEMICOLON: return VK_OEM_1;
  282. case OBS_KEY_A: return 'A';
  283. case OBS_KEY_B: return 'B';
  284. case OBS_KEY_C: return 'C';
  285. case OBS_KEY_D: return 'D';
  286. case OBS_KEY_E: return 'E';
  287. case OBS_KEY_F: return 'F';
  288. case OBS_KEY_G: return 'G';
  289. case OBS_KEY_H: return 'H';
  290. case OBS_KEY_I: return 'I';
  291. case OBS_KEY_J: return 'J';
  292. case OBS_KEY_K: return 'K';
  293. case OBS_KEY_L: return 'L';
  294. case OBS_KEY_M: return 'M';
  295. case OBS_KEY_N: return 'N';
  296. case OBS_KEY_O: return 'O';
  297. case OBS_KEY_P: return 'P';
  298. case OBS_KEY_Q: return 'Q';
  299. case OBS_KEY_R: return 'R';
  300. case OBS_KEY_S: return 'S';
  301. case OBS_KEY_T: return 'T';
  302. case OBS_KEY_U: return 'U';
  303. case OBS_KEY_V: return 'V';
  304. case OBS_KEY_W: return 'W';
  305. case OBS_KEY_X: return 'X';
  306. case OBS_KEY_Y: return 'Y';
  307. case OBS_KEY_Z: return 'Z';
  308. case OBS_KEY_BRACKETLEFT: return VK_OEM_4;
  309. case OBS_KEY_BACKSLASH: return VK_OEM_5;
  310. case OBS_KEY_BRACKETRIGHT: return VK_OEM_6;
  311. case OBS_KEY_ASCIITILDE: return VK_OEM_3;
  312. case OBS_KEY_KANJI: return VK_KANJI;
  313. case OBS_KEY_TOUROKU: return VK_OEM_FJ_TOUROKU;
  314. case OBS_KEY_MASSYO: return VK_OEM_FJ_MASSHOU;
  315. case OBS_KEY_HANGUL: return VK_HANGUL;
  316. case OBS_KEY_MOUSE1: return VK_LBUTTON;
  317. case OBS_KEY_MOUSE2: return VK_RBUTTON;
  318. case OBS_KEY_MOUSE3: return VK_MBUTTON;
  319. case OBS_KEY_MOUSE4: return VK_XBUTTON1;
  320. case OBS_KEY_MOUSE5: return VK_XBUTTON2;
  321. /* TODO: Implement keys for non-US keyboards */
  322. default:;
  323. }
  324. return 0;
  325. }
  326. bool obs_hotkeys_platform_init(struct obs_core_hotkeys *hotkeys)
  327. {
  328. hotkeys->platform_context = bzalloc(sizeof(obs_hotkeys_platform_t));
  329. for (size_t i = 0; i < OBS_KEY_LAST_VALUE; i++)
  330. hotkeys->platform_context->vk_codes[i] = get_virtual_key(i);
  331. return true;
  332. }
  333. void obs_hotkeys_platform_free(struct obs_core_hotkeys *hotkeys)
  334. {
  335. bfree(hotkeys->platform_context);
  336. hotkeys->platform_context = NULL;
  337. }
  338. static bool vk_down(DWORD vk)
  339. {
  340. short state = GetAsyncKeyState(vk);
  341. bool down = (state & 0x8000) != 0;
  342. return down;
  343. }
  344. bool obs_hotkeys_platform_is_pressed(obs_hotkeys_platform_t *context,
  345. obs_key_t key)
  346. {
  347. if (key == OBS_KEY_META) {
  348. return vk_down(VK_LWIN) || vk_down(VK_RWIN);
  349. }
  350. UNUSED_PARAMETER(context);
  351. return vk_down(obs_key_to_virtual_key(key));
  352. }
  353. void obs_key_to_str(obs_key_t key, struct dstr *str)
  354. {
  355. wchar_t name[128] = L"";
  356. UINT scan_code;
  357. int vk;
  358. if (key == OBS_KEY_NONE) {
  359. return;
  360. } else if (key >= OBS_KEY_MOUSE1 && key <= OBS_KEY_MOUSE29) {
  361. if (obs->hotkeys.translations[key]) {
  362. dstr_copy(str, obs->hotkeys.translations[key]);
  363. } else {
  364. dstr_printf(str, "Mouse %d",
  365. (int)(key - OBS_KEY_MOUSE1 + 1));
  366. }
  367. return;
  368. } if (key == OBS_KEY_PAUSE) {
  369. dstr_copy(str, obs_get_hotkey_translation(key, "Pause"));
  370. return;
  371. } else if (key == OBS_KEY_META) {
  372. dstr_copy(str, obs_get_hotkey_translation(key, "Windows"));
  373. return;
  374. }
  375. vk = obs_key_to_virtual_key(key);
  376. scan_code = MapVirtualKey(vk, 0) << 16;
  377. switch (vk) {
  378. case VK_HOME:
  379. case VK_END:
  380. case VK_LEFT:
  381. case VK_UP:
  382. case VK_RIGHT:
  383. case VK_DOWN:
  384. case VK_PRIOR:
  385. case VK_NEXT:
  386. case VK_INSERT:
  387. case VK_DELETE:
  388. case VK_NUMLOCK:
  389. scan_code |= 0x01000000;
  390. }
  391. if (scan_code != 0 && GetKeyNameTextW(scan_code, name, 128) != 0) {
  392. dstr_from_wcs(str, name);
  393. } else if (key != OBS_KEY_NONE) {
  394. dstr_copy(str, obs_key_to_name(key));
  395. }
  396. }
  397. obs_key_t obs_key_from_virtual_key(int code)
  398. {
  399. obs_hotkeys_platform_t *platform = obs->hotkeys.platform_context;
  400. for (size_t i = 0; i < OBS_KEY_LAST_VALUE; i++) {
  401. if (platform->vk_codes[i] == code) {
  402. return (obs_key_t)i;
  403. }
  404. }
  405. return OBS_KEY_NONE;
  406. }
  407. int obs_key_to_virtual_key(obs_key_t key)
  408. {
  409. if (key == OBS_KEY_META)
  410. return VK_LWIN;
  411. return obs->hotkeys.platform_context->vk_codes[(int)key];
  412. }
  413. static inline void add_combo_key(obs_key_t key, struct dstr *str)
  414. {
  415. struct dstr key_str = {0};
  416. obs_key_to_str(key, &key_str);
  417. if (!dstr_is_empty(&key_str)) {
  418. if (!dstr_is_empty(str)) {
  419. dstr_cat(str, " + ");
  420. }
  421. dstr_cat_dstr(str, &key_str);
  422. }
  423. dstr_free(&key_str);
  424. }
  425. void obs_key_combination_to_str(obs_key_combination_t combination,
  426. struct dstr *str)
  427. {
  428. if ((combination.modifiers & INTERACT_CONTROL_KEY) != 0) {
  429. add_combo_key(OBS_KEY_CONTROL, str);
  430. }
  431. if ((combination.modifiers & INTERACT_COMMAND_KEY) != 0) {
  432. add_combo_key(OBS_KEY_META, str);
  433. }
  434. if ((combination.modifiers & INTERACT_ALT_KEY) != 0) {
  435. add_combo_key(OBS_KEY_ALT, str);
  436. }
  437. if ((combination.modifiers & INTERACT_SHIFT_KEY) != 0) {
  438. add_combo_key(OBS_KEY_SHIFT, str);
  439. }
  440. if (combination.key != OBS_KEY_NONE) {
  441. add_combo_key(combination.key, str);
  442. }
  443. }
  444. bool sym_initialize_called = false;
  445. void reset_win32_symbol_paths(void)
  446. {
  447. static BOOL (WINAPI *sym_initialize_w)(HANDLE, const wchar_t*, BOOL);
  448. static BOOL (WINAPI *sym_set_search_path_w)(HANDLE, const wchar_t*);
  449. static bool funcs_initialized = false;
  450. static bool initialize_success = false;
  451. struct obs_module *module = obs->first_module;
  452. struct dstr path_str = {0};
  453. DARRAY(char*) paths;
  454. wchar_t *path_str_w = NULL;
  455. char *abspath;
  456. da_init(paths);
  457. if (!funcs_initialized) {
  458. HMODULE mod;
  459. funcs_initialized = true;
  460. mod = LoadLibraryW(L"DbgHelp");
  461. if (!mod)
  462. return;
  463. sym_initialize_w = (void*)GetProcAddress(mod, "SymInitializeW");
  464. sym_set_search_path_w = (void*)GetProcAddress(mod,
  465. "SymSetSearchPathW");
  466. if (!sym_initialize_w || !sym_set_search_path_w)
  467. return;
  468. initialize_success = true;
  469. }
  470. if (!initialize_success)
  471. return;
  472. abspath = os_get_abs_path_ptr(".");
  473. if (abspath)
  474. da_push_back(paths, &abspath);
  475. while (module) {
  476. bool found = false;
  477. struct dstr path = {0};
  478. char *path_end;
  479. dstr_copy(&path, module->bin_path);
  480. dstr_replace(&path, "/", "\\");
  481. path_end = strrchr(path.array, '\\');
  482. if (!path_end) {
  483. module = module->next;
  484. dstr_free(&path);
  485. continue;
  486. }
  487. *path_end = 0;
  488. for (size_t i = 0; i < paths.num; i++) {
  489. const char *existing_path = paths.array[i];
  490. if (astrcmpi(path.array, existing_path) == 0) {
  491. found = true;
  492. break;
  493. }
  494. }
  495. if (!found) {
  496. abspath = os_get_abs_path_ptr(path.array);
  497. if (abspath)
  498. da_push_back(paths, &abspath);
  499. }
  500. dstr_free(&path);
  501. module = module->next;
  502. }
  503. for (size_t i = 0; i < paths.num; i++) {
  504. const char *path = paths.array[i];
  505. if (path && *path) {
  506. if (i != 0)
  507. dstr_cat(&path_str, ";");
  508. dstr_cat(&path_str, paths.array[i]);
  509. }
  510. }
  511. if (path_str.array) {
  512. os_utf8_to_wcs_ptr(path_str.array, path_str.len, &path_str_w);
  513. if (path_str_w) {
  514. if (!sym_initialize_called) {
  515. sym_initialize_w(GetCurrentProcess(),
  516. path_str_w, false);
  517. sym_initialize_called = true;
  518. } else {
  519. sym_set_search_path_w(GetCurrentProcess(),
  520. path_str_w);
  521. }
  522. bfree(path_str_w);
  523. }
  524. }
  525. for (size_t i = 0; i < paths.num; i++)
  526. bfree(paths.array[i]);
  527. dstr_free(&path_str);
  528. da_free(paths);
  529. }
  530. void initialize_com(void)
  531. {
  532. CoInitializeEx(0, COINIT_MULTITHREADED);
  533. }
  534. void uninitialize_com(void)
  535. {
  536. CoUninitialize();
  537. }