What can I do in my situation?
Implement an abstraction layer on top of the registry API and access the API through the abstraction layer. Then, inject an implementation into the code that needs registry access.
class SettingsStore {
public:
SettingsStore(const std::string&); // receive path or "unique key" for your settings
virtual ~SettingsStore() = 0;
virtual std::string GetValue(const std::string& key) = 0;
virtual void SetValue(const std::string& key, const std::string& value) = 0;
// ...
};
class RegistryStore: public SettingsStore {
public:
SettingsStore(const std::string&); // receive path or "unique key" for your settings
virtual ~SettingsStore();
// implement in terms of Windows Registry API
virtual std::string GetValue(const std::string& key) override;
virtual void SetValue(const std::string& key, const std::string& value) override;
// ...
private:
// registry handle here
};
After this, implement your code in terms of an injected SettingsStore reference.
Your test code then can depend on TestStore (that extends SettingsStore) or whatever.
In short:
I want to emulate the windows registry
I want to create a hook DLL, which will be injected into my own application
This sounds complicated (and similar to the x-y problem). Is it prohibitive for you to implement the solution above?