Windows Registry Access
A new module, wel-regedit-x.ecf, has been added to Eiffel-Loop libraries that provides a more abstract interface to the WEL classes for accessing/modifying the registry in Windows. The following examples illustrate it's use.
Example 1
The following code fragment illustrates iterating over the sub keys of a registry key (EL_ITERABLE_REGISTRY_KEYS) and accessing binary data. As it happens, only the first sub key is required in this instance. The code is part of a class for extracting the physical dimensions of the currently active display monitor.
class
EL_WEL_DISPLAY_MONITOR_INFO
inherit
EL_WEL_DISPLAY_MONITOR_API
undefine
default_create
end
EL_MODULE_WIN_REGISTRY
undefine
default_create
end
feature -- Access
model: STRING
-- Monitor model
-- Example: IVM5601
local
path_steps: EL_PATH_STEPS
do
-- Example device_id: "MONITOR\IVM5601\{4d36e96e-e325-11ce-bfc1-08002be10318}\0000"
path_steps := primary_device.device_id
Result := path_steps.i_th (2)
end
EDID: MANAGED_POINTER
-- Extended display identification data
-- See: http://en.wikipedia.org/wiki/Extended_display_identification_data
feature {NONE} -- Implementation
set_EDID_data
require
long_enough_device_id: primary_device.device_id.split ('\').count >= 2
local
EDID_registry_path: EL_DIR_PATH
display_keys: EL_ITERABLE_REGISTRY_KEYS
do
create display_keys.make (HKLM_enum_display.joined_dir_path (model))
across display_keys as key until key.cursor_index > 1 loop
EDID_registry_path := HKLM_enum_display.joined_dir_steps (<<
model, key.item.name.to_string_8, "Device Parameters"
>>)
end
EDID := Win_registry.data (EDID_registry_path, "EDID")
ensure
has_EDID_data: EDID.count > 0
end
feature {NONE} -- Constants
HKLM_enum_display: EL_DIR_PATH
once
Result := "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\DISPLAY"
end
end
Example 2
The following code adds some registry entries for applications that make use of the embedded browser provided by class EV_WEB_BROWSER. It prevents the browser from emulating an early version of IE provoking JavaScript errors. It illustrates setting an integer value (DWORD) and removing a key value.
class
EL_WEB_BROWSER_INSTALLER
inherit
EL_MODULE_WIN_REGISTRY
EL_MODULE_EXECUTION_ENVIRONMENT
feature -- Basic operations
install
do
Win_registry.set_integer (
HKLM_IE_feature_browser_emulation, Execution.executable_name, Internet_explorer_major_version * 1000 + 1
)
end
uninstall
do
Win_registry.remove_key_value (HKLM_IE_feature_browser_emulation, Execution.executable_name)
end
feature {NONE} -- Constants
Internet_explorer_major_version: INTEGER
local
version: EL_ASTRING
once
across << "svcVersion", "Version" >> as key_name until Result > 0 loop
version := Win_registry.string (HKLM_Internet_explorer, key_name.item)
if not version.is_empty then
Result := version.split ('.').first.to_integer
end
end
end
HKLM_Internet_explorer: EL_DIR_PATH
once
Result := "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer"
end
HKLM_IE_feature_browser_emulation: EL_DIR_PATH
once
Result := HKLM_Internet_explorer.joined_dir_path ("MAIN\FeatureControl\FEATURE_BROWSER_EMULATION")
end
end
Caveats
Unfortunately to use this module you have to compile the entire WEL GUI library even if you are only using it in a command line application. But if you have a decent PC it shouldn't be too noticeable.