Solved

Using Forms in a Delphi DLL

Posted on 2004-04-14
4
392 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
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…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

696 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