简体   繁体   中英

COM Interop (how to pass an array to the com) via classic ASP

I need to create a com object for my classic asp, since i can create a .net Assembly and have it 'Interop' with com, so i proceeded to create a .net Assembly like this:-

using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
using System.Web;


namespace LMS
{

[ComVisible(true)]
public class Calc
{

    public int Add(int val1, int val2, out string[] outputz)
    {
        int total = val1 + val2;
        outputz = new string[5];
        outputz[1] = "test2";
        outputz[2] = "test3";
        outputz[3] = "test4";
        outputz[4] = "test5";
        return total;
    }


}
}

Next i did the usual, build, ran: gacutil & RegAsm

and in my classic asp page i had this:-

Dim params  
dim objPassport3
set objPassport3 = Server.CreateObject("LMS.Calc")
comTest2 = objPassport3.Add(1,1,params)

and i get error:

Error Type: Microsoft VBScript runtime (0x800A0005) Invalid procedure call or argument: 'Add' /eduservice/test.asp, line 25

But if i modify the assembly not to use an array, it all just work, i can even send normal string or int to and from the assembly to classic asp. i read so many things but i get the same error,

anyone tried this before and was successful, please do share your solution

thanks

ASP can only handle arrays that are variant, rather than arrays of strings or ints. So try using an object instead, eg,

public int Add(int val1, int val2, out object outputz)
{
    int total = val1 + val2;
    outputz = new object[5]
      {
          "test1",
          "test2",
          "test3",
          "test4",
          "test5"
      };

    return total;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM