| 277 | |
| 278 | #[pyfunction] |
| 279 | fn ConnectRegistry( |
| 280 | computer_name: Option<String>, |
| 281 | key: PyRef<PyHkey>, |
| 282 | vm: &VirtualMachine, |
| 283 | ) -> PyResult<PyHkey> { |
| 284 | if let Some(computer_name) = computer_name { |
| 285 | let mut ret_key = core::ptr::null_mut(); |
| 286 | let wide_computer_name = computer_name.to_wide_with_nul(); |
| 287 | let res = unsafe { |
| 288 | Registry::RegConnectRegistryW( |
| 289 | wide_computer_name.as_ptr(), |
| 290 | key.hkey.load(), |
| 291 | &mut ret_key, |
| 292 | ) |
| 293 | }; |
| 294 | if res == 0 { |
| 295 | Ok(PyHkey::new(ret_key)) |
| 296 | } else { |
| 297 | Err(vm.new_os_error(format!("error code: {res}"))) |
| 298 | } |
| 299 | } else { |
| 300 | let mut ret_key = core::ptr::null_mut(); |
| 301 | let res = unsafe { |
| 302 | Registry::RegConnectRegistryW(core::ptr::null_mut(), key.hkey.load(), &mut ret_key) |
| 303 | }; |
| 304 | if res == 0 { |
| 305 | Ok(PyHkey::new(ret_key)) |
| 306 | } else { |
| 307 | Err(vm.new_os_error(format!("error code: {res}"))) |
| 308 | } |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | #[pyfunction] |
| 313 | fn CreateKey(key: PyRef<PyHkey>, sub_key: String, vm: &VirtualMachine) -> PyResult<PyHkey> { |