Depends on what you consider "safe". It's not safe in all cases (e.g. aggregation); so, Steve is perfectly correct by dropping to the lowest- common-denominator and saying "Absolutely not". It may work in Josh's circumstances; but, there's lots of ways of writing code that works for a given set of circumstances that doesn't in others.
If I remember correctly, I believe the ATL QueryInterface method just casts the this pointer to whatever interface that is being requested, when not aggregated; but, that's an implementation detail that shouldn't be relied upon. By changing the property get method to accept the correct type (e.g. switch from IDispatch to IServer) and continuing to call QueryInterface(), the ATL internals will automatically get the correct pointer for that interface if aggregation is used in the future. On Mon, 6 Mar 2006 11:08:58 -0800, Wilson, Phil D <[EMAIL PROTECTED]> wrote: >If ISearch is dual, it is also an IDispatch, so existing clients who >expect an IDispatch are still getting an IDispatch. He's returning a new >interface that implements the prior one, so I don't think any COM rule >is being broken. > >Phil Wilson > >-----Original Message----- >From: Discussion of advanced .NET topics. >[mailto:[EMAIL PROTECTED] On Behalf Of Steve Johnson >Sent: Sunday, March 05, 2006 5:09 AM >To: ADVANCED-DOTNET@DISCUSS.DEVELOP.COM >Subject: Re: [ADVANCED-DOTNET] Safe to modify IDL to change from >IDispatch to a different Interface? > >On 3/4/06, Josh Gough <[EMAIL PROTECTED]> wrote: >> >> >> My question is: is it safe to do this? Is there anything I should >> watch out for or could this cause any problems somehow? >> > > >Absolutely not. You're getting by with it because you're only using the >tlb to generate a RCW and not for anything else. The RCW (IIRC), is >going to explicitly QI the retval for the ISearch interface, so it's >working now. >However, the retval is not actually an ISearch*, its an IDispatch*, so >although it's working for you, you've obfuscated the true interface of >the COM component. =================================== This list is hosted by DevelopMentorĀ® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com