Re: How to call DLL with classes?
- Posted by TheresNoTime Sep 18, 2013
- 1549 views
mattlewis said...
C++ is not easy to use from a DLL. The reason for this is that C++ compilers mangle the names in order to add class and parameter and return type information to the exported symbols. It's possible to use these mangled names in your #define_c_func calls, and then typically you'd pass the this## pointer as the first parameter, with the normal parameters following that. This is very fragile, however, as the mangling is different from compiler to compiler, even different versions of the same compiler. If you only need to call a few things, it might not be too bad.
By and large, I need the function "Rect" only.
said...
An easier way is to write a thin C++ wrapper with an "extern C" interface.
Here's what I got, but it's just a dirty draft.
OCRSource src = new OCRSource(); OCRDest dst = new OCRDest(); extern "C" { void* getTextFromRect(int ax, int ay, int bx, int by) { src.Rect(ax, ay, bx, by); OCR(src, dst, 0); return dst.Area; } }