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 / September 2004

Tip: Looking for answers? Try searching our database.

Passing Array From ASP to C#

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Wes - 22 Sep 2004 21:24 GMT
Could someone please post how to pass an array from ASP (VBScript)
into a C# exposed object?

I have this code in ASP:

Dim arrBefore(2)
Dim arrAfter(3)
Dim lngId

lngId = 987
arrBefore(0) = 1234
...Some more init code

Set obj = Server.CreateObject("MyCSharpLib.MyObject")
obj.MyMethod arrBefore, arrAfter, lngId

This is the last C# method I've tried:

    [System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
public class MyClass : MyBase {
 public void MyMethod(ref object before, ref object after, int Id) {
   Array ar1 = (Array) before;
   Array ar2 = (Array) after;
 }
}
This gives me a variable uses an "Variable uses an Automation type not
supported in VBScript" error.  The others gave me "Invalid Procedure
Call" errors from Asp.

I've tried to make before, after params be Array as well, but that
didn't work.  I also tried to use some of the Marshalling attributes,
but couldn't get that to work.  I have also tried object[], and that
didn't work.

I used the class attributes because it seemed to be the thing to do,
but I'm not sure why, so if anyone has insight on that...

Thanks,
Wes
Robert Jordan - 22 Sep 2004 21:35 GMT
> Could someone please post how to pass an array from ASP (VBScript)
> into a C# exposed object?
[quoted text clipped - 32 lines]
> I used the class attributes because it seemed to be the thing to do,
> but I'm not sure why, so if anyone has insight on that...

Try this:

[ClassInterface(ClassInterfaceType.AutoDispatch)]
public class MyClass : MyBase {
  public void MyMethod(object[] before, object[] after,
      int Id) {
  }
  public void MyMethod2(ref object[] before, ref object[] after,
      int Id) {
  }
}

Set obj = Server.CreateObject("MyCSharpLib.MyObject")

now pass the arrays by val:

obj.MyMethod (arrBefore), (arrAfter), lngId

One of the methods should work, but i forgot which of them.

bye
Rob
Wes Stueve - 22 Sep 2004 23:06 GMT
Rob,

That works perfectly either way.  I did not know about the extra
paretheses in VBScript.  Thanks a million!

Wes

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.