
Signature
Regards
Richard Blewett
DevelopMentor
http://www.dotnetconsult.co.uk/weblog2
> <oddball....@gmail.com> wrote in message
>
[quoted text clipped - 46 lines]
> Richard Blewett
> DevelopMentorhttp://www.dotnetconsult.co.uk/weblog2
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.
Richard Blewett - 25 Feb 2008 14:20 GMT
>> <oddball....@gmail.com> wrote in message
>>
[quoted text clipped - 67 lines]
> party libraries that just throw a bunch of untyped objects at you and
> expect you to deal.
OK, so with the way you have called this method it is expecting the
interface to live within your application (assembly). If you want this to
work you will have to add the assembly name on to the string. Suppose the
assembly housing the Runtime Callable Wrapper (I assume you have already
created an RCW) is called MyCOMStuff.dll and has been signed with a public
key token, then you need to pass in something like
wca.AddType, MyCOMStuff, Version=0.0.0.0, Culture=neutral,
PublicKeyToken=<token used for signing>
This will get you the type object for the interface. The question is, is
this really what you want? Aren't you trying to find out if a specific
object implements an interface or have I misunderstood?
Regards
Richard Blewett
DevelopMentor
http://www.dotnetconsult.co.uk/weblog2
Roger Frost - 25 Feb 2008 14:23 GMT
> 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
[quoted text clipped - 5 lines]
>
> Why is this returning NULL!!!!
I don't know much about what your trying to do....but GetType() accepts a
string parameter, so maybe it should be:
Type at = Type.GetType("wca.AddType");
Roger Frost - 25 Feb 2008 14:37 GMT
Wait, according to your comment it is a string argument....sorry.

Signature
Roger Frost
"Logic Is Syntax Independent"
>> 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
[quoted text clipped - 10 lines]
>
> Type at = Type.GetType("wca.AddType");
Willy Denoyette [MVP] - 25 Feb 2008 17:04 GMT
>> <oddball....@gmail.com> wrote in message
>>
[quoted text clipped - 67 lines]
> 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.
Oddball - 25 Feb 2008 17:37 GMT
On 25 Feb, 17:04, "Willy Denoyette [MVP]" <willy.denoye...@telenet.be>
wrote:
> <oddball....@gmail.com> wrote in message
>
[quoted text clipped - 114 lines]
>
> Willy.
It's the AQN of the Type in the Interop assembly.
Willy Denoyette [MVP] - 25 Feb 2008 18:43 GMT
> On 25 Feb, 17:04, "Willy Denoyette [MVP]" <willy.denoye...@telenet.be>
> wrote:
[quoted text clipped - 129 lines]
>
> It's the AQN of the Type in the Interop assembly.
If you have imported the IA, then you can simply cast the interface you got
from an instantiation call to any other interface implemented by the
component.
...
SomeNamespace.Animal animal = new SomeNamespace.AnimalClass();
// cast animal to wanted ITF, this performs a QueryInterface
under the covers
SomeNamespace.IBird bird = animal as SomeNamespace.IBird;
if(bird != null)
bird.Fly();
else
{
SomeNamespace.IDog dog as SomeNamespace.IDog;
if(dog != null)
dog.Bark();
...
Willy.
Willy.