I am trying to add a POINT struct to powershell to use in winapi GetCursorPos function. This is what i have try:
$MethodDefinition=@'
[StructLayout(LayoutKind.Sequential)]
public struct POINT
{
public int X;
public int Y;
public POINT(int x, int y)
{
this.X = x;
this.Y = y;
}
}
[DllImport("user32.dll")]public static extern Int32 GetCursorPos(out POINT lpPoint);
'@;Add-Type -MemberDefinition $MethodDefinition -Name 'Win32' -NameSpace '' -PassThru
When I delete GetCursorPos definition it gives me a yellow: WARNING: The generated type defines no public methods or properties.
I don't know how do I use a struct in powershell, I only find informations on how to create one.
See:
https://www.pinvoke.net/default.aspx/Structures/POINT.html
How do I create a custom type in PowerShell for my scripts to use?
https://learn.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.layoutkind?view=net-5.0
Edit:
I have added a struct but still don't know how to construct it:
$StructDefinition=@'
public struct POINT{public int X;public int Y;public POINT(int x, int y){this.X=x;this.Y=y;}}
'@;Add-Type -TypeDefinition $StructDefinition -PassThru