Solved

DLL with a form and result

Posted on 2006-06-19
9
168 Views
Last Modified: 2010-04-05
I need a skeleton DLL that shows a form with a Memo, checkbox and two buttons.
When the form is closed, I need the DLL to return the value of the checkbox
(0 for unchecked, 1 for checked). This is for a EULA dialog with a do not show again checkbox.

I'd like to load the DLL and then call a function like ShowEULA and then have the result of the
checkbox returned, If the user clicks button2, I'd like a result of 2 returned.
0
Comment
Question by:EddieShipman
  • 6
  • 3
9 Comments
 
LVL 10

Expert Comment

by:atul_parmar
ID: 16935154
Hi,

The dll will look like the following.

library EULA;

uses
  SysUtils,
  Classes,
  Unit1 in 'Unit1.pas' {Form1}; // This is your form what contains memo, checkbox, button etc.

{$R *.res}

function ShowEULA : boolean;
begin
  with TForm1.Create(nil) do
  begin
    try
      ShowModal;
      Result := CheckBox1.Checked;
    finally
      Free;
    end;
  end;
end;

exports
  ShowEULA;

begin
end.
0
 
LVL 10

Accepted Solution

by:
atul_parmar earned 500 total points
ID: 16935216
Sorry, you need the result to be 0, 1 and 2. So, I expect that Button1 will set the ModalResult to mrOk and Button2 will brCancel.

function ShowEULA : Integer;
begin
  with TForm1.Create(nil) do
  begin
    try
      if ShowModal = mrOk then
      begin
        if CheckBox1.Checked then Result := 1 else Result := 0;
      end
      else // for 2nd button
         Result := 2;
    finally
      Free;
    end;
  end;
end;
0
 
LVL 26

Author Comment

by:EddieShipman
ID: 16935235
I was going to accept that as answer but you only return one value.
I need a 0 if unchecked, 1 if checked, and 2 if button2 was clicked.
0
 
LVL 26

Author Comment

by:EddieShipman
ID: 16935237
oh, didn't see your second post...
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 26

Author Comment

by:EddieShipman
ID: 16935255
Now do I use it like this:

LoadLibrary(EULA)
case ShowEULA of
0: do this
1: do this
2: do this
end;
ReleaseLibrary(EULA);

0
 
LVL 26

Author Comment

by:EddieShipman
ID: 16935258
I mean FreeLIbrary(EULA);
0
 
LVL 26

Author Comment

by:EddieShipman
ID: 16935327
Ok, got it:

type
   TEULAFunc = function: integer; stdcall;

procedure TForm1.Button1Click(Sender: TObject);
var
  hMod: HMODULE;
  FShowEULAFunc: TEULAFunc;
begin
  hMod := LoadLibrary('C:\Projects\EULA.dll');
  try
    @FShowEULAFunc:=GetProcAddress(hMod, 'ShowEULA');
    case FShowEULAFunc of
    0: ShowMessage('0');
    1: ShowMessage('1');
    2: ShowMessage('2');
    end;
  finally
    FreeLibrary(hMod);
  end;
end;
0
 
LVL 10

Expert Comment

by:atul_parmar
ID: 16935350
Yep.

I am moving mate, see you next day.
0
 
LVL 26

Author Comment

by:EddieShipman
ID: 16935844
Thanks for the help.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now