Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here's a simple project with only a few steps, to get you started. </p> <p>C# code: </p> <pre><code>using System; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; [assembly:System.CLSCompliant(true)] [assembly: ComVisible(true)] // The following GUID is for the ID of the typelib if this project is exposed to COM [assembly: Guid("7d9c5cd3-73d4-4ab1-ba98-32515256c0b0")] namespace Cheeso.ComTests { [Guid("7d9c5cd3-73d4-4ab1-ba98-32515256c0b1")] public class TestReply { public string salutation; public string name; public string time; } [Guid("7d9c5cd3-73d4-4ab1-ba98-32515256c0b2")] public class TestObj { // ctor public TestObj () {} public TestReply SayHello(string addressee) { return SayHello(addressee, "hello"); } public TestReply SayHello(string addressee, string greeting) { string x = String.Format("{0}, {1}!", greeting, addressee); Console.WriteLine("{0}", x); TestReply r = new TestReply { salutation = greeting, name = addressee, time = System.DateTime.Now.ToString("u") }; return r; } } } </code></pre> <p>VBScript client code: </p> <pre><code>Function Main() Dim obj Dim reply set obj = CreateObject("Cheeso.ComTests.TestObj") Set reply = obj.SayHello("Evgeny") WScript.Echo "Reply at: " &amp; reply.time Set reply = obj.SayHello_2("Evgeny", "wassup") WScript.Echo "Reply at: " &amp; reply.time End Function Main </code></pre> <p>To build: </p> <pre><code>(produce your .snk file, once) csc.exe /t:library /debug+ /keyfile:Foo.snk /out:TestObj.dll TestObj.cs regasm /codebase TestObj.exe </code></pre> <p>Then just run the vbscript (through cscript.exe). </p> <p>Once you get the basic thing working, you can tweak it, add GAC, make the typelib explicit, add an explicit ProgId, and so on. </p> <p>ps: FYI, this example shows what happens with overloaded .NET methods on a class registered for interop. There's an implicit _2 (_3, _4, etc) appended to the method name. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload