www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - pragma mangle hacking

reply "evilrat" <evilrat666 gmail.com> writes:
hello guys,

is this is possible to write full name mangle? and what compilers 
support this pragma except DMD?

i mean look at this (hacky) stuff

C++ side:
namespace somenamespace
  EXPORT int func() { return 42; }

D side:
// this is already works with MS C++
pragma(mangle, "func somenamespace")
extern(C++) int func();

and now i'm(not first of course) trying to do something like this:
// this is not currently working for me due to mangling pattern 
mismatches between DMD and VC++2013?
  class CppClass
   pragma(mangle, "?0")
   static void cppctor();

so next in code it may be possible to do
1) malloc enough space
2) move pointer to edx/eax? ... i always forgot this calling 
conventions :(
3) call cppctor
PROFIT!!11 (or actually not, who knows what else may happen here)

i'll need this at least for windows, no intention for 
portability. the whole problem is just because many "professional 
oriented" stuff has C++ API only, hacking ABI directly is not 
worth it and currently there is not so much binding generators 
available which able to produce reliable bindings.

so with just little tuning here this pragma could provide access 
for more C++ stuff including much anticipated Qt bindings and 
other libs...

p.s. stuff i'm looking at is such examples as proprietary FBX 
SDK, or 'open source' Allembic SDK and others. they both has 
bloat API so doing wrapping even for a subset of it would take 
just a lot of time(and produce more bugs).
Feb 17 2014
parent "evilrat" <evilrat666 gmail.com> writes:
ok. gone making wrappers now :(
Feb 17 2014