Solved

Using Forms in a Delphi DLL

Posted on 2004-04-14
4
387 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Path  to current project in Delphi. 2 79
delphi prevent click fast 2 215
Working with hours 3 57
Why  'Host Connection unavailable/Socket Error #113 No route to host' 6 39
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

775 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