簡體   English   中英

COM Interop(如何將數組傳遞給 com)通過經典 ASP

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

我需要為我的經典 asp 創建一個 com 對象,因為我可以創建一個 .net 程序集並讓它與 com“互操作”,所以我繼續創建一個這樣的 .net 程序集:-

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


}
}

接下來我做了通常的構建,運行:gacutil & RegAsm

在我的經典asp頁面中,我有這個:-

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

我得到錯誤:

錯誤類型:Microsoft VBScript 運行時 (0x800A0005) 無效的過程調用或參數:“添加”/eduservice/test.asp,第 25 行

但是,如果我修改程序集不使用數組,這一切都可以正常工作,我什至可以將普通字符串或 int 發送到程序集和從程序集發送到經典 asp。 我讀了很多東西,但我得到了同樣的錯誤,

以前有人嘗試過並且成功了,請分享您的解決方案

謝謝

ASP 只能處理變體數組,而不是字符串或整數數組。 所以嘗試使用一個對象,例如,

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM