Delphi BPLs do a DLL name mangling as explained in this German article http://edn.embarcadero.com/article/27758 (use your favorite translator page if needed). The name mangling is obviously different than using __declspec(dllexport) from visual C++

Are there any known ways of using the classes exposed in a BPL from Visual C++? If not, how would one go about tackling a task like this?

[EDIT] Assume this task must be accomplished.

  • 3
    Editing to say "assume this task must be accomplished" doesn't change the basic reality of the situation: this is an insanely infeasible to thing to try to accomplish. If you want to make Delphi code run, use Delphi. If you really need to get Delphi code to run from C++, you could try Embarcadero's C++ Builder, but trying to get your Visual C++ codebase to build there would present problems of its own, of course. – Mason Wheeler Sep 12 '16 at 19:21
  • 1
    But really, this feels like an XY problem, where you're trying to accomplish Y, and you say "that would be easy if only I could do X", so you ask how to do X and it turns out X is impossible. What are you really trying to accomplish? – Mason Wheeler Sep 12 '16 at 19:23
  • Assume linking the methods into a VC++ directly are not viable, there are many ways to solve this problem. For instance one could build a COM bridge or manually flatten the object and export from C++ builder. Looking for strategy here... – Jasper Schellingerhout Sep 12 '16 at 19:38
  • Do you have source? If so, type for a couple of days and convert them to C++. What is the point anyway? What is so special about these bpl modules? You could fiddle with them using Win32 functions LoadLibrary and GetProcAddess. Here are some ways to explore what is available in a dll. stackoverflow.com/questions/4438900/how-to-view-dll-functions – Martin Maat Sep 12 '16 at 21:35
  • @MartinMaat I'm interested in strategy planning rather than a specific sample. At this point I'm leaning towards flattening the objects manually into a helper dll. I will post as an answer to my own question. Hopefully, it will prompt better suggestions than "don't" – Jasper Schellingerhout Sep 13 '16 at 13:04

The best answer to this question is "don't".

BPLs are much more than ordinary DLLs; they're containers for object-oriented code libraries and all the metadata needed to support them, not unlike Java's JARs or .NET assemblies. (And in fact, Anders Hejlsberg was the principal architect for both Delphi and the .NET framework, so this isn't surprising.) Instantiating and working with Delphi classes assumes a bunch of low-level plumbing that the language ordinarily takes care of. To try to do it from Visual C++ would be such an enormous headache it's not even worth thinking about.

| improve this answer | |
  • BPLs are no more than DLLs just as C++ class exports are just DLLs. The plumbing magic is all just in the name mangling. Assume this task MUST be accomplished, HOW would it be approached? – Jasper Schellingerhout Sep 12 '16 at 19:07
  • @JasperSchellingerhout There is far more to it than just the name mangling. The Delphi object model is complete different from the C++ object model. Even if you had a reference to the constructor, you couldn't instantiate one just by calling it (or calling new) because constructors work completely differently. Not to mention Delphi's TClass metaclasses and virtual constructors, or even ordinary virtual methods--the Delphi VMT is laid out completely differently from a C++ vtable, and so on. – Mason Wheeler Sep 12 '16 at 19:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.