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

Unable to Marshal function parameters #14

Open
jaredcatkinson opened this issue Jun 22, 2017 · 4 comments
Open

Unable to Marshal function parameters #14

jaredcatkinson opened this issue Jun 22, 2017 · 4 comments

Comments

@jaredcatkinson
Copy link
Contributor

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
);
@jaredcatkinson jaredcatkinson changed the title Unable to Marshal Unable to Marshal function parameters Jun 22, 2017
@mattifestation
Copy link
Owner

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().

@jambonmcyeah
Copy link

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);

@jaredcatkinson
Copy link
Contributor Author

jaredcatkinson commented Jul 5, 2017 via email

@jambonmcyeah
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants