| 52 | #define BOOLEAN_COMMAND_LINE_ARG_MISSING_VALUE L"value-not-specified" |
| 53 | |
| 54 | bool ExtractResource(unsigned short resource_id, |
| 55 | const std::wstring& output_file_name) { |
| 56 | bool success = false; |
| 57 | try { |
| 58 | // First find and load the required resource |
| 59 | HRSRC resource_handle = ::FindResource(NULL, |
| 60 | MAKEINTRESOURCE(resource_id), |
| 61 | RESOURCE_TYPE); |
| 62 | HGLOBAL global_resouce_handle = ::LoadResource(NULL, resource_handle); |
| 63 | |
| 64 | // Now open and map this to a disk file |
| 65 | LPVOID file_pointer = ::LockResource(global_resouce_handle); |
| 66 | DWORD resource_size = ::SizeofResource(NULL, resource_handle); |
| 67 | |
| 68 | // Open the file and filemap |
| 69 | HANDLE file_handle = ::CreateFile(output_file_name.c_str(), |
| 70 | GENERIC_READ | GENERIC_WRITE, |
| 71 | 0, |
| 72 | NULL, |
| 73 | CREATE_ALWAYS, |
| 74 | FILE_ATTRIBUTE_NORMAL, |
| 75 | NULL); |
| 76 | HANDLE file_mapping_handle = ::CreateFileMapping(file_handle, |
| 77 | NULL, |
| 78 | PAGE_READWRITE, |
| 79 | 0, |
| 80 | resource_size, |
| 81 | NULL); |
| 82 | LPVOID base_address_pointer = ::MapViewOfFile(file_mapping_handle, |
| 83 | FILE_MAP_WRITE, |
| 84 | 0, |
| 85 | 0, |
| 86 | 0); |
| 87 | |
| 88 | // Write the file |
| 89 | ::CopyMemory(base_address_pointer, file_pointer, resource_size); |
| 90 | |
| 91 | // Unmap the file and close the handles |
| 92 | ::UnmapViewOfFile(base_address_pointer); |
| 93 | ::CloseHandle(file_mapping_handle); |
| 94 | ::CloseHandle(file_handle); |
| 95 | success = true; |
| 96 | } catch(...) { |
| 97 | // Ignore all type of errors |
| 98 | } |
| 99 | return success; |
| 100 | } |
| 101 | |
| 102 | std::wstring GetProcessArchitectureDescription() { |
| 103 | std::wstring arch_description = L"32-bit"; |