Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Acessing Application and Controls from outside of EXE

Posted on 1999-07-09
19
Medium Priority
?
246 Views
Last Modified: 2010-04-06
How can i access Application object and all forms and their components from outside of compiled Delphi program? I do know that i need to hook into EXE using DLL, and i do it successfully (given any Delphi 3,4 compiled EXE i can force it to load my DLL), but DLL's Application is not the same as Application in the program.
I can not recompile given EXE, and i need the thing to work for ANY Delphi compiled program.

Any suggestions?
0
Comment
Question by:rpo
[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
  • 8
  • 6
  • 3
  • +2
19 Comments
 
LVL 13

Expert Comment

by:Epsylon
ID: 1387415
You need to know certain thing of how the app is constructed. You can check that with WinSight (Delphi tool) if you know how to look.

Getting a handle to a component may look something like this

Function GetHandle: THandle;
Var
  S: String;
Begin
  Result:= FindWindow(NIL 'WindowName');
  Result:= GetWindow(Result, GW_CHILD);
  SetLength(S, 40);
  GetClassName(Result, PChar(S), 39);
  If PChar(S) <> 'ClassName' Then Result:= 0;
End;

(See Q.10179640)

0
 
LVL 20

Expert Comment

by:Madshi
ID: 1387416
Sorry to say that, but I think it's almost impossible, since no standard Delphi exe does export or expose the application objects or the screen(.forms) object or any other object.
Why do you need that? Is there no other possibility to achieve your goals?

Regards, Madshi.
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1387417
A created a new Delphi app and put a listbox with some item and a button on it. When you press the button the first item of the list box will be deleted. It also works with another Delphi app. This is the code:

Function GetHandle: THandle;
Var
  S: String;
Begin
  Result:= FindWindow(NIL, 'MyForm');
  Result:= GetWindow(Result, GW_CHILD);
  Result:= GetWindow(Result, GW_HWNDNEXT);
  SetLength(S, 40);
  GetClassName(Result, PChar(S), 39);
  If PChar(S) <> 'TListBox' Then Result:= 0;
End;

procedure TMyForm.Button1Click(Sender: TObject);
var h: THandle;
    s: array[0..9] of Char;
begin
  s := 'Test';
  h := GetHandle;
  SendMessage(h, LB_DELETESTRING, 0, 0);
end;

0
Independent Software Vendors: 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!

 
LVL 13

Expert Comment

by:Epsylon
ID: 1387418
Huh? Madshi, what's the problem?
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1387419
Not the same thing as the other Q I hope....
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1387420
No, Eps, this time we have the DLL and the app in the same address/memory context. So not the same prob as in the other Q.
But as far as I understood rpo's question, he doesn't want to have the window *HANDLES*, but the *OBJECTS*. You know, TApplication, TForm and this stuff - the pointers to all the objects.
0
 
LVL 4

Expert Comment

by:Radler
ID: 1387421
Hi;

I've a insignificant guess:
- The problem would be soved with a interface to give a response to standard windows messages subsystem.
So at App1.FormX a user-defined message handler catch the messages sended by
App2.
 - A more sofisticated manner is use DDE/OLE that actualy is the more fashion way.
0
 
LVL 1

Author Comment

by:rpo
ID: 1387422
Just as Madshi wrote i want to get pointers to objects, not handes.

The general idea is to make something like Runtime Object Inspector which need not be compiled into EXE and can work with any Delphi compiled program (even with one created with no knowledge about this Inspector).

I already know how to get those pointers (using Win32 window's properties and atoms) but the problem is that every Delphi application has it's own list of registered classes, thus TApplication in DLL and TApplication in EXE do NOT have the same class information. I still didn't go deep into this but i think there should be solution.

Also, any message hooking or DDE/OLE won't help since messages know nothing about Delphi objects and i want it to work with EXEs which do not support any DDE or OLE stuff.

0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1387423
Now it becomes clear to me.
No sorry, that's not possible unless that application sends back a pointer on request. Even then you need to know which object reside in there.

Usually when you create an instance fo an object in Delphi you do something like this:

NewObject := TObject.Create;
...
NewObject.Free;

NewObject gets a pointer to the object this way. But what happens if you lose this pointer before you 'Free' the object? It can't be done. I know that it resides somewhere in memory, but where? I can only guess.

Eps.
0
 
LVL 1

Author Comment

by:rpo
ID: 1387424
Epsilon, it is possible. I finally got it working and here is the way.

Every Delphi application can load a specific DLL called VCLTest3.DLL (the same name holds for Delphi 3 and 4 application) as a respond to WM_COPYDATA mesage with some parameters. This way it's possible to get into any Delphi 3,4 program address space.
The next step is to get Application object and Forms. Every TWinControl has underlying Win32 window which has two properties (Win32 window properties, not Delphi, see SetProp function) :
1) Delphi<ProcessID> = Pointer to TWinControl having this property
2) ControlOfs<HInstance><CurerntThreadID> = Pointer to TWinControl having this property.

So, using first property we can walk through all windows in a system and get only those having relevant ProcessID (it can be done in few ways).
The only problem left now is Application. It is not TWinControl and although it creates window it does not set the properties for it. The only way i foun to get Application is to inspect Owner for every fond form and check if it is TApplication. This does not give 100% chance to get Application but after finding all the forms Application is not  so necessary.

That is all.

Any comments?
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1387425
Hi rpo,

thanx for this info!!! Well, I did not know, that Delphi puts the object pointers into the window properties. That's quite interesting!! So it seems you teached us something instead of learning something from us...   :-))

Are the property strings the same in D3&4 compiled exes? Or even in D2 compiled exes?

Thnx...   :-)

Regards, Madshi.
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1387426
I did not know eighter. This sure opens some perspectives.

Nice thinking   :o)


Is there any info on VCLTest3.dll? How did you find out about its existence?

Cheers,

Eps.
0
 
LVL 1

Author Comment

by:rpo
ID: 1387427
I discovered those property strings by just looking at Controls.PAS source.
These strings are the same for Delphi 3 and 4 (i don't have Delphi 2 installed, so i don't know about it).

Existence of VCLTest3.DLL was found when i tried to figure out what AllowTesting property of TApplication does.
There is no any information on VCLTest3.DLL, but it works. From looking at VCL sources i can only conclude this feature was designed to enable some kind of testing/debugging of Delphi and VCL.

If anybody interested in demo of this DLL, write here, i'll put it on the web.

P.S. How can i make my question answered without loosing the points (since i answered it)?

Roman.
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1387428
Roman, you can go to the Customer Service/Expert-Exchange area and post a request to delete Q.10180681 (=this question). If you mention in you post that you solved the question yourself, your points will be returned by one of the admins of this site.

And YES, I am SURE interested in it, so please put it on the web or mail it to: Epsylon3@hotmail.com

I eager to see it  :o)

Thanks in advance!

Eps.
0
 
LVL 1

Author Comment

by:rpo
ID: 1387429
Everybody intereted.

I put the source of VclTest3.DLL along with test project and all the stuff needed to make the DLL work on the web at http://www.geocities.com/SiliconValley/Campus/3979/VclTest.ZIP.

Do with it whatever you want.

Thanks to all.

Roman.
0
 
LVL 1

Author Comment

by:rpo
ID: 1387430
Everybody intereted.

I put the source of VclTest3.DLL along with test project and all the stuff needed to make the DLL work on the web at http://www.geocities.com/SiliconValley/Campus/3979/VclTest.ZIP.

Do with it whatever you want.

Thanks to all.

Roman.
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1387431
Roman, that's a real COOL app!!!!!    :o)
0
 
LVL 3

Accepted Solution

by:
darinw earned 900 total points
ID: 1387432
I am posting the solution found so it can be saved in the previously asked questions.  Please see your customer service question for an explanation.

darinw
Customer Service @ Experts Exchange

_______

Comment
From: rpo Date: Saturday, July 10 1999 - 03:02AM CDT  
 
Epsilon, it is possible. I finally got it working and here is the way.

Every Delphi application can load a specific DLL called VCLTest3.DLL (the same name holds for Delphi 3 and 4 application) as a respond to WM_COPYDATA mesage with some parameters. This way it's possible to get into any Delphi 3,4 program address space.
The next step is to get Application object and Forms. Every TWinControl has underlying Win32 window which has two properties (Win32 window properties, not Delphi, see SetProp function) :
1) Delphi<ProcessID> = Pointer to TWinControl having this property
2) ControlOfs<HInstance><CurerntThreadID> = Pointer to TWinControl having this property.

So, using first property we can walk through all windows in a system and get only those having relevant ProcessID (it can be done in few ways).
The only problem left now is Application. It is not TWinControl and although it creates window it does not set the properties for it. The only way i foun to get Application is to inspect Owner for every fond form and check if it is TApplication. This does not give 100% chance to get Application but after finding all the forms Application is not  so necessary.

That is all.

Any comments?
0
 
LVL 1

Author Comment

by:rpo
ID: 1387433
Thanks to customer service and to everyone here.

I have just one more comment.

After discovering object in a way discribed above it's impossible to use dynamic typecating ( the As operator ) and dynamic type checking ( the Is operator ). It follows from the fact that type information for the object resides in EXE file (used for left operand) and similar information resides in DLL (used for right operand). As and Is operators do some checks which fail because of this duality, the same result as if we write "Button as TSpeedButton" where Button is an object of TButton class. If we don't use these operators it's possible to get and set values of properties.

Roman.
0

Featured Post

Industry Leaders: 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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

664 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