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 / March 2008

Tip: Looking for answers? Try searching our database.

Overloading in ActiveX

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Maris Janis Vasilevskis - 14 Mar 2008 08:23 GMT
Hi,

I create ActiveX dll in C# (VS 2005) as following:

[ClassInterface(ClassInterfaceType.AutoDual)]
public class MyClass {
  public void MyMethod(string arg1) {...}
  public void MyMethod(string arg1, string arg2) {...}
}

I regasm it and try to call in IE7 JScript:

function Test() {
  var obj=new ActiveXObject('MyNamespace.MyClass');
  obj.MyMethod('q');
  obj.MyMethod('q','w');
}

The second call fails with message "wrong number of arguments".
If I change definition sequence in MyClass, only two argument call is accepted in JScript.

How can I expose both overloaded functions in ActiveX?

Thank you,
Mahris
Christian Fröschlin - 14 Mar 2008 09:24 GMT
> How can I expose both overloaded functions in ActiveX?

AFAIK, COM does not support overloaded interface members at all.
Martin Bonner - 14 Mar 2008 15:56 GMT
> > How can I expose both overloaded functions in ActiveX?
>
> AFAIK, COM does not support overloaded interface members at all.

I don't think COM will have a problem.  COM doesn't actually care /
what/ the functions are called - just their position in the vtable.

The problem is that IDispatch doesn't support overloaded functions,
and JScript uses IDispatch.

To the OP: You are going to have to change the name of one of the
functions.
Maris Janis Vasilevskis - 15 Mar 2008 11:08 GMT
Thanks to all. I found a solution.

In C#, I define
public void MyMethod([In,Optional]ref object arg1, [In,Optional]ref object arg2) {...}

It accepts JScript calls with different number of args.

Mahris

Martin Bonner wrote 2008.03.14. 16:56:
>>> How can I expose both overloaded functions in ActiveX?
>> AFAIK, COM does not support overloaded interface members at all.
[quoted text clipped - 7 lines]
> To the OP: You are going to have to change the name of one of the
> functions.

Rate this thread:







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.