forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathresource_util.cc
35 lines (26 loc) · 1.02 KB
/
resource_util.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/chrome_cleaner/os/resource_util.h"
#include <windows.h>
#include <stdint.h>
#include "base/check_op.h"
namespace chrome_cleaner {
bool LoadResourceOfKind(uint32_t resource_id,
const wchar_t* kind,
base::StringPiece* output) {
DCHECK(output);
HRSRC handle = ::FindResource(::GetModuleHandle(nullptr),
MAKEINTRESOURCE(resource_id), kind);
if (!handle)
return false;
HGLOBAL loaded_buffer = ::LoadResource(::GetModuleHandle(nullptr), handle);
DPCHECK(loaded_buffer);
LPVOID locked_buffer = ::LockResource(loaded_buffer);
DPCHECK(locked_buffer);
DWORD size = ::SizeofResource(::GetModuleHandle(nullptr), handle);
DCHECK_GT(size, 0U);
*output = base::StringPiece(reinterpret_cast<char*>(locked_buffer), size);
return true;
}
} // namespace chrome_cleaner