Skip to content

Instantly share code, notes, and snippets.

@tmplinshi
Created October 30, 2022 03:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmplinshi/ff268eecfc055792ca749ef359866a0f to your computer and use it in GitHub Desktop.
Save tmplinshi/ff268eecfc055792ca749ef359866a0f to your computer and use it in GitHub Desktop.
Add-Type -TypeDefinition @'
using System;
using System.Runtime;
using System.Runtime.InteropServices;
public static class Marshal
{
internal const String OLEAUT32 = "oleaut32.dll";
public static Object GetActiveObject(Guid clsid)
{
Object obj = null;
GetActiveObject(ref clsid, IntPtr.Zero, out obj);
return obj;
}
//[DllImport(Microsoft.Win32.Win32Native.OLEAUT32, PreserveSig = false)]
[DllImport(OLEAUT32, PreserveSig = false)]
private static extern void GetActiveObject(ref Guid rclsid, IntPtr reserved, [MarshalAs(UnmanagedType.Interface)] out Object ppunk);
}
'@
$clsid = "{E123917B-8D61-4CCF-A1BB-F15551EAF442}"
$test = [Marshal]::GetActiveObject($clsid)
$test.hello()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment