Tutorial on C++ Integration?
Mike McKee via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Sep 28 00:08:50 PDT 2015
I'm using Qt/C++ on a Mac. I want to try my hand at making a
dylib in D that can receive a C++ string, reverse it, and respond
with the result back to Qt/C++.
Are there any easy tutorials out there with something simple like
that?
You probably want me to type some code so that I showed that I at
least tried something. Okay, here's me just guessing:
// test.dylib
auto _cstr2dstr(inout(char)* cstr) {
import core.stdc.string: strlen;
return cstr ? cstr[0 .. strlen(cstr)] : cstr[0 .. 0];
}
extern(C++) char* reverseString(char* cstr) {
import std.string;
import std.algorithm;
s = _cstr2dstr(cstr);
s = s.reverse();
return toStringz(s);
}
Also, what do I type to define this as a class that C++ can call,
such as the following C++?
QObject Foo = new Foo();
qDebug() << Foo.reverseString('bar');
Next, I'm a bit fuzzy on how to compile that into a dylib yet, as
well as how to call this inside of Qt/C++ with QtCreator.
More information about the Digitalmars-d-learn
mailing list