obs-windows.c 28 KB

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