Aggregating a COM object in .NET using ICustomQueryInterface


hi,

i found blog post "icustomqueryinterface , clr v4" jmstall (http://blogs.msdn.com/b/jmstall/archive/2009/07/09/icustomqueryinterface-and-clr-v4.aspx ) describes how force clr not throw away "com callable wrapper" (ccw) in case managed object gets handed managed object through unmanaged object.
code worked beta versions of .net 4 unfortunately not final. ccw thrown away , in sample code cast ifoo2 fails. icustomqueryinterface.getinterface() never called.

does of have idea how code fixed works .net 4.0 final?

in case matters, scenario different: want write add-in unmanaged application. these add-ins must implement com interfaces. there exists unmanaged add-in pretty want want, need change behavior of single interface (let's call iinteresting). class implements iinteresting. other casts pipe instance of existing add-in class using icustomqueryinterface:

  		customqueryinterfaceresult icustomqueryinterface.getinterface(ref guid iid, out intptr ppv)  		{  			try  			{  				if (iid.equals(_guidiintersting))  				{  					// causes our explicit interface implementation called:  					ppv = intptr.zero;  					return customqueryinterfaceresult.nothandled;  				}    				if (iid.equals(_guidimarshal) || iid.equals(_guidimanagedobject))  				{  					// *** worked in .net beta imarshal , imanagedobject never make   					// *** method in final.  					// .net recognizes object ccw testing imanagedobject. throws  					// away ccw if our custom feature used managed code. don't want   					// behavior because icustomqueryinterface won't used anymore , our add-in<br/>                       // end implementing iinteresting only.  					// tell clr don't implement imanagedobject:  					ppv = intptr.zero;  					return customqueryinterfaceresult.failed;  				}    				int result = marshal.queryinterface(_existingaddinintptr, ref iid, out ppv);    				const int e_nointerface = -2147467262;  				if (result == e_nointerface)  				{  					return customqueryinterfaceresult.nothandled;  				}    				return ppv == intptr.zero ? customqueryinterfaceresult.nothandled : customqueryinterfaceresult.handled;  			}  			catch (exception ex)  			{  				system.diagnostics.debug.writeline(ex.message);  				throw;  			}  		}    


works , application uses add-in using iinteresting , other 15 (or so) interfaces existing unmanaged add-in provides. , problem: there other managed add-ins, , if find add-in icustomqueryinterface.getinterface() implementation not called , don't rcw ccw of managed add-in add-in (normal interop behavior), , them object seems implement iinteresting. i'd force clr hand them rcw ccw of managed add-in transparently cast add-in other interfaces.

i know provide cast operator each of interfaces existing unmanaged object provides that's not want because add-in might implement more interfaces in future , need add them class well.

does of have idea how make other managed add-ins see interfaces?

common microsoft guys!

take challenge, answer question, , become heroes! (and give me reason continue msdn subscription.. ;-))



.NET Framework  >  Common Language Runtime Internals and Architecture



Comments

Popular posts from this blog

Azure DocumentDB Owner resource does not exist

job syspolicy_purge_history job fail in sqlserver 2008

Trying to register with public marketplace error with 'Get-AzureStackStampInformation'