2009-08-31 49 views
6

我需要爲我的經典ASP創建一個COM對象,因爲我可以創建一個.net程序集,並使用'COM'與COM互操作,所以我繼續創建.NET程序集是這樣的: -COM Interop(如何將數組傳遞給COM)通過傳統的ASP

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) 

和我得到的錯誤:

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

但是,如果我修改大會不要使用數組,這一切只是工作,我甚至可以發送普通字符串或int和從組裝到傳統的ASP。 我看了這麼多的東西,但我得到了同樣的錯誤,

人之前嘗試這樣做,是成功的,請你分享你的解決方案

感謝

回答

9

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

感謝這麼多的答覆......等不及try..will更新您的狀態 – visual 2009-08-31 21:24:36

+0

OrbMan,謝謝,你解決了我的問題,希望我能治療你吃午飯。 – visual 2009-09-01 00:57:45

+0

沒有probs,很高興提供幫助。 – RedFilter 2009-09-01 12:24:46

相關問題