I have a Delphi application that I have written a fairly simple wrapper .exe for.
Basically, there was a dll that had a bunch of functions, one of which I would call iteratively once my wrapper did what it needed to. I am not in control of this dll file, and will never be.
Well, now this DLL is a BPL, and I'm not sure how to call functions within that file. Thanks in advance.
Dynamic-link library (DLL) used by Delphi, a software development application; may contain a run-time package for compiled applications, or may store a component that extends the Delphi IDE; can be shared across multiple projects.
A package is a specially compiled library used by applications, the IDE, or both. Packages allow you to rearrange where code resides without affecting the source code. This is sometimes referred to as application partitioning. Runtime packages provide functionality when a user runs an application.
The easy way to use functions from a package is to "use" the unit that contains the function, call it as usual, and put the package on the list of your project's runtime packages. For that to work, there are a few requirements:
If you can't satisfy the third requirement, or if you don't want to have the package loaded all the time, then you can call LoadPackage
for it instead. The way to make that work is to have another package that is loaded all the time. It will be used by both your project and the package you wish to load. The intermediate package will expose an interface (such as some registration functions, a variable, or a class) that the main package can use to tell the application what its functions are. You won't be able to "use" the main package's unit in your application directly.
If you can't satisfy the first two requirements, then there is the much harder way, which is also what you'd need to do if your application isn't written in Delphi or C++ Builder. Treat the package like an ordinary DLL. Load it with LoadLibrary
. Use GetProcAddress
to load its Initialize
function, and then call it. (Remember that the calling convention is register
, not stdcall
.) Then load the address of the function you wish to call, keeping in mind that the name of the function has been mangled to include some unit and type information. Call the Finalize
function before you call FreeLibrary
. Check the source for LoadPackage
and UnloadPackage
; whether you need to call CheckForDuplicateUnits
probably depends on whether you can satisfy requirement number 1.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With