1 // 2 // GetModuleFileNameA.cpp 3 // 4 // Copyright (c) Microsoft Corporation. All rights reserved. 5 // 6 // Definition of __acrt_GetModuleFileNameA. 7 // 8 9 #include <corecrt_internal_win32_buffer.h> 10 11 DWORD __cdecl __acrt_GetModuleFileNameA( 12 HMODULE const hModule, 13 char * const lpFilename, 14 DWORD const nSize 15 ) 16 { 17 size_t const wide_buffer_size = MAX_PATH + 1; 18 wchar_t wide_buffer[wide_buffer_size]; 19 20 DWORD const amount_copied = GetModuleFileNameW( 21 hModule, 22 wide_buffer, 23 wide_buffer_size 24 ); 25 26 if (amount_copied == 0) { 27 __acrt_errno_map_os_error(GetLastError()); 28 return 0; 29 } 30 31 __crt_no_alloc_win32_buffer<char> filename_buffer(lpFilename, static_cast<size_t>(nSize)); 32 33 errno_t const cvt = __acrt_wcs_to_mbs_cp( 34 wide_buffer, 35 filename_buffer, 36 __acrt_get_utf8_acp_compatibility_codepage() 37 ); 38 39 return static_cast<DWORD>(filename_buffer.size()); 40 } 41