仍然可以訪問我有一個C#類庫項目(DLL)與一個類,COMTEST:COM組件沒有在VBScript
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace COMTest
{
[Guid("45D639E4-FDDE-4b7b-A35F-FC19856DFF24")]
[ComVisible(true)]
public class Foo
{
public Foo()
{
Console.WriteLine("Constructing Foo");
}
private string mName = "FOO";
public string Name
{
get { return mName; }
set { mName = value; }
}
}
}
該項目註冊爲COM互操作,並將該組件進行COM-可見。目標框架是.Net 3.5,平臺目標是x86。該.dll文件使用32位C:\Windows\Microsoft.NET\Framework\v2.0.50727\RegAsm.exe /codebase COMTest.dll
我試圖訪問從VBScript(再次,32位,使用C:\Windows\SysWOW64\cscript.exe test.vbs
)這個類註冊,但我似乎具有腳本中獲取的Foo
實例問題。我可以使用課堂;我無法保留任何參考。
這裏是我的腳本:
Wscript.Echo "CreateObject(""ComTest.Foo"").Name Results: " + CreateObject("COMTest.Foo").Name
IF IsEmpty(CreateObject("COMTest.Foo")) THEN Wscript.Echo "CreateObject() is empty" ELSE Wscript.Echo "CreateObject() is NOT empty"
DIM foo : CreateObject("COMTest.Foo")
IF IsEmpty(foo) THEN Wscript.Echo "foo is empty" ELSE Wscript.Echo "foo is NOT empty"
這裏是輸出:
Constructing Foo
CreateObject("ComTest.Foo").Name Results: FOO
Constructing Foo
CreateObject() is NOT empty
Constructing Foo
foo is empty
正如你所看到的,CreateObject()
調用成功 - 我只是無法保持對它的引用該對象返回(在foo
)。
我覺得我錯過了一些簡單的東西。如何保留從CreateObject()
返回的對象?
我知道這一定很容易。謝謝。 – TreDubZedd 2012-02-21 17:13:35