Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Safe to modify IDL to change from IDispatch to a different Interface?

1 view
Skip to first unread message

jsg...@gmail.com

unread,
Mar 3, 2006, 7:40:14 PM3/3/06
to
Hello,

I am developing a C# wrapper to an existing C++ / COM system. The
interfaces within the IDL for the project contain a number of propget
statements which currently return IDispatch ** types. This causes the
tlbimp program to expose those properties simply as "object" types.

For instance, one interface is like this (pseudo-code)

interface IServer {

[id(0x0000000f), propget, helpstring("Advanced Search")]
HRESULT AdvancedSearch([out, retval] IDispatch** pVal);
}

interface ISearch
{
[id(0x0000000f), propput, helpstring("Page Size")]
HRESULT PageSize([in, retval] long pVal);
[id(0x0000000f), propget, helpstring("Page Size")]
HRESULT PageSize([out, retval] long* pVal);
}

When the interop assembly is created, IServer looks like:

interface IServer
{
object AdvancedSearch { get; }
}

This leads to having to write non-intuitive code like:

Server s = new ServerClass();
Search src = (Search) s.AdvancedSearch;
src.PageSize = 20;

What I really want is to be able to do more like:

Server s = new ServerClass();
s.AdvancedSearch.PageSize = 20;


So, I manually modified the IDL to look like:


interface IServer {

[id(0x0000000f), propget, helpstring("Advanced Search")]
HRESULT AdvancedSearch([out, retval] ISearch** pVal);
}


And compiled it with MIDL.EXE then used tlbimp.exe to create a new RCW.
This then allowed me to use that nice dotted syntax.

My question is: is it safe to do this? Is there anything I should watch
out for or could this cause any problems somehow?

Thank you,
Josh

Phil Wilson

unread,
Mar 4, 2006, 2:31:36 PM3/4/06
to
If your code actually works, it's probably safe ;=). Although the IDL
describes the return type as IDispatch** I'd guess that substituting IServer
works because the AdvancedSearch method is actually returning an IServer**
and IServer is a dual interface, deriving from IDispatch. So your code works
ok, and anyone that uses IDispatch methods on the returned IServer should be
ok because IServer does in fact implement IDispatch because of that
derivation. So it comes down to whether IServer is dual or not.
--
Phil Wilson
[Microsoft MVP-Windows Installer]
Definitive Guide to Windows Installer
http://apress.com/book/bookDisplay.html?bID=280

<jsg...@gmail.com> wrote in message
news:1141432814.5...@z34g2000cwc.googlegroups.com...

jsg...@gmail.com

unread,
Mar 4, 2006, 4:18:58 PM3/4/06
to
Phil, thank you for the response. I appreciate it.

I don't have the code with me at home, but I believe that yes, they are
all dual.

This will be part of a gradual rewrite of a well-designed COM api. I'd
like to enable as much re-use as possible moving forward, but if we
have to do all kinds of (cast)ing in C#, it's going to be pretty
cumbersome, but if I can just make a copy of the IDL, modify those
areas where I know that the property get will be returning ISearch or
IConfig, or IWhatever, then the TLB generated from that will build a
more programmer / reuse friendly interop assembly. That should even
allow for a fair amount of copying and pasting some of the existing ASP
code into .NET and just adding some ; at the end of the lines if all
goes well.

Thanks again,
Josh

0 new messages