Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RegOpenKeyEx doesn’t work #47

Closed
Hawk777 opened this issue Nov 6, 2022 · 0 comments
Closed

RegOpenKeyEx doesn’t work #47

Hawk777 opened this issue Nov 6, 2022 · 0 comments
Assignees
Labels
bindings Something with the low-level WinAPI bidings bug Something isn't working

Comments

@Hawk777
Copy link

Hawk777 commented Nov 6, 2022

RegOpenKeyEx always returns a null HKEYon success. The problem is that a null HKEY is constructed, then hKey.as_ptr() is passed into the raw function, which means it will store the newly opened HKEY into wherever hKey pointed at, which is null, rather than into hKey itself. I changed the function to look like this and it now works, but I imagine raw types like c_void probably aren’t supposed to appear here; I just don’t really quite understand all the type aliases so it was the fastest and simplest fix I could come up with:

	fn RegOpenKeyEx(self, sub_key: &str,
		options: co::REG_OPTION, access_rights: co::KEY) -> SysResult<HKEY>
	{
		let mut hKey: *mut std::ffi::c_void = std::ptr::null_mut();

		match co::ERROR(
			unsafe {
				advapi::ffi::RegOpenKeyExW(
					self.as_ptr(),
					WString::from_str(sub_key).as_ptr(),
					options.0,
					access_rights.0,
					&mut hKey as _,
				)
			} as _,
		) {
			co::ERROR::SUCCESS => Ok(unsafe { HKEY::from_ptr(hKey) }),
			err => Err(err),
		}
	}
@rodrigocfd rodrigocfd self-assigned this Nov 6, 2022
@rodrigocfd rodrigocfd added the bug Something isn't working label Nov 6, 2022
@rodrigocfd rodrigocfd added the bindings Something with the low-level WinAPI bidings label Jan 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bindings Something with the low-level WinAPI bidings bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants