Refactored not to expose raw pointers on ProxyList class.
[chromium-blink-merge.git] / base / win / resource_util.cc
blob0c100785e7bef69a20cd8b8942d9e8693555ba91
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/logging.h"
6 #include "base/win/resource_util.h"
8 namespace base {
9 namespace win {
11 bool GetResourceFromModule(HMODULE module,
12 int resource_id,
13 LPCTSTR resource_type,
14 void** data,
15 size_t* length) {
16 if (!module)
17 return false;
19 if (!IS_INTRESOURCE(resource_id)) {
20 NOTREACHED();
21 return false;
24 HRSRC hres_info = FindResource(module, MAKEINTRESOURCE(resource_id),
25 resource_type);
26 if (NULL == hres_info)
27 return false;
29 DWORD data_size = SizeofResource(module, hres_info);
30 HGLOBAL hres = LoadResource(module, hres_info);
31 if (!hres)
32 return false;
34 void* resource = LockResource(hres);
35 if (!resource)
36 return false;
38 *data = resource;
39 *length = static_cast<size_t>(data_size);
40 return true;
43 bool GetDataResourceFromModule(HMODULE module,
44 int resource_id,
45 void** data,
46 size_t* length) {
47 return GetResourceFromModule(module, resource_id, L"BINDATA", data, length);
50 } // namespace win
51 } // namespace base