Solved

Using Forms in a Delphi DLL

Posted on 2004-04-14
4
389 Views
Last Modified: 2010-04-05
Hello, I am a complete newbie to Delphi and have been trying to create a AIM Plugin.

Below is what i am using to Load my DLL when AIM starts:

library AIMPlugin;

uses
  SysUtils,
  Windows,
  Messages,
  Classes,
  Unit1 in 'Unit1.pas' {Form1};

{$E .ocm}

//Called when AIM Starts
function OCMOpen(dword:DWORD):Boolean;stdcall;
begin
Form1.Show;
end;

//Called when AIM Closes
function OCMClose():Boolean;stdcall;
begin
Exit;
end;

//Called when an even occurs
function OCMRegister(int1, int2 ,int3, int4 : Integer):Integer;stdcall;
begin

end;

exports OCMOpen, OCMClose, OCMRegister;

end.

Now this works, but when trying to show a Form, i get nasty errors, Access Violations and a Runtime 217 error. I have played around and modified things, only to find it made things worse. Is there something im doing wrong?? I can show messgaboxes and stuff, but not show Forms. If i replace the Form1.Show; with a messagebox, it shows when AIM loads and no errors. Should i be using ShareMem? Please help somone, any info would be greatly appreciated!
0
Comment
Question by:EvilPhil
  • 2
4 Comments
 
LVL 3

Expert Comment

by:BJThomsen
ID: 10828491
I see you are doing a Form1.show but I see no code where you actually create the form.
0
 
LVL 3

Accepted Solution

by:
BJThomsen earned 125 total points
ID: 10828500
You need to so a Form1 := TForm1.Create(nil);
before the show.

Not sure but probably a Form1.Free; in the function OCMClose.
0
 

Author Comment

by:EvilPhil
ID: 10828710
O wow! Thanx man!!!! WOw i feel STUPID!!! I changed some stuff into this:

{$E .ocm}
{$R *.dfm}

type
  TForm1 = class(TForm)
    Button1: TButton;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

function OCMOpen(dword:DWORD):Boolean;stdcall;
begin

   Form1 := TForm1.Create(nil);
   Form1.Show;

end;

And now it works!!! This is great! Thanx alot!!! I though i could call my form from inside Unit1.pas, but now im starting to understand how Delphi works, thanx alot!!! I need to go read some books...
0
 

Expert Comment

by:loadman
ID: 20634503
Great!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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 add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

832 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