| 32 | } // namespace |
| 33 | |
| 34 | std::error_code LoadResourceData(HMODULE hModule, const std::wstring& name, LPCWSTR type, std::vector<uint8_t>& output) |
| 35 | { |
| 36 | std::error_code ec; |
| 37 | |
| 38 | HRSRC hResource = FindResourceW(hModule, name.c_str(), type); |
| 39 | if (!hResource) |
| 40 | { |
| 41 | ec = LastWin32Error(); |
| 42 | Log::Debug(L"Failed FindResourceW (name: {}) [{}]", name, ec); |
| 43 | return ec; |
| 44 | } |
| 45 | |
| 46 | HGLOBAL hLoaded = LoadResource(hModule, hResource); |
| 47 | if (!hLoaded) |
| 48 | { |
| 49 | ec = LastWin32Error(); |
| 50 | Log::Debug(L"Failed LoadResource (name: {}, type: {}) [{}]", name, type, ec); |
| 51 | return ec; |
| 52 | } |
| 53 | |
| 54 | DWORD size = SizeofResource(hModule, hResource); |
| 55 | if (size == 0) |
| 56 | { |
| 57 | ec = LastWin32Error(); |
| 58 | Log::Debug(L"Failed SizeofResource (name: {}) [{}]", name, type, ec); |
| 59 | return ec; |
| 60 | } |
| 61 | |
| 62 | const void* pData = LockResource(hLoaded); |
| 63 | if (!pData) |
| 64 | { |
| 65 | return std::make_error_code(std::errc::bad_address); |
| 66 | } |
| 67 | |
| 68 | const auto* bytePtr = static_cast<const uint8_t*>(pData); |
| 69 | output.assign(bytePtr, bytePtr + size); |
| 70 | return {}; |
| 71 | } |
| 72 | |
| 73 | std::error_code |
| 74 | LoadResourceData(const fs::path& path, const std::wstring& name, LPCWSTR type, std::vector<uint8_t>& output) |
no test coverage detected