obs-windows.c 28 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298
  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-registry.h"
  15. #include "util/windows/win-version.h"
  16. #include "util/platform.h"
  17. #include "util/dstr.h"
  18. #include "obs.h"
  19. #include "obs-internal.h"
  20. #include <windows.h>
  21. #include <wscapi.h>
  22. #include <iwscapi.h>
  23. static uint32_t win_ver = 0;
  24. static uint32_t win_build = 0;
  25. const char *get_module_extension(void)
  26. {
  27. return ".dll";
  28. }
  29. #ifdef _WIN64
  30. #define BIT_STRING "64bit"
  31. #else
  32. #define BIT_STRING "32bit"
  33. #endif
  34. static const char *module_bin[] = {
  35. "../../obs-plugins/" BIT_STRING,
  36. };
  37. static const char *module_data[] = {"../../data/obs-plugins/%module%"};
  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. dstr_free(&path);
  53. return NULL;
  54. }
  55. static void log_processor_info(void)
  56. {
  57. HKEY key;
  58. wchar_t data[1024];
  59. char *str = NULL;
  60. DWORD size, speed;
  61. LSTATUS status;
  62. memset(data, 0, sizeof(data));
  63. status = RegOpenKeyW(
  64. HKEY_LOCAL_MACHINE,
  65. L"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", &key);
  66. if (status != ERROR_SUCCESS)
  67. return;
  68. size = sizeof(data);
  69. status = RegQueryValueExW(key, L"ProcessorNameString", NULL, NULL,
  70. (LPBYTE)data, &size);
  71. if (status == ERROR_SUCCESS) {
  72. os_wcs_to_utf8_ptr(data, 0, &str);
  73. blog(LOG_INFO, "CPU Name: %s", str);
  74. bfree(str);
  75. }
  76. size = sizeof(speed);
  77. status = RegQueryValueExW(key, L"~MHz", NULL, NULL, (LPBYTE)&speed,
  78. &size);
  79. if (status == ERROR_SUCCESS)
  80. blog(LOG_INFO, "CPU Speed: %ldMHz", speed);
  81. RegCloseKey(key);
  82. }
  83. static void log_processor_cores(void)
  84. {
  85. blog(LOG_INFO, "Physical Cores: %d, Logical Cores: %d",
  86. os_get_physical_cores(), os_get_logical_cores());
  87. }
  88. static void log_available_memory(void)
  89. {
  90. MEMORYSTATUSEX ms;
  91. ms.dwLength = sizeof(ms);
  92. GlobalMemoryStatusEx(&ms);
  93. #ifdef _WIN64
  94. const char *note = "";
  95. #else
  96. const char *note = " (NOTE: 32bit programs cannot use more than 3gb)";
  97. #endif
  98. blog(LOG_INFO, "Physical Memory: %luMB Total, %luMB Free%s",
  99. (DWORD)(ms.ullTotalPhys / 1048576),
  100. (DWORD)(ms.ullAvailPhys / 1048576), note);
  101. }
  102. extern const char *get_win_release_id();
  103. static void log_windows_version(void)
  104. {
  105. struct win_version_info ver;
  106. get_win_ver(&ver);
  107. const char *release_id = get_win_release_id();
  108. bool b64 = is_64_bit_windows();
  109. const char *windows_bitness = b64 ? "64" : "32";
  110. blog(LOG_INFO,
  111. "Windows Version: %d.%d Build %d (release: %s; revision: %d; %s-bit)",
  112. ver.major, ver.minor, ver.build, release_id, ver.revis,
  113. windows_bitness);
  114. }
  115. static void log_admin_status(void)
  116. {
  117. SID_IDENTIFIER_AUTHORITY auth = SECURITY_NT_AUTHORITY;
  118. PSID admin_group;
  119. BOOL success;
  120. success = AllocateAndInitializeSid(&auth, 2,
  121. SECURITY_BUILTIN_DOMAIN_RID,
  122. DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0,
  123. 0, 0, &admin_group);
  124. if (success) {
  125. if (!CheckTokenMembership(NULL, admin_group, &success))
  126. success = false;
  127. FreeSid(admin_group);
  128. }
  129. blog(LOG_INFO, "Running as administrator: %s",
  130. success ? "true" : "false");
  131. }
  132. typedef HRESULT(WINAPI *dwm_is_composition_enabled_t)(BOOL *);
  133. static void log_aero(void)
  134. {
  135. dwm_is_composition_enabled_t composition_enabled = NULL;
  136. const char *aeroMessage =
  137. win_ver >= 0x602
  138. ? " (Aero is always on for windows 8 and above)"
  139. : "";
  140. HMODULE dwm = LoadLibraryW(L"dwmapi");
  141. BOOL bComposition = true;
  142. if (!dwm) {
  143. return;
  144. }
  145. composition_enabled = (dwm_is_composition_enabled_t)GetProcAddress(
  146. dwm, "DwmIsCompositionEnabled");
  147. if (!composition_enabled) {
  148. FreeLibrary(dwm);
  149. return;
  150. }
  151. composition_enabled(&bComposition);
  152. blog(LOG_INFO, "Aero is %s%s", bComposition ? "Enabled" : "Disabled",
  153. aeroMessage);
  154. }
  155. #define WIN10_GAME_BAR_REG_KEY \
  156. L"Software\\Microsoft\\Windows\\CurrentVersion\\GameDVR"
  157. #define WIN10_GAME_DVR_POLICY_REG_KEY \
  158. L"SOFTWARE\\Policies\\Microsoft\\Windows\\GameDVR"
  159. #define WIN10_GAME_DVR_REG_KEY L"System\\GameConfigStore"
  160. #define WIN10_GAME_MODE_REG_KEY L"Software\\Microsoft\\GameBar"
  161. #define WIN10_HAGS_REG_KEY \
  162. L"SYSTEM\\CurrentControlSet\\Control\\GraphicsDrivers"
  163. static void log_gaming_features(void)
  164. {
  165. if (win_ver < 0xA00)
  166. return;
  167. struct reg_dword game_bar_enabled;
  168. struct reg_dword game_dvr_allowed;
  169. struct reg_dword game_dvr_enabled;
  170. struct reg_dword game_dvr_bg_recording;
  171. struct reg_dword game_mode_enabled;
  172. struct reg_dword hags_enabled;
  173. get_reg_dword(HKEY_CURRENT_USER, WIN10_GAME_BAR_REG_KEY,
  174. L"AppCaptureEnabled", &game_bar_enabled);
  175. get_reg_dword(HKEY_CURRENT_USER, WIN10_GAME_DVR_POLICY_REG_KEY,
  176. L"AllowGameDVR", &game_dvr_allowed);
  177. get_reg_dword(HKEY_CURRENT_USER, WIN10_GAME_DVR_REG_KEY,
  178. L"GameDVR_Enabled", &game_dvr_enabled);
  179. get_reg_dword(HKEY_CURRENT_USER, WIN10_GAME_BAR_REG_KEY,
  180. L"HistoricalCaptureEnabled", &game_dvr_bg_recording);
  181. get_reg_dword(HKEY_CURRENT_USER, WIN10_GAME_MODE_REG_KEY,
  182. L"AutoGameModeEnabled", &game_mode_enabled);
  183. get_reg_dword(HKEY_LOCAL_MACHINE, WIN10_HAGS_REG_KEY, L"HwSchMode",
  184. &hags_enabled);
  185. if (game_mode_enabled.status != ERROR_SUCCESS) {
  186. get_reg_dword(HKEY_CURRENT_USER, WIN10_GAME_MODE_REG_KEY,
  187. L"AllowAutoGameMode", &game_mode_enabled);
  188. }
  189. blog(LOG_INFO, "Windows 10/11 Gaming Features:");
  190. if (game_bar_enabled.status == ERROR_SUCCESS) {
  191. blog(LOG_INFO, "\tGame Bar: %s",
  192. (bool)game_bar_enabled.return_value ? "On" : "Off");
  193. }
  194. if (game_dvr_allowed.status == ERROR_SUCCESS) {
  195. blog(LOG_INFO, "\tGame DVR Allowed: %s",
  196. (bool)game_dvr_allowed.return_value ? "Yes" : "No");
  197. }
  198. if (game_dvr_enabled.status == ERROR_SUCCESS) {
  199. blog(LOG_INFO, "\tGame DVR: %s",
  200. (bool)game_dvr_enabled.return_value ? "On" : "Off");
  201. }
  202. if (game_dvr_bg_recording.status == ERROR_SUCCESS) {
  203. blog(LOG_INFO, "\tGame DVR Background Recording: %s",
  204. (bool)game_dvr_bg_recording.return_value ? "On" : "Off");
  205. }
  206. if (game_mode_enabled.status == ERROR_SUCCESS) {
  207. blog(LOG_INFO, "\tGame Mode: %s",
  208. (bool)game_mode_enabled.return_value ? "On" : "Off");
  209. } else if (win_build >= 19042) {
  210. // On by default in newer Windows 10 builds (no registry key set)
  211. blog(LOG_INFO, "\tGame Mode: Probably On (no reg key set)");
  212. }
  213. if (hags_enabled.status == ERROR_SUCCESS) {
  214. blog(LOG_INFO, "\tHardware GPU Scheduler: %s",
  215. (hags_enabled.return_value == 2) ? "On" : "Off");
  216. } else if (win_build >= 22000) {
  217. // On by default in Windows 11 (no registry key set)
  218. blog(LOG_INFO,
  219. "\tHardware GPU Scheduler: Probably On (no reg key set)");
  220. }
  221. }
  222. static const char *get_str_for_state(int state)
  223. {
  224. switch (state) {
  225. case WSC_SECURITY_PRODUCT_STATE_ON:
  226. return "enabled";
  227. case WSC_SECURITY_PRODUCT_STATE_OFF:
  228. return "disabled";
  229. case WSC_SECURITY_PRODUCT_STATE_SNOOZED:
  230. return "temporarily disabled";
  231. case WSC_SECURITY_PRODUCT_STATE_EXPIRED:
  232. return "expired";
  233. default:
  234. return "unknown";
  235. }
  236. }
  237. static const char *get_str_for_type(int type)
  238. {
  239. switch (type) {
  240. case WSC_SECURITY_PROVIDER_ANTIVIRUS:
  241. return "AV";
  242. case WSC_SECURITY_PROVIDER_FIREWALL:
  243. return "FW";
  244. case WSC_SECURITY_PROVIDER_ANTISPYWARE:
  245. return "ASW";
  246. default:
  247. return "unknown";
  248. }
  249. }
  250. static void log_security_products_by_type(IWSCProductList *prod_list, int type)
  251. {
  252. HRESULT hr;
  253. LONG count = 0;
  254. IWscProduct *prod;
  255. BSTR name;
  256. WSC_SECURITY_PRODUCT_STATE prod_state;
  257. hr = prod_list->lpVtbl->Initialize(prod_list, type);
  258. if (FAILED(hr))
  259. return;
  260. hr = prod_list->lpVtbl->get_Count(prod_list, &count);
  261. if (FAILED(hr)) {
  262. prod_list->lpVtbl->Release(prod_list);
  263. return;
  264. }
  265. for (int i = 0; i < count; i++) {
  266. hr = prod_list->lpVtbl->get_Item(prod_list, i, &prod);
  267. if (FAILED(hr))
  268. continue;
  269. hr = prod->lpVtbl->get_ProductName(prod, &name);
  270. if (FAILED(hr))
  271. continue;
  272. hr = prod->lpVtbl->get_ProductState(prod, &prod_state);
  273. if (FAILED(hr)) {
  274. SysFreeString(name);
  275. continue;
  276. }
  277. blog(LOG_INFO, "\t%S: %s (%s)", name,
  278. get_str_for_state(prod_state), get_str_for_type(type));
  279. SysFreeString(name);
  280. prod->lpVtbl->Release(prod);
  281. }
  282. prod_list->lpVtbl->Release(prod_list);
  283. }
  284. static void log_security_products(void)
  285. {
  286. IWSCProductList *prod_list = NULL;
  287. HMODULE h_wsc;
  288. HRESULT hr;
  289. /* We load the DLL rather than import wcsapi.lib because the clsid /
  290. * iid only exists on Windows 8 or higher. */
  291. h_wsc = LoadLibraryW(L"wscapi.dll");
  292. if (!h_wsc)
  293. return;
  294. const CLSID *prod_list_clsid =
  295. (const CLSID *)GetProcAddress(h_wsc, "CLSID_WSCProductList");
  296. const IID *prod_list_iid =
  297. (const IID *)GetProcAddress(h_wsc, "IID_IWSCProductList");
  298. if (prod_list_clsid && prod_list_iid) {
  299. blog(LOG_INFO, "Sec. Software Status:");
  300. hr = CoCreateInstance(prod_list_clsid, NULL,
  301. CLSCTX_INPROC_SERVER, prod_list_iid,
  302. &prod_list);
  303. if (!FAILED(hr)) {
  304. log_security_products_by_type(
  305. prod_list, WSC_SECURITY_PROVIDER_ANTIVIRUS);
  306. }
  307. hr = CoCreateInstance(prod_list_clsid, NULL,
  308. CLSCTX_INPROC_SERVER, prod_list_iid,
  309. &prod_list);
  310. if (!FAILED(hr)) {
  311. log_security_products_by_type(
  312. prod_list, WSC_SECURITY_PROVIDER_FIREWALL);
  313. }
  314. hr = CoCreateInstance(prod_list_clsid, NULL,
  315. CLSCTX_INPROC_SERVER, prod_list_iid,
  316. &prod_list);
  317. if (!FAILED(hr)) {
  318. log_security_products_by_type(
  319. prod_list, WSC_SECURITY_PROVIDER_ANTISPYWARE);
  320. }
  321. }
  322. FreeLibrary(h_wsc);
  323. }
  324. void log_system_info(void)
  325. {
  326. struct win_version_info ver;
  327. get_win_ver(&ver);
  328. win_ver = (ver.major << 8) | ver.minor;
  329. win_build = ver.build;
  330. log_processor_info();
  331. log_processor_cores();
  332. log_available_memory();
  333. log_windows_version();
  334. log_admin_status();
  335. log_aero();
  336. log_gaming_features();
  337. log_security_products();
  338. }
  339. struct obs_hotkeys_platform {
  340. int vk_codes[OBS_KEY_LAST_VALUE];
  341. };
  342. static int get_virtual_key(obs_key_t key)
  343. {
  344. switch (key) {
  345. case OBS_KEY_RETURN:
  346. return VK_RETURN;
  347. case OBS_KEY_ESCAPE:
  348. return VK_ESCAPE;
  349. case OBS_KEY_TAB:
  350. return VK_TAB;
  351. case OBS_KEY_BACKTAB:
  352. return VK_OEM_BACKTAB;
  353. case OBS_KEY_BACKSPACE:
  354. return VK_BACK;
  355. case OBS_KEY_INSERT:
  356. return VK_INSERT;
  357. case OBS_KEY_DELETE:
  358. return VK_DELETE;
  359. case OBS_KEY_PAUSE:
  360. return VK_PAUSE;
  361. case OBS_KEY_PRINT:
  362. return VK_SNAPSHOT;
  363. case OBS_KEY_CLEAR:
  364. return VK_CLEAR;
  365. case OBS_KEY_HOME:
  366. return VK_HOME;
  367. case OBS_KEY_END:
  368. return VK_END;
  369. case OBS_KEY_LEFT:
  370. return VK_LEFT;
  371. case OBS_KEY_UP:
  372. return VK_UP;
  373. case OBS_KEY_RIGHT:
  374. return VK_RIGHT;
  375. case OBS_KEY_DOWN:
  376. return VK_DOWN;
  377. case OBS_KEY_PAGEUP:
  378. return VK_PRIOR;
  379. case OBS_KEY_PAGEDOWN:
  380. return VK_NEXT;
  381. case OBS_KEY_SHIFT:
  382. return VK_SHIFT;
  383. case OBS_KEY_CONTROL:
  384. return VK_CONTROL;
  385. case OBS_KEY_ALT:
  386. return VK_MENU;
  387. case OBS_KEY_CAPSLOCK:
  388. return VK_CAPITAL;
  389. case OBS_KEY_NUMLOCK:
  390. return VK_NUMLOCK;
  391. case OBS_KEY_SCROLLLOCK:
  392. return VK_SCROLL;
  393. case OBS_KEY_F1:
  394. return VK_F1;
  395. case OBS_KEY_F2:
  396. return VK_F2;
  397. case OBS_KEY_F3:
  398. return VK_F3;
  399. case OBS_KEY_F4:
  400. return VK_F4;
  401. case OBS_KEY_F5:
  402. return VK_F5;
  403. case OBS_KEY_F6:
  404. return VK_F6;
  405. case OBS_KEY_F7:
  406. return VK_F7;
  407. case OBS_KEY_F8:
  408. return VK_F8;
  409. case OBS_KEY_F9:
  410. return VK_F9;
  411. case OBS_KEY_F10:
  412. return VK_F10;
  413. case OBS_KEY_F11:
  414. return VK_F11;
  415. case OBS_KEY_F12:
  416. return VK_F12;
  417. case OBS_KEY_F13:
  418. return VK_F13;
  419. case OBS_KEY_F14:
  420. return VK_F14;
  421. case OBS_KEY_F15:
  422. return VK_F15;
  423. case OBS_KEY_F16:
  424. return VK_F16;
  425. case OBS_KEY_F17:
  426. return VK_F17;
  427. case OBS_KEY_F18:
  428. return VK_F18;
  429. case OBS_KEY_F19:
  430. return VK_F19;
  431. case OBS_KEY_F20:
  432. return VK_F20;
  433. case OBS_KEY_F21:
  434. return VK_F21;
  435. case OBS_KEY_F22:
  436. return VK_F22;
  437. case OBS_KEY_F23:
  438. return VK_F23;
  439. case OBS_KEY_F24:
  440. return VK_F24;
  441. case OBS_KEY_SPACE:
  442. return VK_SPACE;
  443. case OBS_KEY_APOSTROPHE:
  444. return VK_OEM_7;
  445. case OBS_KEY_PLUS:
  446. return VK_OEM_PLUS;
  447. case OBS_KEY_COMMA:
  448. return VK_OEM_COMMA;
  449. case OBS_KEY_MINUS:
  450. return VK_OEM_MINUS;
  451. case OBS_KEY_PERIOD:
  452. return VK_OEM_PERIOD;
  453. case OBS_KEY_SLASH:
  454. return VK_OEM_2;
  455. case OBS_KEY_0:
  456. return '0';
  457. case OBS_KEY_1:
  458. return '1';
  459. case OBS_KEY_2:
  460. return '2';
  461. case OBS_KEY_3:
  462. return '3';
  463. case OBS_KEY_4:
  464. return '4';
  465. case OBS_KEY_5:
  466. return '5';
  467. case OBS_KEY_6:
  468. return '6';
  469. case OBS_KEY_7:
  470. return '7';
  471. case OBS_KEY_8:
  472. return '8';
  473. case OBS_KEY_9:
  474. return '9';
  475. case OBS_KEY_NUMASTERISK:
  476. return VK_MULTIPLY;
  477. case OBS_KEY_NUMPLUS:
  478. return VK_ADD;
  479. case OBS_KEY_NUMMINUS:
  480. return VK_SUBTRACT;
  481. case OBS_KEY_NUMPERIOD:
  482. return VK_DECIMAL;
  483. case OBS_KEY_NUMSLASH:
  484. return VK_DIVIDE;
  485. case OBS_KEY_NUM0:
  486. return VK_NUMPAD0;
  487. case OBS_KEY_NUM1:
  488. return VK_NUMPAD1;
  489. case OBS_KEY_NUM2:
  490. return VK_NUMPAD2;
  491. case OBS_KEY_NUM3:
  492. return VK_NUMPAD3;
  493. case OBS_KEY_NUM4:
  494. return VK_NUMPAD4;
  495. case OBS_KEY_NUM5:
  496. return VK_NUMPAD5;
  497. case OBS_KEY_NUM6:
  498. return VK_NUMPAD6;
  499. case OBS_KEY_NUM7:
  500. return VK_NUMPAD7;
  501. case OBS_KEY_NUM8:
  502. return VK_NUMPAD8;
  503. case OBS_KEY_NUM9:
  504. return VK_NUMPAD9;
  505. case OBS_KEY_SEMICOLON:
  506. return VK_OEM_1;
  507. case OBS_KEY_A:
  508. return 'A';
  509. case OBS_KEY_B:
  510. return 'B';
  511. case OBS_KEY_C:
  512. return 'C';
  513. case OBS_KEY_D:
  514. return 'D';
  515. case OBS_KEY_E:
  516. return 'E';
  517. case OBS_KEY_F:
  518. return 'F';
  519. case OBS_KEY_G:
  520. return 'G';
  521. case OBS_KEY_H:
  522. return 'H';
  523. case OBS_KEY_I:
  524. return 'I';
  525. case OBS_KEY_J:
  526. return 'J';
  527. case OBS_KEY_K:
  528. return 'K';
  529. case OBS_KEY_L:
  530. return 'L';
  531. case OBS_KEY_M:
  532. return 'M';
  533. case OBS_KEY_N:
  534. return 'N';
  535. case OBS_KEY_O:
  536. return 'O';
  537. case OBS_KEY_P:
  538. return 'P';
  539. case OBS_KEY_Q:
  540. return 'Q';
  541. case OBS_KEY_R:
  542. return 'R';
  543. case OBS_KEY_S:
  544. return 'S';
  545. case OBS_KEY_T:
  546. return 'T';
  547. case OBS_KEY_U:
  548. return 'U';
  549. case OBS_KEY_V:
  550. return 'V';
  551. case OBS_KEY_W:
  552. return 'W';
  553. case OBS_KEY_X:
  554. return 'X';
  555. case OBS_KEY_Y:
  556. return 'Y';
  557. case OBS_KEY_Z:
  558. return 'Z';
  559. case OBS_KEY_BRACKETLEFT:
  560. return VK_OEM_4;
  561. case OBS_KEY_BACKSLASH:
  562. return VK_OEM_5;
  563. case OBS_KEY_BRACKETRIGHT:
  564. return VK_OEM_6;
  565. case OBS_KEY_ASCIITILDE:
  566. return VK_OEM_3;
  567. case OBS_KEY_HENKAN:
  568. return VK_CONVERT;
  569. case OBS_KEY_MUHENKAN:
  570. return VK_NONCONVERT;
  571. case OBS_KEY_KANJI:
  572. return VK_KANJI;
  573. case OBS_KEY_TOUROKU:
  574. return VK_OEM_FJ_TOUROKU;
  575. case OBS_KEY_MASSYO:
  576. return VK_OEM_FJ_MASSHOU;
  577. case OBS_KEY_HANGUL:
  578. return VK_HANGUL;
  579. case OBS_KEY_BACKSLASH_RT102:
  580. return VK_OEM_102;
  581. case OBS_KEY_MOUSE1:
  582. return VK_LBUTTON;
  583. case OBS_KEY_MOUSE2:
  584. return VK_RBUTTON;
  585. case OBS_KEY_MOUSE3:
  586. return VK_MBUTTON;
  587. case OBS_KEY_MOUSE4:
  588. return VK_XBUTTON1;
  589. case OBS_KEY_MOUSE5:
  590. return VK_XBUTTON2;
  591. case OBS_KEY_VK_CANCEL:
  592. return VK_CANCEL;
  593. case OBS_KEY_0x07:
  594. return 0x07;
  595. case OBS_KEY_0x0A:
  596. return 0x0A;
  597. case OBS_KEY_0x0B:
  598. return 0x0B;
  599. case OBS_KEY_0x0E:
  600. return 0x0E;
  601. case OBS_KEY_0x0F:
  602. return 0x0F;
  603. case OBS_KEY_0x16:
  604. return 0x16;
  605. case OBS_KEY_VK_JUNJA:
  606. return VK_JUNJA;
  607. case OBS_KEY_VK_FINAL:
  608. return VK_FINAL;
  609. case OBS_KEY_0x1A:
  610. return 0x1A;
  611. case OBS_KEY_VK_ACCEPT:
  612. return VK_ACCEPT;
  613. case OBS_KEY_VK_MODECHANGE:
  614. return VK_MODECHANGE;
  615. case OBS_KEY_VK_SELECT:
  616. return VK_SELECT;
  617. case OBS_KEY_VK_PRINT:
  618. return VK_PRINT;
  619. case OBS_KEY_VK_EXECUTE:
  620. return VK_EXECUTE;
  621. case OBS_KEY_VK_HELP:
  622. return VK_HELP;
  623. case OBS_KEY_0x30:
  624. return 0x30;
  625. case OBS_KEY_0x31:
  626. return 0x31;
  627. case OBS_KEY_0x32:
  628. return 0x32;
  629. case OBS_KEY_0x33:
  630. return 0x33;
  631. case OBS_KEY_0x34:
  632. return 0x34;
  633. case OBS_KEY_0x35:
  634. return 0x35;
  635. case OBS_KEY_0x36:
  636. return 0x36;
  637. case OBS_KEY_0x37:
  638. return 0x37;
  639. case OBS_KEY_0x38:
  640. return 0x38;
  641. case OBS_KEY_0x39:
  642. return 0x39;
  643. case OBS_KEY_0x3A:
  644. return 0x3A;
  645. case OBS_KEY_0x3B:
  646. return 0x3B;
  647. case OBS_KEY_0x3C:
  648. return 0x3C;
  649. case OBS_KEY_0x3D:
  650. return 0x3D;
  651. case OBS_KEY_0x3E:
  652. return 0x3E;
  653. case OBS_KEY_0x3F:
  654. return 0x3F;
  655. case OBS_KEY_0x40:
  656. return 0x40;
  657. case OBS_KEY_0x41:
  658. return 0x41;
  659. case OBS_KEY_0x42:
  660. return 0x42;
  661. case OBS_KEY_0x43:
  662. return 0x43;
  663. case OBS_KEY_0x44:
  664. return 0x44;
  665. case OBS_KEY_0x45:
  666. return 0x45;
  667. case OBS_KEY_0x46:
  668. return 0x46;
  669. case OBS_KEY_0x47:
  670. return 0x47;
  671. case OBS_KEY_0x48:
  672. return 0x48;
  673. case OBS_KEY_0x49:
  674. return 0x49;
  675. case OBS_KEY_0x4A:
  676. return 0x4A;
  677. case OBS_KEY_0x4B:
  678. return 0x4B;
  679. case OBS_KEY_0x4C:
  680. return 0x4C;
  681. case OBS_KEY_0x4D:
  682. return 0x4D;
  683. case OBS_KEY_0x4E:
  684. return 0x4E;
  685. case OBS_KEY_0x4F:
  686. return 0x4F;
  687. case OBS_KEY_0x50:
  688. return 0x50;
  689. case OBS_KEY_0x51:
  690. return 0x51;
  691. case OBS_KEY_0x52:
  692. return 0x52;
  693. case OBS_KEY_0x53:
  694. return 0x53;
  695. case OBS_KEY_0x54:
  696. return 0x54;
  697. case OBS_KEY_0x55:
  698. return 0x55;
  699. case OBS_KEY_0x56:
  700. return 0x56;
  701. case OBS_KEY_0x57:
  702. return 0x57;
  703. case OBS_KEY_0x58:
  704. return 0x58;
  705. case OBS_KEY_0x59:
  706. return 0x59;
  707. case OBS_KEY_0x5A:
  708. return 0x5A;
  709. case OBS_KEY_VK_LWIN:
  710. return VK_LWIN;
  711. case OBS_KEY_VK_RWIN:
  712. return VK_RWIN;
  713. case OBS_KEY_VK_APPS:
  714. return VK_APPS;
  715. case OBS_KEY_0x5E:
  716. return 0x5E;
  717. case OBS_KEY_VK_SLEEP:
  718. return VK_SLEEP;
  719. case OBS_KEY_VK_SEPARATOR:
  720. return VK_SEPARATOR;
  721. case OBS_KEY_0x88:
  722. return 0x88;
  723. case OBS_KEY_0x89:
  724. return 0x89;
  725. case OBS_KEY_0x8A:
  726. return 0x8A;
  727. case OBS_KEY_0x8B:
  728. return 0x8B;
  729. case OBS_KEY_0x8C:
  730. return 0x8C;
  731. case OBS_KEY_0x8D:
  732. return 0x8D;
  733. case OBS_KEY_0x8E:
  734. return 0x8E;
  735. case OBS_KEY_0x8F:
  736. return 0x8F;
  737. case OBS_KEY_VK_OEM_FJ_JISHO:
  738. return VK_OEM_FJ_JISHO;
  739. case OBS_KEY_VK_OEM_FJ_LOYA:
  740. return VK_OEM_FJ_LOYA;
  741. case OBS_KEY_VK_OEM_FJ_ROYA:
  742. return VK_OEM_FJ_ROYA;
  743. case OBS_KEY_0x97:
  744. return 0x97;
  745. case OBS_KEY_0x98:
  746. return 0x98;
  747. case OBS_KEY_0x99:
  748. return 0x99;
  749. case OBS_KEY_0x9A:
  750. return 0x9A;
  751. case OBS_KEY_0x9B:
  752. return 0x9B;
  753. case OBS_KEY_0x9C:
  754. return 0x9C;
  755. case OBS_KEY_0x9D:
  756. return 0x9D;
  757. case OBS_KEY_0x9E:
  758. return 0x9E;
  759. case OBS_KEY_0x9F:
  760. return 0x9F;
  761. case OBS_KEY_VK_LSHIFT:
  762. return VK_LSHIFT;
  763. case OBS_KEY_VK_RSHIFT:
  764. return VK_RSHIFT;
  765. case OBS_KEY_VK_LCONTROL:
  766. return VK_LCONTROL;
  767. case OBS_KEY_VK_RCONTROL:
  768. return VK_RCONTROL;
  769. case OBS_KEY_VK_LMENU:
  770. return VK_LMENU;
  771. case OBS_KEY_VK_RMENU:
  772. return VK_RMENU;
  773. case OBS_KEY_VK_BROWSER_BACK:
  774. return VK_BROWSER_BACK;
  775. case OBS_KEY_VK_BROWSER_FORWARD:
  776. return VK_BROWSER_FORWARD;
  777. case OBS_KEY_VK_BROWSER_REFRESH:
  778. return VK_BROWSER_REFRESH;
  779. case OBS_KEY_VK_BROWSER_STOP:
  780. return VK_BROWSER_STOP;
  781. case OBS_KEY_VK_BROWSER_SEARCH:
  782. return VK_BROWSER_SEARCH;
  783. case OBS_KEY_VK_BROWSER_FAVORITES:
  784. return VK_BROWSER_FAVORITES;
  785. case OBS_KEY_VK_BROWSER_HOME:
  786. return VK_BROWSER_HOME;
  787. case OBS_KEY_VK_VOLUME_MUTE:
  788. return VK_VOLUME_MUTE;
  789. case OBS_KEY_VK_VOLUME_DOWN:
  790. return VK_VOLUME_DOWN;
  791. case OBS_KEY_VK_VOLUME_UP:
  792. return VK_VOLUME_UP;
  793. case OBS_KEY_VK_MEDIA_NEXT_TRACK:
  794. return VK_MEDIA_NEXT_TRACK;
  795. case OBS_KEY_VK_MEDIA_PREV_TRACK:
  796. return VK_MEDIA_PREV_TRACK;
  797. case OBS_KEY_VK_MEDIA_STOP:
  798. return VK_MEDIA_STOP;
  799. case OBS_KEY_VK_MEDIA_PLAY_PAUSE:
  800. return VK_MEDIA_PLAY_PAUSE;
  801. case OBS_KEY_VK_LAUNCH_MAIL:
  802. return VK_LAUNCH_MAIL;
  803. case OBS_KEY_VK_LAUNCH_MEDIA_SELECT:
  804. return VK_LAUNCH_MEDIA_SELECT;
  805. case OBS_KEY_VK_LAUNCH_APP1:
  806. return VK_LAUNCH_APP1;
  807. case OBS_KEY_VK_LAUNCH_APP2:
  808. return VK_LAUNCH_APP2;
  809. case OBS_KEY_0xB8:
  810. return 0xB8;
  811. case OBS_KEY_0xB9:
  812. return 0xB9;
  813. case OBS_KEY_0xC1:
  814. return 0xC1;
  815. case OBS_KEY_0xC2:
  816. return 0xC2;
  817. case OBS_KEY_0xC3:
  818. return 0xC3;
  819. case OBS_KEY_0xC4:
  820. return 0xC4;
  821. case OBS_KEY_0xC5:
  822. return 0xC5;
  823. case OBS_KEY_0xC6:
  824. return 0xC6;
  825. case OBS_KEY_0xC7:
  826. return 0xC7;
  827. case OBS_KEY_0xC8:
  828. return 0xC8;
  829. case OBS_KEY_0xC9:
  830. return 0xC9;
  831. case OBS_KEY_0xCA:
  832. return 0xCA;
  833. case OBS_KEY_0xCB:
  834. return 0xCB;
  835. case OBS_KEY_0xCC:
  836. return 0xCC;
  837. case OBS_KEY_0xCD:
  838. return 0xCD;
  839. case OBS_KEY_0xCE:
  840. return 0xCE;
  841. case OBS_KEY_0xCF:
  842. return 0xCF;
  843. case OBS_KEY_0xD0:
  844. return 0xD0;
  845. case OBS_KEY_0xD1:
  846. return 0xD1;
  847. case OBS_KEY_0xD2:
  848. return 0xD2;
  849. case OBS_KEY_0xD3:
  850. return 0xD3;
  851. case OBS_KEY_0xD4:
  852. return 0xD4;
  853. case OBS_KEY_0xD5:
  854. return 0xD5;
  855. case OBS_KEY_0xD6:
  856. return 0xD6;
  857. case OBS_KEY_0xD7:
  858. return 0xD7;
  859. case OBS_KEY_0xD8:
  860. return 0xD8;
  861. case OBS_KEY_0xD9:
  862. return 0xD9;
  863. case OBS_KEY_0xDA:
  864. return 0xDA;
  865. case OBS_KEY_VK_OEM_8:
  866. return VK_OEM_8;
  867. case OBS_KEY_0xE0:
  868. return 0xE0;
  869. case OBS_KEY_VK_OEM_AX:
  870. return VK_OEM_AX;
  871. case OBS_KEY_VK_ICO_HELP:
  872. return VK_ICO_HELP;
  873. case OBS_KEY_VK_ICO_00:
  874. return VK_ICO_00;
  875. case OBS_KEY_VK_PROCESSKEY:
  876. return VK_PROCESSKEY;
  877. case OBS_KEY_VK_ICO_CLEAR:
  878. return VK_ICO_CLEAR;
  879. case OBS_KEY_VK_PACKET:
  880. return VK_PACKET;
  881. case OBS_KEY_0xE8:
  882. return 0xE8;
  883. case OBS_KEY_VK_OEM_RESET:
  884. return VK_OEM_RESET;
  885. case OBS_KEY_VK_OEM_JUMP:
  886. return VK_OEM_JUMP;
  887. case OBS_KEY_VK_OEM_PA1:
  888. return VK_OEM_PA1;
  889. case OBS_KEY_VK_OEM_PA2:
  890. return VK_OEM_PA2;
  891. case OBS_KEY_VK_OEM_PA3:
  892. return VK_OEM_PA3;
  893. case OBS_KEY_VK_OEM_WSCTRL:
  894. return VK_OEM_WSCTRL;
  895. case OBS_KEY_VK_OEM_CUSEL:
  896. return VK_OEM_CUSEL;
  897. case OBS_KEY_VK_OEM_ATTN:
  898. return VK_OEM_ATTN;
  899. case OBS_KEY_VK_OEM_FINISH:
  900. return VK_OEM_FINISH;
  901. case OBS_KEY_VK_OEM_COPY:
  902. return VK_OEM_COPY;
  903. case OBS_KEY_VK_OEM_AUTO:
  904. return VK_OEM_AUTO;
  905. case OBS_KEY_VK_OEM_ENLW:
  906. return VK_OEM_ENLW;
  907. case OBS_KEY_VK_ATTN:
  908. return VK_ATTN;
  909. case OBS_KEY_VK_CRSEL:
  910. return VK_CRSEL;
  911. case OBS_KEY_VK_EXSEL:
  912. return VK_EXSEL;
  913. case OBS_KEY_VK_EREOF:
  914. return VK_EREOF;
  915. case OBS_KEY_VK_PLAY:
  916. return VK_PLAY;
  917. case OBS_KEY_VK_ZOOM:
  918. return VK_ZOOM;
  919. case OBS_KEY_VK_NONAME:
  920. return VK_NONAME;
  921. case OBS_KEY_VK_PA1:
  922. return VK_PA1;
  923. case OBS_KEY_VK_OEM_CLEAR:
  924. return VK_OEM_CLEAR;
  925. /* TODO: Implement keys for non-US keyboards */
  926. default:;
  927. }
  928. return 0;
  929. }
  930. bool obs_hotkeys_platform_init(struct obs_core_hotkeys *hotkeys)
  931. {
  932. hotkeys->platform_context = bzalloc(sizeof(obs_hotkeys_platform_t));
  933. for (size_t i = 0; i < OBS_KEY_LAST_VALUE; i++)
  934. hotkeys->platform_context->vk_codes[i] = get_virtual_key(i);
  935. return true;
  936. }
  937. void obs_hotkeys_platform_free(struct obs_core_hotkeys *hotkeys)
  938. {
  939. bfree(hotkeys->platform_context);
  940. hotkeys->platform_context = NULL;
  941. }
  942. static bool vk_down(DWORD vk)
  943. {
  944. short state = GetAsyncKeyState(vk);
  945. bool down = (state & 0x8000) != 0;
  946. return down;
  947. }
  948. bool obs_hotkeys_platform_is_pressed(obs_hotkeys_platform_t *context,
  949. obs_key_t key)
  950. {
  951. if (key == OBS_KEY_META) {
  952. return vk_down(VK_LWIN) || vk_down(VK_RWIN);
  953. }
  954. UNUSED_PARAMETER(context);
  955. return vk_down(obs_key_to_virtual_key(key));
  956. }
  957. void obs_key_to_str(obs_key_t key, struct dstr *str)
  958. {
  959. wchar_t name[128] = L"";
  960. UINT scan_code;
  961. int vk;
  962. if (key == OBS_KEY_NONE) {
  963. return;
  964. } else if (key >= OBS_KEY_F13 && key <= OBS_KEY_F24) {
  965. dstr_printf(str, "F%d", (int)(key - OBS_KEY_F13 + 13));
  966. return;
  967. } else if (key >= OBS_KEY_MOUSE1 && key <= OBS_KEY_MOUSE29) {
  968. if (obs->hotkeys.translations[key]) {
  969. dstr_copy(str, obs->hotkeys.translations[key]);
  970. } else {
  971. dstr_printf(str, "Mouse %d",
  972. (int)(key - OBS_KEY_MOUSE1 + 1));
  973. }
  974. return;
  975. }
  976. if (key == OBS_KEY_PAUSE) {
  977. dstr_copy(str, obs_get_hotkey_translation(key, "Pause"));
  978. return;
  979. } else if (key == OBS_KEY_META) {
  980. dstr_copy(str, obs_get_hotkey_translation(key, "Windows"));
  981. return;
  982. }
  983. vk = obs_key_to_virtual_key(key);
  984. scan_code = MapVirtualKey(vk, 0) << 16;
  985. switch (vk) {
  986. case VK_HOME:
  987. case VK_END:
  988. case VK_LEFT:
  989. case VK_UP:
  990. case VK_RIGHT:
  991. case VK_DOWN:
  992. case VK_PRIOR:
  993. case VK_NEXT:
  994. case VK_INSERT:
  995. case VK_DELETE:
  996. case VK_NUMLOCK:
  997. scan_code |= 0x01000000;
  998. }
  999. if ((key < OBS_KEY_VK_CANCEL || key > OBS_KEY_VK_OEM_CLEAR) &&
  1000. scan_code != 0 && GetKeyNameTextW(scan_code, name, 128) != 0) {
  1001. dstr_from_wcs(str, name);
  1002. } else if (key != OBS_KEY_NONE) {
  1003. dstr_copy(str, obs_key_to_name(key));
  1004. }
  1005. }
  1006. obs_key_t obs_key_from_virtual_key(int code)
  1007. {
  1008. obs_hotkeys_platform_t *platform = obs->hotkeys.platform_context;
  1009. for (size_t i = 0; i < OBS_KEY_LAST_VALUE; i++) {
  1010. if (platform->vk_codes[i] == code) {
  1011. return (obs_key_t)i;
  1012. }
  1013. }
  1014. return OBS_KEY_NONE;
  1015. }
  1016. int obs_key_to_virtual_key(obs_key_t key)
  1017. {
  1018. if (key == OBS_KEY_META)
  1019. return VK_LWIN;
  1020. return obs->hotkeys.platform_context->vk_codes[(int)key];
  1021. }
  1022. static inline void add_combo_key(obs_key_t key, struct dstr *str)
  1023. {
  1024. struct dstr key_str = {0};
  1025. obs_key_to_str(key, &key_str);
  1026. if (!dstr_is_empty(&key_str)) {
  1027. if (!dstr_is_empty(str)) {
  1028. dstr_cat(str, " + ");
  1029. }
  1030. dstr_cat_dstr(str, &key_str);
  1031. }
  1032. dstr_free(&key_str);
  1033. }
  1034. void obs_key_combination_to_str(obs_key_combination_t combination,
  1035. struct dstr *str)
  1036. {
  1037. if ((combination.modifiers & INTERACT_CONTROL_KEY) != 0) {
  1038. add_combo_key(OBS_KEY_CONTROL, str);
  1039. }
  1040. if ((combination.modifiers & INTERACT_COMMAND_KEY) != 0) {
  1041. add_combo_key(OBS_KEY_META, str);
  1042. }
  1043. if ((combination.modifiers & INTERACT_ALT_KEY) != 0) {
  1044. add_combo_key(OBS_KEY_ALT, str);
  1045. }
  1046. if ((combination.modifiers & INTERACT_SHIFT_KEY) != 0) {
  1047. add_combo_key(OBS_KEY_SHIFT, str);
  1048. }
  1049. if (combination.key != OBS_KEY_NONE) {
  1050. add_combo_key(combination.key, str);
  1051. }
  1052. }
  1053. bool sym_initialize_called = false;
  1054. void reset_win32_symbol_paths(void)
  1055. {
  1056. static BOOL(WINAPI * sym_initialize_w)(HANDLE, const wchar_t *, BOOL);
  1057. static BOOL(WINAPI * sym_set_search_path_w)(HANDLE, const wchar_t *);
  1058. static bool funcs_initialized = false;
  1059. static bool initialize_success = false;
  1060. struct obs_module *module = obs->first_module;
  1061. struct dstr path_str = {0};
  1062. DARRAY(char *) paths;
  1063. wchar_t *path_str_w = NULL;
  1064. char *abspath;
  1065. da_init(paths);
  1066. if (!funcs_initialized) {
  1067. HMODULE mod;
  1068. funcs_initialized = true;
  1069. mod = LoadLibraryW(L"DbgHelp");
  1070. if (!mod)
  1071. return;
  1072. sym_initialize_w =
  1073. (void *)GetProcAddress(mod, "SymInitializeW");
  1074. sym_set_search_path_w =
  1075. (void *)GetProcAddress(mod, "SymSetSearchPathW");
  1076. if (!sym_initialize_w || !sym_set_search_path_w) {
  1077. FreeLibrary(mod);
  1078. return;
  1079. }
  1080. initialize_success = true;
  1081. // Leaks 'mod' once.
  1082. }
  1083. if (!initialize_success)
  1084. return;
  1085. abspath = os_get_abs_path_ptr(".");
  1086. if (abspath)
  1087. da_push_back(paths, &abspath);
  1088. while (module) {
  1089. bool found = false;
  1090. struct dstr path = {0};
  1091. char *path_end;
  1092. dstr_copy(&path, module->bin_path);
  1093. dstr_replace(&path, "/", "\\");
  1094. path_end = strrchr(path.array, '\\');
  1095. if (!path_end) {
  1096. module = module->next;
  1097. dstr_free(&path);
  1098. continue;
  1099. }
  1100. *path_end = 0;
  1101. for (size_t i = 0; i < paths.num; i++) {
  1102. const char *existing_path = paths.array[i];
  1103. if (astrcmpi(path.array, existing_path) == 0) {
  1104. found = true;
  1105. break;
  1106. }
  1107. }
  1108. if (!found) {
  1109. abspath = os_get_abs_path_ptr(path.array);
  1110. if (abspath)
  1111. da_push_back(paths, &abspath);
  1112. }
  1113. dstr_free(&path);
  1114. module = module->next;
  1115. }
  1116. for (size_t i = 0; i < paths.num; i++) {
  1117. const char *path = paths.array[i];
  1118. if (path && *path) {
  1119. if (i != 0)
  1120. dstr_cat(&path_str, ";");
  1121. dstr_cat(&path_str, paths.array[i]);
  1122. }
  1123. }
  1124. if (path_str.array) {
  1125. os_utf8_to_wcs_ptr(path_str.array, path_str.len, &path_str_w);
  1126. if (path_str_w) {
  1127. if (!sym_initialize_called) {
  1128. sym_initialize_w(GetCurrentProcess(),
  1129. path_str_w, false);
  1130. sym_initialize_called = true;
  1131. } else {
  1132. sym_set_search_path_w(GetCurrentProcess(),
  1133. path_str_w);
  1134. }
  1135. bfree(path_str_w);
  1136. }
  1137. }
  1138. for (size_t i = 0; i < paths.num; i++)
  1139. bfree(paths.array[i]);
  1140. dstr_free(&path_str);
  1141. da_free(paths);
  1142. }
  1143. extern void initialize_crash_handler(void);
  1144. void obs_init_win32_crash_handler(void)
  1145. {
  1146. initialize_crash_handler();
  1147. }
  1148. bool initialize_com(void)
  1149. {
  1150. const HRESULT hr = CoInitializeEx(0, COINIT_APARTMENTTHREADED);
  1151. const bool success = SUCCEEDED(hr);
  1152. if (!success)
  1153. blog(LOG_ERROR, "CoInitializeEx failed: 0x%08X", hr);
  1154. return success;
  1155. }
  1156. void uninitialize_com(void)
  1157. {
  1158. CoUninitialize();
  1159. }