Hello,
I am new to PInvoke and I am trying to figure out why I can not convert HWind from the System.Object[]. So if you know what’s cause of the error, please let me know.
Thank you so much in advance for all of the helps.
Attached is a simple program that I found on Google, In this program , I passed in the $h as the window handle pointer to the un-managed code Tricks program
Add-Type @”
using System;
using System.Runtime.InteropServices;
public class Tricks {
[DllImport(“user32.dll”)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetForegroundWindow(IntPtr hWnd);
}
“@
sleep -sec 2
$h = (Get-Process Chrome).MainWindowHandle
[Tricks]::SetForegroundWindow($h)
The system gave me an error stating that it did not recognize $h as the pointer:
Cannot convert argument “hWnd”, with value: “System.Object[]”, for “SetForegroundWindow” to type “System.IntPtr”: “Cannot convert the “System.Object[]” value of type “System.Object[]” to
type “System.IntPtr”.”