Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / February 2008

Tip: Looking for answers? Try searching our database.

More Type/COM fun

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
oddball.bfi@gmail.com - 25 Feb 2008 16:55 GMT
Ok - now I've got me stuck again - this time good and proper.

I've got a Type object for an interface a COM object may (or may not)
implement.  Lets call it IBob

Now

IBob bobObject = comObject as IBob;

if (bobObject == null)
return "Don't call me Bob";
else
return "Call me Bob!  If you call me Bobby, I'll kill you";

That's all well and groovy.  But my real issue starts with the fact
that I have a type object, and that don't work with 'as' as far as I
know.

if (iBobType.InstanceOf(comObject))
return "Hi - call me Bob!";
else
return "Its Robert.";

This always return Robert... COM appares to be pathalogicaly opposed
to being called Bob.  What can I do?

My name is Josh, btw.
Richard Blewett - 25 Feb 2008 17:12 GMT
> Ok - now I've got me stuck again - this time good and proper.
>
[quoted text clipped - 23 lines]
>
> My name is Josh, btw.

Hi Josh,

I think you should be using IsAssignableFrom IIRC

Signature

Regards

Richard Blewett
DevelopMentor
http://www.dotnetconsult.co.uk/weblog2

Oddball - 25 Feb 2008 17:21 GMT
> <oddball....@gmail.com> wrote in message
>
[quoted text clipped - 37 lines]
> Richard Blewett
> DevelopMentorhttp://www.dotnetconsult.co.uk/weblog2

That didn't work either.  I swapped to IsAssignableFrom, that required
a Type.  I tried comObject.GetType() but, of course, that just
returned the System.__ComObject type - which is a heap of junk, as any
good tank mechanic will tell you.

This is the last step between me and world-wide recognition for my COM
skills - at least, as far as my mates go when I sit them down and make
them hear all about my hours of hell at the hands of daemon of a model.
Nicholas Paldino [.NET/C# MVP] - 25 Feb 2008 17:59 GMT
Quite simply, you can't do this with the type information.  COM doesn't
require that a component publish in some sort of metadata that a type
implements a particular interface or not.  Because of this, with simply a
Type instance, you can't determine if a component implements a COM
interface.  In COM, you have to call QueryInterface and the component will
tell you if the interface is supported or not.  The catch here is that the
call to QueryInterface requires the instantiation of the component, which
means you have to move beyond the Type instance.

Signature

         - Nicholas Paldino [.NET/C# MVP]
         - mvp@spam.guard.caspershouse.com

>> <oddball....@gmail.com> wrote in message
>>
[quoted text clipped - 46 lines]
> skills - at least, as far as my mates go when I sit them down and make
> them hear all about my hours of hell at the hands of daemon of a model.
Oddball - 25 Feb 2008 18:37 GMT
On 25 Feb, 17:59, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.com> wrote:
>     Quite simply, you can't do this with the type information.  COM doesn't
> require that a component publish in some sort of metadata that a type
[quoted text clipped - 59 lines]
> > skills - at least, as far as my mates go when I sit them down and make
> > them hear all about my hours of hell at the hands of daemon of a model.

That's not a problem!!! How? :)
Nicholas Paldino [.NET/C# MVP] - 25 Feb 2008 19:26 GMT
Oddball,

   Well, if you want to create an instance given a Type, you can simply
pass the Type to the static CreateInstance method of the Activator class,
and then perform your checks against the instance (obj as IWhatever).

Signature

         - Nicholas Paldino [.NET/C# MVP]
         - mvp@spam.guard.caspershouse.com

> On 25 Feb, 17:59, "Nicholas Paldino [.NET/C# MVP]"
> <m...@spam.guard.caspershouse.com> wrote:
[quoted text clipped - 67 lines]
>
> That's not a problem!!! How? :)

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.