Zig 0.17.0-dev (Split by item)

Shortcut keys
?
Show these tips
S
Focus search field
Esc
Clear focus & close tips
U
Jump to source code
↑
Move up in search results
↓
Move down in search results
↵
Go to active search result
This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig standard library. Private Function

getOrOpenKey

Private Function
std.zig.WindowsSdk.Registry.Software.getOrOpenKey
fn getOrOpenKey(self: Software, registry: *Registry) !Key

Params

File

zig/WindowsSdk.zig:233
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
        fn getOrOpenKey(self: Software, registry: *Registry) !Key {
            if (registry.cache.getSoftware(self)) |handle| {
                return .{ .handle = handle };
            }

            const is_foreign = !is_32_bit and self.wow64 == .wow64_32;
            switch (self.root) {
                .local_machine => {
                    const path = if (is_foreign) L("\\Registry\\Machine\\Software\\WOW6432Node") else L("\\Registry\\Machine\\Software");
                    var key: Key = undefined;
                    const attr: windows.OBJECT.ATTRIBUTES = .{
                        .RootDirectory = null,
                        .Attributes = .{},
                        .ObjectName = @constCast(&windows.UNICODE_STRING.init(path)),
                        .SecurityDescriptor = null,
                        .SecurityQualityOfService = null,
                    };
                    const status = windows.ntdll.NtOpenKeyEx(
                        &key.handle,
                        .{ .MAXIMUM_ALLOWED = true },
                        &attr,
                        .{},
                    );
                    switch (status) {
                        .SUCCESS => {},
                        else => return error.KeyNotFound,
                    }
                    if (is_foreign) {
                        registry.cache.hklm_software_foreign = key.handle;
                    } else {
                        registry.cache.hklm_software_native = key.handle;
                    }
                    return key;
                },
                .current_user => {
                    const cu_handle: windows.HANDLE = registry.cache.hkcu orelse hkcu: {
                        var cu_handle: windows.HANDLE = undefined;
                        const status = windows.ntdll.RtlOpenCurrentUser(
                            .{ .MAXIMUM_ALLOWED = true },
                            &cu_handle,
                        );
                        switch (status) {
                            .SUCCESS => {},
                            else => return error.KeyNotFound,
                        }
                        registry.cache.hkcu = cu_handle;
                        break :hkcu cu_handle;
                    };
                    const cu_key: Registry.Key = .{ .handle = cu_handle };
                    const path = if (is_foreign) L("Software\\WOW6432Node") else L("Software");
                    const key = try cu_key.open(path);
                    if (is_foreign) {
                        registry.cache.hkcu_software_foreign = key.handle;
                    } else {
                        registry.cache.hkcu_software_native = key.handle;
                    }
                    return key;
                },
            }
        }