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

回眸只為那壹抹淺笑 提交于 2019-12-08 21:16:46

问题


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


回答1:


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

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;
}


来源:https://stackoverflow.com/questions/1356755/com-interop-how-to-pass-an-array-to-the-com-via-classic-asp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!