?
Solved

BPL + unit + procedure

Posted on 2003-02-27
4
Medium Priority
?
319 Views
Last Modified: 2010-04-04
Hi,

I cretae a .BPL.
At this BPL I add a simple unit (not TForm or TComponent) with many procedure and functions.

What's the way to use these procedure and functions when I dynamically load the package in my project ?

Jean-Luc !
0
Comment
Question by:Alphomega
  • 2
  • 2
4 Comments
 
LVL 9

Accepted Solution

by:
mocarts earned 300 total points
ID: 8033464
dynamically loaded packages don't differs from dll in this situation. you must define procedure/function type (prototype) and use GetProcAddress(..).
another way is to use interfaces - define one interface with all methods you need and implement it in your package as object.
when package is loaded get that interface by calling one proc/func (through GetProcAddress) and use it in your programm.
there of course is much more solutions (for examp. filling some pointer structures and etc.)

wbr, mo.
0
 

Author Comment

by:Alphomega
ID: 8035620
It doesn't work with GetProcAddress. Can you correct the code ?

unit fct_AlphoPackD6;

interface

function DivParDeux(V: integer): single; stdcall;

implementation

function DivParDeux(V: integer): single;
begin
 result := V / 2;
end;

end.

The unit is added to the package.

The code to call the function:

procedure TForm1.Button2Click(Sender: TObject);
type
  TMyProc = function(V: integer): single; stdcall;
var
  Plugin: HModule;
  MyProc: TMyProc;
begin
  Plugin := LoadPackage('AlphoPackD6.bpl');
  if Plugin <> 0 then
  begin
    @MyProc := GetProcAddress(Plugin, 'DivParDeux');
    if @MyProc <> nil then
    begin
     ShowMessage(FloatToStr(MyProc(25)));
     @MyProc := nil;
    end
    else
      ShowMessage('procedure not found in AlphoPackD6');
    UnloadPackage(Plugin);
  end
  else
    ShowMessage('AlphoPackD6 not found');
end;

I get
      ShowMessage('procedure not found in AlphoPackD6');
0
 
LVL 9

Expert Comment

by:mocarts
ID: 8036539
as in dll you must export your functions.
at the end of your unit fct_AlphoPackD6 add exports block:

...
exports
  DivParDeux;
end.

mo.
0
 

Author Comment

by:Alphomega
ID: 8040008
Ok, it work very well !

Thanks a lot !
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question