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
<jsg...@gmail.com> wrote in message
news:1141432814.5...@z34g2000cwc.googlegroups.com...
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