PSReflect
PSReflect copied to clipboard
Unable to Marshal function parameters
PSReflect does not have the ability to use the MarshalAs attribute on function parameters.
Below is an example P/Invoke definition where the MarshalAs attribute is used on the pgActionID parameter:
[DllImport("wintrust.dll", ExactSpelling = true, SetLastError = false, CharSet = CharSet.Unicode)]
static extern WinVerifyTrustResult WinVerifyTrust(
[In] IntPtr hwnd,
[In] [MarshalAs(UnmanagedType.LPStruct)] Guid pgActionID,
[In] WinTrustData pWVTData
);
Should be doable using the ParameterBuilder.SetCustomAttribute method in a similar fashion to how I do it with struct members. Before I dive into this, could you offer some additional use cases where you might need this? In the example above, you can get away without the MarshalAs attribute by specifying pgActionID as [Guid].MakeByRefType()
.
I have a similar issue where I can't marshal return values
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool EnumChildWindows(IntPtr hwndParent, EnumWindowsProc lpEnumFunc, IntPtr lParam);
For this example can't you specify the return type as [bool]? I think the marshaling would happen automatically.
Something like: (func user32 EnumChildWindows ([bool]) @( [IntPtr], [IntPtr], [IntPtr] ))
Sent from my iPhone
On Jul 4, 2017, at 5:32 PM, jambonmcyeah [email protected] wrote:
I have a similar issue where I can't marshal return values
[DllImport("user32.dll")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool EnumChildWindows(IntPtr hwndParent, EnumWindowsProc lpEnumFunc, IntPtr lParam); — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.
Well, what there is a function where marshaling won't happen automatically? I remembered a while ago I neede a function with a UnmanagedType.LPArray return type. Forgot which function though.