Closed DerMagereStudent closed 8 months ago
This is what I see CsWin32 generating:
static extern unsafe winmdroot.Foundation.WIN32_ERROR GetApplicationUserModelId(
winmdroot.Foundation.HANDLE hProcess,
uint* applicationUserModelIdLength,
winmdroot.Foundation.PWSTR applicationUserModelId);
And this is the C header:
LONG GetApplicationUserModelId(
[in] HANDLE hProcess,
[in, out] UINT32 *applicationUserModelIdLength,
[out] PWSTR applicationUserModelId
);
Those look equivalent to me.
From what you describe to have expected, I think you misunderstand the PWSTR
type, which is a struct that contains a pointer -- equivalant to PWSTR
in C. It is not like the string
type in C#.
The reason your code is failing is because you haven't initialized the 3rd argument (the PWSTR) to point to a buffer. The docs for the function describe this parameter to be:
A pointer to a buffer that receives the application user model ID.
But you haven't pointed at a buffer. You just new'd it up and passed it in (with the implied null pointer inside). Just like in C, you should allocate a buffer, initialize your PWSTR to point at it, and then pass it in.
I want to read out the AUMID of a process. But this is not possible because the created Pinvoke takes in the PWSTR by value.
Actual behavior
This is the created method:
Expected behavior
I would expect the method to take in
winmdroot.Foundation.PWSTR* applicationUserModelId
ref winmdroot.Foundation.PWSTR applicationUserModelId
out winmdroot.Foundation.PWSTR applicationUserModelId
Repro steps
NativeMethods.txt
content:// Interfaces
// Functions OpenProcess GetApplicationUserModelId CloseHandle
using Windows.Win32; using Windows.Win32.Foundation; using Windows.Win32.System.Threading;
public static class Program { public static async Task Main(string[] args) { var processHandle = PInvoke.OpenProcess(PROCESS_ACCESS_RIGHTS.PROCESS_QUERY_LIMITED_INFORMATION, false, 8552U);
}