I basicaly need to identify the object type so I can send it to a
handler. I only care about one or two specific interfaces, just
enough to pass the object to the right handler which runs a specific
cast and does it's jiggery pokery.
Type at = Type.GetType(wca.AddType); // Add type is a string name of a
COM interface.
Why is this returning NULL!!!!
Join me in the pub this evening and I'll tell you all about third-
party libraries that just throw a bunch of untyped objects at you and
expect you to deal.
What exactly do you mean with "string name of a COM interface" here?
Type at = Type.GetType(wca.AddType); // Add type is a string name of a COM
interface.
what does wca.AddType contain?
Interfaces are identified using UUID's, so you need to specify the UUID of
the interface (the IID) you are looking for in a call to QI.
Herewith a small sample calling a method on a native COM object using late
binding.
string progId = "SimpleCom.Bird";
Type t = Type.GetTypeFromProgID(progId);
if (t == null)
{
throw new Exception("Invalid ProgID.");
}
Console.WriteLine("GUID for ProgID RemServer.Server is {0}.",
t.GUID);
object o = Activator.CreateInstance(t); // create an instance
of this server
IntPtr pUnkn = Marshal.GetIUnknownForObject(o); // Get the
IUnknow pointer
Guid IID = new Guid("0938B479-ED9A-4997-B780-85AF420E01FF"); //
This is the Interface I need
IntPtr ppv;
int hResult = Marshal.QueryInterface(pUnkn, ref IID, out ppv);
// Does above Interface exists?
if(hResult < 0)
{ throw ... }
else
{
// success, use interface
object bird = Marshal.GetObjectForIUnknown(ppv);
//late bound call
bird .GetType().InvokeMember("Fly",
BindingFlags.InvokeMethod, null, bird , new Object[] {"To Somewhere"});
...
Willy.