1 // Copyright 2006-2008 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/win/resource_util.h"
6 #include "base/notreached.h"
7
8 namespace base {
9 namespace win {
10
GetResourceFromModule(HMODULE module,int resource_id,LPCTSTR resource_type,void ** data,size_t * length)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;
18
19 if (!IS_INTRESOURCE(resource_id)) {
20 NOTREACHED();
21 }
22
23 HRSRC hres_info =
24 FindResource(module, MAKEINTRESOURCE(resource_id), resource_type);
25 if (nullptr == hres_info)
26 return false;
27
28 DWORD data_size = SizeofResource(module, hres_info);
29 HGLOBAL hres = LoadResource(module, hres_info);
30 if (!hres)
31 return false;
32
33 void* resource = LockResource(hres);
34 if (!resource)
35 return false;
36
37 *data = resource;
38 *length = static_cast<size_t>(data_size);
39 return true;
40 }
41
GetDataResourceFromModule(HMODULE module,int resource_id,void ** data,size_t * length)42 bool GetDataResourceFromModule(HMODULE module,
43 int resource_id,
44 void** data,
45 size_t* length) {
46 return GetResourceFromModule(module, resource_id, L"BINDATA", data, length);
47 }
48
49 } // namespace win
50 } // namespace base
51