arsd.com

Code for COM interop on Windows. You can use it to consume COM objects (including several objects from .net assemblies) and to create COM servers with a natural D interface.

This code is not well tested, don't rely on it yet. But even in its incomplete state it might help in some cases.

1 namespace Cool {
2 	public class Test {
3 
4 		static void Main() {
5 			System.Console.WriteLine("hello!");
6 		}
7 
8 		public int test() { return 4; }
9 		public int test2(int a) { return 10 + a; }
10 		public string hi(string s) { return "hello, " + s; }
11 	}
12 }

Compile it into a library like normal, then regasm it to register the assembly... then the following D code will work:

1 import arsd.com;
2 
3 interface CsharpTest {
4 	int test();
5 	int test2(int a);
6 	string hi(string s);
7 }
8 
9 void main() {
10 	auto obj = createComObject!CsharpTest("Cool.Test"); // early-bind dynamic version
11 	//auto obj = createComObject("Cool.Test"); // late-bind dynamic version
12 
13 	import std.stdio;
14 	writeln(obj.test()); // early-bind already knows the signature
15 	writeln(obj.test2(12));
16 	writeln(obj.hi("D"));
17 	//writeln(obj.test!int()); // late-bind needs help
18 	//writeln(obj.opDispatch!("test", int)());
19 }

I'll show a COM server example later. It is cool to call D objects from JScript and such.

Members

Aliases

pfn_t
alias pfn_t = HRESULT function()

Register/unregister a DLL server. Input: flag !=0: register ==0: unregister

Classes

ComException
class ComException

Functions

ComCheck
bool ComCheck(HRESULT hr, string desc)
createComObject
auto createComObject(wstring c)
auto createComObject(GUID classId)

Create a COM object. The passed interface should be a child of IUnknown and from core.sys.windows or have a ComGuid UDA, or be something else entirely and you get dynamic binding.

initializeClassicCom
void initializeClassicCom()

Mixin templates

ComObjectImpl
mixintemplate ComObjectImpl()

Mixin to a low-level COM implementation class

IDispatchImpl
mixintemplate IDispatchImpl()

Mixin to a low-level COM implementation class

Structs

ComClient
struct ComClient(DVersion, ComVersion = IDispatch)
ComGuid
struct ComGuid

Meta

Suggestion Box / Bug Report