Tom>С остальным сам справишься?
Как то так:
namespace ConsoleApplication7
{
[GuidAttribute("682E2D3C-FF7B-4833-8DDF-6CF25389E729")]
[ComVisible(true)]
[ClassInterface(ClassInterfaceType.AutoDual)]
public class Foo
{
public string Bar()
{
return string.Format("Hello, world from process {0}", Process.GetCurrentProcess().Id);
}
}
class Program
{
static private void RegisterManagedType(Type type)
{
String strClsId = "{" + Marshal.GenerateGuidForType(type).ToString().ToUpper(CultureInfo.InvariantCulture) + "}";
// Create the HKEY_CLASS_ROOT\CLSID key.
using (RegistryKey ClsIdRootKey = Registry.ClassesRoot.CreateSubKey("CLSID"))
{
// Create the HKEY_CLASS_ROOT\CLSID\<CLSID> key.
using (RegistryKey ClsIdKey = ClsIdRootKey.CreateSubKey(strClsId))
{
ClsIdKey.SetValue("", type.FullName);
// Create the HKEY_CLASS_ROOT\CLSID\<CLSID>\LocalServer32 key.
using (RegistryKey LocalServerKey = ClsIdKey.CreateSubKey("LocalServer32"))
{
LocalServerKey.SetValue("", (new Uri(Assembly.GetExecutingAssembly().CodeBase)).LocalPath);
}
}
}
}
[MTAThread]
static void Main(string[] args)
{
RegistrationServices rs = new RegistrationServices();
if ((args.Length == 1) && (args[0] == "register"))
{
RegisterManagedType(typeof(Foo));
Console.WriteLine("Server registered, press any key to exit");
Console.ReadKey();
return;
}
Guid FooGuid = typeof(Foo).GUID;
rs.RegisterTypeForComClients(
typeof(Foo),
RegistrationClassContext.RemoteServer | RegistrationClassContext.LocalServer | RegistrationClassContext.InProcessServer,
RegistrationConnectionType.MultipleUse);
Console.WriteLine("Server started, press any key to exit");
Console.ReadKey();
}
}
}
Ну и скрипт для проверки сего дела:
Dim oFoo
set oFoo = CreateObject("ConsoleApplication7.Foo")
WScript.echo oFoo.Bar