I am trying to use InteropServices.Marshal.QueryInterface to convert a COM object to a specific type in C#, but I am having trouble to pass in the first and last parameters.
I am assuming that IntPtr is a reference, but I cannot get IntPtr to reference my classes to use QueryInterface due to syntax errors.
Of course, the code that is shown below does not have the correct syntax, but it gives you an idea of what I am trying to do.
set
{
ClassA a;
Guid guid = Guid.Parse("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX");
System.Runtime.InteropServices.Marshal.QueryInterface(ref value,
ref guid, out a);
}
EDIT:
[ComVisible(true), Guid("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX")]
public ClassA : COMInterface{ ... }
ClassA is the C# class, and COMInterface is the COM interface. It is the only class that implements COMInterface. value in the set scope is the reference to the COM Interface, COMInterface
ClassAis the C# class, and it implements aCOMInterface, which is the COM interface. It is the only class that implements the COMInterface. The value is the reference to the COM interface.ClassA:InterfaceB, andInterfaceB:COMInterface. Ya, never mind.