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.

namespace Cool {
	public class Test {

		static void Main() {
			System.Console.WriteLine("hello!");
		}

		public int test() { return 4; }
		public int test2(int a) { return 10 + a; }
		public string hi(string s) { return "hello, " + s; }
	}
}

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

import arsd.com;

interface CsharpTest {
	int test();
	int test2(int a);
	string hi(string s);
}

void main() {
	auto obj = createComObject!CsharpTest("Cool.Test"); // early-bind dynamic version
	//auto obj = createComObject("Cool.Test"); // late-bind dynamic version

	import std.stdio;
	writeln(obj.test()); // early-bind already knows the signature
	writeln(obj.test2(12));
	writeln(obj.hi("D"));
	//writeln(obj.test!int()); // late-bind needs help
	//writeln(obj.opDispatch!("test", int)());
}

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

Public Imports

core.sys.windows.windows
public import core.sys.windows.windows;
core.sys.windows.com
public import core.sys.windows.com;
core.sys.windows.wtypes
public import core.sys.windows.wtypes;
core.sys.windows.oaidl
public import core.sys.windows.oaidl;

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
Suggestion Box / Bug Report