出處:http://abeln.bokee.com/vIEwdiary.11421127.Html
文件要滿足示例所示的邏輯格式
其中sk.snk由sn.exe產生,即sn -k sk.snk
guid由guidgen.exe產生,分別標識接口id和類id
//bb.cs
using System;
using System.Runtime.InteropServices;
using System.Reflection;
using System.Runtime.CompilerServices;
[assembly: AssemblyKeyFile("sk.snk")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace myNamespace{
[Guid("1CFC458F-640D-4c5d-8F61-F7ABA70839B6")]
public interface ifce{
void setString(string s);
string getString();
}
[Guid("7C93C4BE-1111-4ee7-996E-0F3F5C27F82A")]
public class xiaobao:ifce{
private string Str;
public xiaobao(){Str = "";}
public xiaobao(string ss){Str = ss;}
public string getString(){return Str;}
public void setString(string s){Str = s;}
}
}
編譯及注冊
csc /t:library /out:bb.DLL bb.cs
tlbexp bb.dll /out:bb.tlb
regasm /tlb:bb.tlb bb.dll
gacutil /I bb.dll
測試
建立.vbs文件,其中輸入
set obj = createobject("myNamespace.xiaobao")
obj.setString("success")
msgbox obj.getString
set obj = nothing
保存後雙擊運行之,有對話框彈出則ok,否則請核實。