license.bot | f003cfe | 2008-08-24 09:55:55 +0900 | [diff] [blame^] | 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. |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 4 | |
| 5 | #include "base/resource_util.h" |
| 6 | |
| 7 | #include "base/logging.h" |
| 8 | |
| 9 | namespace base { |
| 10 | bool GetDataResourceFromModule(HMODULE module, int resource_id, |
| 11 | void** data, size_t* length) { |
| 12 | if (!module) |
| 13 | return false; |
| 14 | |
| 15 | // Get a pointer to the data in the dll. |
| 16 | DCHECK(IS_INTRESOURCE(resource_id)); |
| 17 | HRSRC hres_info = FindResource(module, MAKEINTRESOURCE(resource_id), |
| 18 | L"BINDATA"); |
| 19 | if (NULL == hres_info) |
| 20 | return false; |
| 21 | |
| 22 | DWORD data_size = SizeofResource(module, hres_info); |
| 23 | |
| 24 | HGLOBAL hres = LoadResource(module, hres_info); |
| 25 | if (!hres_info) |
| 26 | return false; |
| 27 | |
| 28 | *data = LockResource(hres); |
| 29 | *length = static_cast<size_t>(data_size); |
| 30 | return true; |
| 31 | } |
| 32 | } // namespace |
license.bot | f003cfe | 2008-08-24 09:55:55 +0900 | [diff] [blame^] | 33 | |