Improve performance of registering font preferences
[chromium-blink-merge.git] / base / win / resource_util.cc
blobde9f5833924f48cb6270dafb559472278179e6d7
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 {
10 bool GetDataResourceFromModule(HMODULE module, int resource_id,
11 void** data, size_t* length) {
12 if (!module)
13 return false;
15 if (!IS_INTRESOURCE(resource_id)) {
16 NOTREACHED();
17 return false;
20 HRSRC hres_info = FindResource(module, MAKEINTRESOURCE(resource_id),
21 L"BINDATA");
22 if (NULL == hres_info)
23 return false;
25 DWORD data_size = SizeofResource(module, hres_info);
26 HGLOBAL hres = LoadResource(module, hres_info);
27 if (!hres)
28 return false;
30 void* resource = LockResource(hres);
31 if (!resource)
32 return false;
34 *data = resource;
35 *length = static_cast<size_t>(data_size);
36 return true;
38 } // namespace win
39 } // namespace base