resource_util.cc 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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.
  4. #include "base/win/resource_util.h"
  5. #include "base/notreached.h"
  6. namespace base {
  7. namespace win {
  8. bool GetResourceFromModule(HMODULE module,
  9. int resource_id,
  10. LPCTSTR resource_type,
  11. void** data,
  12. size_t* length) {
  13. if (!module)
  14. return false;
  15. if (!IS_INTRESOURCE(resource_id)) {
  16. NOTREACHED();
  17. return false;
  18. }
  19. HRSRC hres_info =
  20. FindResource(module, MAKEINTRESOURCE(resource_id), resource_type);
  21. if (nullptr == hres_info)
  22. return false;
  23. DWORD data_size = SizeofResource(module, hres_info);
  24. HGLOBAL hres = LoadResource(module, hres_info);
  25. if (!hres)
  26. return false;
  27. void* resource = LockResource(hres);
  28. if (!resource)
  29. return false;
  30. *data = resource;
  31. *length = static_cast<size_t>(data_size);
  32. return true;
  33. }
  34. bool GetDataResourceFromModule(HMODULE module,
  35. int resource_id,
  36. void** data,
  37. size_t* length) {
  38. return GetResourceFromModule(module, resource_id, L"BINDATA", data, length);
  39. }
  40. } // namespace win
  41. } // namespace base