Windows COM objects accessability
JC
johnch_atms at hotmail.com
Thu Sep 28 04:35:23 PDT 2006
"jicman" <cabrera at wrc.xerox.com> wrote in message
news:effj86$2u2v$1 at digitaldaemon.com...
> So, the question is, has anyone being able to access Windows COM
> objects? Any quick sample will do.
>
> thanks,
>
> jos
There are two ways to go about this: 1) Early binding - download the
Illustrator SDK, which should include the COM type library and C headers,
which you'd then need to translate to D modules. 2) Late binding. Neither
route is going to be as straightforward as JScript (which, incidentally,
uses late binding behind the scenes).
If you choose early binding, try running TlbImpD on the type library
(http://www.paperocean.org/d/tlbimpd.zip). It attempts to generate a D
module from the definitions in the library.
If, on the other hand, you fancy a real challenge and choose the late
binding method, I've put together some code that should help.
http://www.paperocean.org/d/comtest.zip. The sample in the zip file shows
how to automate an Internet Explorer instance. Here's a simplistic example
for Illustrator:
import com;
void main() {
// var app = w.CreateObject("Illustrator.Application.3");
auto app = coCreate!(IDispatch)("Illustrator.Application.3",
CoClassContext.LocalServer);
// var doc = app.Open("myfile.ai");
auto doc = com_cast!(IDispatch)(invokeCOMMember(app, "Open",
DispatchFlags.InvokeMethod, "myfile.ai"));
// var textFrames = doc.TextFrames;
auto textFrames = com_cast!(IDispatch)(invokeCOMMember(doc,
"TextFrames", DispatchFlags.GetProperty));
// var textFramesCount = textFrames.Count;
int textFramesCount = com_cast!(int)(invokeCOMMember(textFrames,
"Count", DispatchFlags.GetProperty));
// Clean up
releaseCOMObject(textFrames);
releaseCOMObject(doc);
releaseCOMObject(app);
}
That should get you started.
John.
More information about the Digitalmars-d-learn
mailing list