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

findInstancesDirViaCLSID

Private Function
std.zig.WindowsSdk.MsvcLibDir.findInstancesDirViaCLSID
fn findInstancesDirViaCLSID(gpa: Allocator, io: Io, registry: *Registry) error

Params

File

zig/WindowsSdk.zig:679
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
    fn findInstancesDirViaCLSID(gpa: Allocator, io: Io, registry: *Registry) error{ OutOfMemory, PathNotFound }!Dir {
        const setup_configuration_clsid = "{177f0c4a-1cd3-4de7-a32c-71dbbb9fa36d}";

        // HKEY_CLASSES_ROOT is not a single key but instead a combination of
        // HKCU\Software\Classes and HKLM\Software\Classes with HKCU taking precedent
        // https://learn.microsoft.com/en-us/windows/win32/sysinfo/hkey-classes-root-key
        //
        // Instead of a CLASSES_ROOT abstraction, we emulate the behavior with a more
        // general abstraction, which also means we need to include `Classes` in the path since
        // we're starting from the `Software` keys instead of the "classes root".
        //
        // The advapi32 APIs with `HKEY_CLASSES_ROOT` go through `\REGISTRY\USER\<SID>_Classes`
        // instead of `\REGISTRY\USER\<SID>\Software\Classes`, but we go through the latter
        // because it allows us to take advantage of `RtlOpenCurrentUser` to avoid needing to implement
        // the logic for getting the current user registry path, and it appears that the two keys are
        // effectively equivalent. Further investigation of the relationship of these keys would probably
        // be beneficial, though.
        const setup_config_key = registry.tryOpenSoftwareKeyWithPrecedence(&.{
            .{ .root = .current_user },
            .{ .root = .local_machine },
        }, L("Classes\\CLSID\\" ++ setup_configuration_clsid)) catch |err| switch (err) {
            error.KeyNotFound => return error.PathNotFound,
        };
        defer setup_config_key.close();

        const inproc_server = setup_config_key.open(L("InprocServer32")) catch return error.PathNotFound;
        const dll_path = inproc_server.getString(gpa, .default, .wtf8) catch |err| switch (err) {
            error.NotAString,
            error.ValueNameNotFound,
            error.StringNotFound,
            => return error.PathNotFound,

            error.OutOfMemory => |e| return e,
        };
        defer gpa.free(dll_path);

        if (!std.fs.path.isAbsolute(dll_path)) return error.PathNotFound;

        var path_it = std.fs.path.componentIterator(dll_path);
        // the .dll filename
        _ = path_it.last();
        const root_path = while (path_it.previous()) |dir_component| {
            if (std.ascii.eqlIgnoreCase(dir_component.name, "VisualStudio")) {
                break dir_component.path;
            }
        } else {
            return error.PathNotFound;
        };

        const instances_path = try std.fs.path.join(gpa, &.{ root_path, "Packages", "_Instances" });
        defer gpa.free(instances_path);

        return Dir.openDirAbsolute(io, instances_path, .{ .iterate = true }) catch return error.PathNotFound;
    }