MCPcopy Index your code
hub / github.com/RustPython/RustPython / ConnectRegistry

Function ConnectRegistry

crates/vm/src/stdlib/winreg.rs:279–310  ·  view source on GitHub ↗
(
        computer_name: Option<String>,
        key: PyRef<PyHkey>,
        vm: &VirtualMachine,
    )

Source from the content-addressed store, hash-verified

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> {

Calls 6

newFunction · 0.85
to_wide_with_nulMethod · 0.80
new_os_errorMethod · 0.80
ErrClass · 0.50
as_ptrMethod · 0.45
loadMethod · 0.45