Accessing COM Objects

Incognito via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Jun 12 18:22:33 PDT 2016


I've been reading over D's com and can't find anything useful. It 
seems there are different ways:

http://www.lunesu.com/uploads/ModernCOMProgramminginD.pdf

which is of no help and requires an idl file, which I don't have.

Then theres this

http://wiki.dlang.org/COM_Programming

which is also of no help:

import std.stdio;

import std.stdio, core.sys.windows.com, core.sys.windows.windows, 
std.exception, std.meta, std.traits;
import std.utf, core.stdc.stdlib, core.sys.windows.objidl, 
core.sys.windows.ole2;
pragma(lib, "ole32.lib");


GUID Guid(string str)()
{
     static assert(str.length==36, "Guid string must be 36 chars 
long");
     enum GUIDstring = "GUID(0x" ~ str[0..8] ~ ", 0x" ~ str[9..13] 
~ ", 0x" ~ str[14..18] ~
         ", [0x" ~ str[19..21] ~ ", 0x" ~ str[21..23] ~ ", 0x" ~ 
str[24..26] ~ ", 0x" ~ str[26..28]
         ~ ", 0x" ~ str[28..30] ~ ", 0x" ~ str[30..32] ~ ", 0x" ~ 
str[32..34] ~ ", 0x" ~ str[34..36] ~ "])";
     return mixin(GUIDstring);
}

int main(string[] argv)
{

	// Adobe Photoshop App 9.0 CLSID 
{c09f153e-dff7-4eff-a570-af82c1a5a2a8}
	// Adobe Photoshop App 9.1 CLSID 
{6DECC242-87EF-11cf-86B4-444553540000}

	auto CLSID_DOMDocument60 = 
Guid!("6DECC242-87EF-11cf-86B4-444553540000");
	auto iid = IID_IUnknown;

	void* pUnk;
	auto hr = CoCreateInstance(&CLSID_DOMDocument60, null, 
CLSCTX_ALL, &iid, &pUnk);
	if (FAILED(hr))
		throw new Exception("Error!");

     writeln("Hello D-World!");
     return 0;
}

Maybe my CLSID's are wrong. Got them from the registry. The 
exception triggers each time. Even if it worked, I wouldn't know 
how to use it.

I can do this stuff in C# by simply dragging and dropping a dll 
into the references and it works fine but is a bit slow. I was 
hoping I could speed things up using D but it seems like COM 
isn't really supported, despite what several references say.



More information about the Digitalmars-d-learn mailing list