Files
Michael Zhmailo a655de2076 Initial Commit
2024-06-24 22:44:32 +05:00

40 lines
984 B
C#

using System;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
namespace RemoteKrbRelay.Relay.Com
{
public static class ComUtils
{
[DllImport("ole32.dll")]
private static extern int CreateObjrefMoniker(
IntPtr punk,
out IMoniker ppmk);
[DllImport("ole32.dll")]
private static extern int CreateBindCtx(
int reserved,
out IBindCtx ppbc
);
[DllImport("ole32.dll")]
public static extern void CoUninitialize();
public static byte[] GetMarshalledObject(object o)
{
IMoniker mk;
CreateObjrefMoniker(Marshal.GetIUnknownForObject(o), out mk);
IBindCtx bc;
CreateBindCtx(0, out bc);
string name;
mk.GetDisplayName(bc, null, out name);
return Convert.FromBase64String(name.Substring(7).TrimEnd(':'));
}
}
}