Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
WindowsResourceManager.cpp
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#include "Stroika/Foundation/StroikaPreComp.h"
5
6#include "Stroika/Foundation/Common/Common.h"
7#include "Stroika/Foundation/Execution/Resources/ResourceNotFoundException.h"
9
10#include "WindowsResourceManager.h"
11
12using namespace Stroika::Foundation;
13using namespace Stroika::Foundation::Execution;
14using namespace Stroika::Foundation::Execution::Resources;
15using namespace Stroika::Foundation::Execution::Resources::Concrete;
16
17class WindowsResourceManager::Rep_ final : public Manager::_IRep {
18private:
19 HMODULE fModule_;
20
21public:
22 Rep_ (HMODULE hModule)
23 : fModule_{hModule}
24 {
25 }
26 virtual Accessor ReadResource (const Name& name) const override
27 {
28 HRSRC hres = ::FindResource (fModule_, name.GetSDKString (), name.GetType ());
29 if (hres != nullptr) {
30 HGLOBAL lglbl = ::LoadResource (fModule_, hres);
31 if (lglbl != nullptr) {
32 const void* lr = ::LockResource (lglbl);
33 AssertNotNull (lr);
34 const byte* start = reinterpret_cast<const byte*> (lr);
35 return Manager::_mkAccessor (span{start, ::SizeofResource (fModule_, hres)});
36 }
37 }
38 Throw (ResourceNotFoundException::kThe);
39 }
40};
41
42/*
43********************************************************************************
44***************************** WindowsResourceManager ***************************
45********************************************************************************
46*/
47WindowsResourceManager::WindowsResourceManager (HMODULE hModule)
48 : Manager{make_shared<Rep_> (hModule)}
49{
50}
#define AssertNotNull(p)
Definition Assertions.h:333
void Throw(T &&e2Throw)
identical to builtin C++ 'throw' except that it does helpful, type dependent DbgTrace() messages firs...
Definition Throw.inl:43