public static GetInterfacesOOP ( COMCLSIDEntry ent ) : Task |
||
ent | COMCLSIDEntry | |
return | Task |
public async static Task<COMEnumerateInterfaces> GetInterfacesOOP(COMCLSIDEntry ent)
{
using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(System.IO.Pipes.PipeDirection.In,
HandleInheritability.Inheritable, 16 * 1024, null))
{
string process = null;
if (!Environment.Is64BitOperatingSystem || Environment.Is64BitProcess)
{
process = COMUtilities.GetExePath();
}
else
{
process = COMUtilities.Get32bitExePath();
}
string apartment = "s";
if (ent.ThreadingModel == COMThreadingModel.Both
|| ent.ThreadingModel == COMThreadingModel.Free)
{
apartment = "m";
}
Process proc = new Process();
ProcessStartInfo info = new ProcessStartInfo(process, String.Format("{0} {1} {2} {3} \"{4}\"",
"-e", server.GetClientHandleAsString(), ent.Clsid.ToString("B"), apartment, ent.CreateContext));
info.UseShellExecute = false;
info.CreateNoWindow = true;
proc.StartInfo = info;
proc.Start();
try
{
server.DisposeLocalCopyOfClientHandle();
using (StreamReader reader = new StreamReader(server))
{
List<COMInterfaceInstance> interfaces = new List<COMInterfaceInstance>();
List<COMInterfaceInstance> factory_interfaces = new List<COMInterfaceInstance>();
while (true)
{
string line = await reader.ReadLineAsync();
if (line == null)
{
break;
}
if (line.StartsWith("ERROR:"))
{
uint errorCode;
try
{
errorCode = uint.Parse(line.Substring(6), System.Globalization.NumberStyles.AllowHexSpecifier);
}
catch (FormatException ex)
{
Debug.WriteLine(ex.ToString());
errorCode = 0x80004005;
}
throw new Win32Exception((int)errorCode);
}
else
{
Guid g;
bool factory = false;
if (line.StartsWith("*"))
{
factory = true;
line = line.Substring(1);
}
string[] parts = line.Split(new char[] { ',' }, 3);
if (Guid.TryParse(parts[0], out g))
{
string module_path = null;
long vtable_offset = 0;
if (parts.Length == 3)
{
module_path = parts[1];
long.TryParse(parts[2], out vtable_offset);
}
if (factory)
{
factory_interfaces.Add(new COMInterfaceInstance(g, module_path, vtable_offset));
}
else
{
interfaces.Add(new COMInterfaceInstance(g, module_path, vtable_offset));
}
}
}
}
if (!proc.WaitForExit(5000))
{
proc.Kill();
}
int exitCode = proc.ExitCode;
if (exitCode != 0)
{
interfaces = new List<COMInterfaceInstance>(new COMInterfaceInstance[] { new COMInterfaceInstance(COMInterfaceEntry.IID_IUnknown) });
factory_interfaces = new List<COMInterfaceInstance>(new COMInterfaceInstance[] { new COMInterfaceInstance(COMInterfaceEntry.IID_IUnknown) });
}
return new COMEnumerateInterfaces(ent.Clsid, ent.CreateContext, interfaces, factory_interfaces);
}
}
finally
{
proc.Close();
}
}
}
}
private async Task <COMEnumerateInterfaces> GetSupportedInterfacesInternal() { try { return(await COMEnumerateInterfaces.GetInterfacesOOP(this, m_registry)); } catch (Win32Exception) { throw; } }