Open gumbarros opened 8 months ago
https://learn.microsoft.com/en-us/dotnet/standard/native-interop/pinvoke-source-generation
Another reference explaining the benefits. I think this is an important issue.
I like this idea. Feel free to work on it with @yaira2’s approval.
Sounds good, it might be worth splitting this into multiple PRs to make it easier to test and review.
Thanks for the initial try. Do you know CsWin32? If you know, you can replace them with API generated by CsWin32. Using DllImport or LibraryImport is deprecation in Files app because we plan to use CsWin32 instead of those code and Vanara.
Just checked about CsWin32, looks promising because of source generator usage like LibraryImportAttribute
. Will make a try tonight at NativeFindStorageItemHelper.cs
Don't know if this is expected behavior when migrating: https://github.com/microsoft/CsWin32/issues/1167
I'm not sure, but this function in C language uses void*.
I assume that whether adding in
or out
and even ref
is defined in win32metadata or CsWin32 repo.
#include <fileapifromapp.h>
WINSTORAGEAPI HANDLE FindFirstFileExFromAppW(
LPCWSTR lpFileName,
FINDEX_INFO_LEVELS fInfoLevelId,
LPVOID lpFindFileData, // HERE
FINDEX_SEARCH_OPS fSearchOp,
LPVOID lpSearchFilter,
DWORD dwAdditionalFlags
) noexcept;
You can use Marshal.PtrToStructure
:
using System.Runtime.InteropServices;
Marshal.PtrToStructure((nint)lpFindFileData, typeof(WIN32_FIND_DATA));
And you don't need to migrate all of inside of NativeFindStorageItemHelper because it would make us unreviewable so why not migrate step by step.
Also, if you're struggling with some issues you can skip, or you can pick functions up from Win32PInvoke
that I made in my PR #15075 after merged because I gathered methods into single file and I think it's a good play ground as well for you.
Now you can see Files.App.Helpers.Win32 Win32PInvoke class. We can replace them with CsWin32 piece by piece (starting from about 10 functions).
[!IMPORTANT]
- Please Use CsWin32 instead of replacing with LibraryImport. This Win32PInvoke class should be going to contain undocumented native functions defined through LibraryImport or DllImport when possible.
- Don't use "*FromApp" functions. They are intended to be used on UWP. Instead, use native ones.
- E is easy, M is medium, D is difficult. If anyone else can take a look, it'd be good to start from ones marked as E.
Description
Related to https://learn.microsoft.com/en-us/dotnet/fundamentals/syslib-diagnostics/syslib1050-1069.
Concerned code
Example:
to
Gains
Requirements
Comments
No response