juno.com.server Module

Contains boiler-plate code for creating a COM server (a DLL that exports COM classes).

Examples
 --- hello.d ---
 module hello;

 // This is the interface.

 private import juno.com.all;

 interface ISaysHello : IUnknown {
   mixin(uuid("ae0dd4b7-e817-44ff-9e11-d1cffae11f16"));

   int sayHello();
 }

 // coclass
 abstract class SaysHello {
   mixin(uuid("35115e92-33f5-4e14-9d0a-bd43c80a75af"));

   mixin Interfaces!(ISaysHello);
 }
 --- server.d ---
 module server;

 // This is the DLL's private implementation.

 import juno.com.all, juno.utils.registry, hello;

 mixin Export!(SaysHelloClass);

 // Implements ISaysHello
 class SaysHelloClass : Implements!(ISaysHello) {
   // Note: must have the same CLSID as the SaysHello coclass above.
   mixin(uuid("35115e92-33f5-4e14-9d0a-bd43c80a75af"));

   int sayHello() {
     writefln("Hello there!");
     return S_OK;
   }

 }
 --- client.d ---
 module client;

 import juno.com.core, hello;

 void main() {
   ISaysHello saysHello = SaysHello.coCreate!(ISaysHello);
   saysHello.sayHello(); // Prints "Hello there!"
   saysHello.Release();
 }
The COM server needs to be registered with the system. Usually, a CLSID is associated with the DLL in the registry (under HKEY_CLASSES_ROOT\CLSID). On Windows XP and above, an alternative is to deploy an application manifest in the same folder as the client application. This is an XML file that does the same thing as the registry method. Here's an example:

 --- client.exe.manifest ---
 <?xml version="1.0" encoding="utf-8" standalone="yes"?>
 <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
   <assemblyIdentity name="client.exe" version="1.0.0.0" type="win32"/>
   <file name="C:\\Program Files\\My COM Server\\server.dll">
     <comClass clsid="{35115e92-33f5-4e14-9d0a-bd43c80a75af}" description="SaysHello" threadingModel="Apartment"/>
  </file>
 </assembly>

Alternatively, define a static register and unregister method on each coclass implementation. If the methods exist, the DLL will register itself in the registry when 'regsvr32' is executed, and unregister itself on 'regsvr32 /u'.

Licence
See licence.txt for use and distribution terms.


Handle getHInstance();



void setHInstance(Handle value);



char[] getLocation();



int getLockCount();



void lock();



void unlock();



class ClassFactory(T): Implements!(IClassFactory);



template Export(T...)