summaryrefslogtreecommitdiffstats
path: root/base/win/resource_util.cc
blob: 0c100785e7bef69a20cd8b8942d9e8693555ba91 (plain)
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright (c) 2006-2008 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 "base/logging.h"
#include "base/win/resource_util.h"

namespace base {
namespace win {

bool GetResourceFromModule(HMODULE module,
                           int resource_id,
                           LPCTSTR resource_type,
                           void** data,
                           size_t* length) {
  if (!module)
    return false;

  if (!IS_INTRESOURCE(resource_id)) {
    NOTREACHED();
    return false;
  }

  HRSRC hres_info = FindResource(module, MAKEINTRESOURCE(resource_id),
                                 resource_type);
  if (NULL == hres_info)
    return false;

  DWORD data_size = SizeofResource(module, hres_info);
  HGLOBAL hres = LoadResource(module, hres_info);
  if (!hres)
    return false;

  void* resource = LockResource(hres);
  if (!resource)
    return false;

  *data = resource;
  *length = static_cast<size_t>(data_size);
  return true;
}

bool GetDataResourceFromModule(HMODULE module,
                               int resource_id,
                               void** data,
                               size_t* length) {
  return GetResourceFromModule(module, resource_id, L"BINDATA", data, length);
}

}  // namespace win
}  // namespace base