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

Fix KnownFolder for x86 Windows #17705

Merged
merged 2 commits into from
Dec 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions src/Avalonia.Base/Platform/Storage/FileIO/BclStorageProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,29 +150,24 @@ string GetFromSpecialFolder(Environment.SpecialFolder folder) =>

private static unsafe string? TryGetWindowsKnownFolder(Guid guid)
{
nint path = IntPtr.Zero;
char* path = null;
string? result = null;

try
var hr = SHGetKnownFolderPath(&guid, 0, null, &path);
if (hr == 0)
{
var hr = SHGetKnownFolderPath(guid, 0, 0, &path);
if (hr == 0)
{
result = Marshal.PtrToStringUni(path);
}
result = Marshal.PtrToStringUni((IntPtr)path);
}
finally

if (path != null)
{
if (path != IntPtr.Zero)
{
Marshal.FreeCoTaskMem(path);
}
Marshal.FreeCoTaskMem((IntPtr)path);
}

return result;
}

private static readonly Guid s_folderDownloads = new Guid("374DE290-123F-4565-9164-39C4925E467B");
[DllImport("shell32.dll")]
private static unsafe extern int SHGetKnownFolderPath([MarshalAs(UnmanagedType.LPStruct)] Guid id, int flags, nint token, nint* ppszPath);
[DllImport("shell32.dll", ExactSpelling = true)]
private static unsafe extern int SHGetKnownFolderPath(Guid* rfid, uint dwFlags, void* hToken, char** ppszPath);
}
Loading