Main Page | Report this Page
.NET DotNet Forum Index  »  .NET Framework Forum  »  How to implement IDispatch manually...
Page 1 of 1    

How to implement IDispatch manually...

Author Message
Marvin Landman...
Posted: Sat Oct 10, 2009 10:01 am
Guest
Hi,

I have tried to declare IDispatch using its GUID and implement it, but
the runtime either seems to provide its own IDispatch implementation or
none at all depending on ClassInterface attribute of the class.

Is using my own IDispatch implementation possible?

Thanks.

Regards,
Marvin
 
Jie Wang [MSFT]...
Posted: Tue Oct 13, 2009 1:58 am
Guest
Hi Marvin,

What you wanted won't work because IDispatch is treated specially, it can't
be implemented in managed code like what you did (and many others tried the
same thing before).

There is another option though. You can implement the
System.Reflection.IReflect interface on your object to be working with COM.

See http://msdn.microsoft.com/en-us/library/system.reflection.ireflect.aspx

And for .NET Framework 4.0 (the future), the new interface
ICustomQueryInterface will be helpful on this issue.

See
http://clrinterop.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=32350

Hope this helps.

Regards,
Jie Wang

Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg at (no spam) microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business days is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Marvin Landman...
Posted: Tue Oct 13, 2009 2:12 am
Guest
Hi,

Thank you very much for pointing out IReflect. It's perfect for me.

Regards,
Marvin

Jie Wang [MSFT] wrote:
Quote:
Hi Marvin,

What you wanted won't work because IDispatch is treated specially, it can't
be implemented in managed code like what you did (and many others tried the
same thing before).

There is another option though. You can implement the
System.Reflection.IReflect interface on your object to be working with COM.

See http://msdn.microsoft.com/en-us/library/system.reflection.ireflect.aspx

And for .NET Framework 4.0 (the future), the new interface
ICustomQueryInterface will be helpful on this issue.

See
http://clrinterop.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=32350

Hope this helps.

Regards,
Jie Wang

Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg at (no spam) microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business days is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Gregory A. Beamer...
Posted: Thu Oct 15, 2009 10:29 am
Guest
Marvin Landman <marvin at (no spam) newsgroup.nospam> wrote in news:uRSGlr2SKHA.4028
at (no spam) TK2MSFTNGP05.phx.gbl:

Quote:
I am working in .NET and would like to have a custom IDispatch
implementation instead of the one that .NET provides.

I know of no facility to do that in .NET, as the COM wrapper is a form
of marshalling from managed to unmanaged code.

You could, conceivably, make a custom COM "wrapper" in C++ and implement
a custom IDispatch. Realize, however, that you end up flipping back and
forth from COM to .NET a few times to accomplish exposing your .NET
assembly, with its custom IDispatch, for COM clients (assume that is the
goal, will have to reread the thread to be sure).

You have hit a fringe case here that affects too few to be high on the
radar (I have never personally customized a built in COM interface even
when I was writing COM components, for example).

If it were me, I would consider taking a step back and seeing if the
architectural direction is correct for this piece.

Peace and Grace,

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Twitter: at (no spam) gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 
 
Page 1 of 1    
All times are GMT - 5 Hours
The time now is Fri Nov 27, 2009 4:50 am