Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / January 2005

Tip: Looking for answers? Try searching our database.

COM with C# overloads

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
eezee - 09 Dec 2004 11:13 GMT
I wrote an API in C# which included a couple of overloaded methods:

   bool SendMessage(byte[] msg);
   bool SendMessage(byte[] msg, uint priority);

I've now been asked to add a COM wrapper. However COM doesn't
support overloads. Hence, my MIDL becomes:

   [id(0x60020002)]
   HRESULT SendMessage(
       [in] SAFEARRAY(unsigned char) msg,
       [out, retval] VARIANT_BOOL* pRetVal);

   [id(0x60020003),
       custom(0F21F359-AB84-41E8-9A78-36D110E6D2F9, SendMessage)]
   HRESULT SendMessage_2(
       [in] SAFEARRAY(unsigned char) msg,
       [in] unsigned long priority,
       [out, retval] VARIANT_BOOL* pRetVal);

Is there anyway around this? I don't want the application developers to have
to
write:

   hr = pIsmf->SendMessage(psa, &bResult);
   hr = pIsmf->SendMessage_2(psa, 1, &bResult);

Thanks folks.
Mattias Sj?gren - 09 Dec 2004 23:04 GMT
>Is there anyway around this?

No, COM doesn't support overloading.

Mattias

Signature

Mattias Sjögren [MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Frederic Pesquet - 22 Dec 2004 10:35 GMT
> No, COM doesn't support overloading.

Ok, but is it possible to customize the generated COM name for the
overloaded methods ?
(i.e. renaming the second overloaded method with something like
SendMessageWithPriority)
I found no attributes to do so.

Thanks
Mattias Sj?gren - 05 Jan 2005 22:18 GMT
>Ok, but is it possible to customize the generated COM name for the
>overloaded methods ?

No easy way. But you can decompile the typelib with Oleview, edit it
as needed and then generate a new with MIDL.

Mattias

Signature

Mattias Sjögren [MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.