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:

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

PFNDESTROYED
alias PFNDESTROYED = void function()

Undocumented in source.

pfn_t
alias pfn_t = HRESULT function()

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

Classes

ClassFactory
class ClassFactory(Class)

Undocumented in source.

ComException
class ComException

Functions

ComCheck
bool ComCheck(HRESULT hr, string desc)
ObjectDestroyed
void ObjectDestroyed()

Undocumented in source. Be warned that the author may not have intended to support it.

SetKeyAndValue
BOOL SetKeyAndValue(LPCSTR pszKey, LPCSTR pszSubkey, LPCSTR pszValue)

Undocumented in source. Be warned that the author may not have intended to support it.

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.

dll_regserver
int dll_regserver(const(char)* dllname, int flag)

Undocumented in source. Be warned that the author may not have intended to support it.

gc_init
void gc_init()

Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.

gc_term
void gc_term()

Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.

getFromVariant
T getFromVariant(VARIANT arg)

Undocumented in source. Be warned that the author may not have intended to support it.

guidForClassName
GUID guidForClassName(wstring c)

Undocumented in source. Be warned that the author may not have intended to support it.

hasGuidAttribute
bool hasGuidAttribute()

Undocumented in source. Be warned that the author may not have intended to support it.

initializeClassicCom
void initializeClassicCom()
oleCharsToString
char[] oleCharsToString(char[] buffer, OLECHAR* chars)

Undocumented in source. Be warned that the author may not have intended to support it.

rt_init
void rt_init()

Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.

rt_term
void rt_term()

Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.

stringToGuid
GUID stringToGuid(string g)

Undocumented in source. Be warned that the author may not have intended to support it.

toComVariant
VARIANT toComVariant(T arg)

Undocumented in source. Be warned that the author may not have intended to support it.

unicode2ansi
void unicode2ansi(char* s)

Undocumented in source. Be warned that the author may not have intended to support it.

Interfaces

Dynamic
interface Dynamic

Undocumented in source.

Mixin templates

ComObjectImpl
mixintemplate ComObjectImpl()

Mixin to a low-level COM implementation class

ComServerMain
mixintemplate ComServerMain(Class, string progId, string ver)

Undocumented in source.

IDispatchImpl
mixintemplate IDispatchImpl()

Mixin to a low-level COM implementation class

Static variables

coInitializeCalled
int coInitializeCalled;

Undocumented in source.

g_cLock
ULONG g_cLock;

Undocumented in source.

g_cObj
ULONG g_cObj;

Undocumented in source.

Structs

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

Undocumented in source.

Templates

Dify
template Dify(T)

Undocumented in source.

getGuidAttribute
template getGuidAttribute(T)

Undocumented in source.

Meta