Solved

Using Forms in a Delphi DLL

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

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.

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

705 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

11 Experts available now in Live!

Get 1:1 Help Now