how to read exe's dbgrid content in DLL???

i have a exe writen by delphi(no sourcecode), the exe load a DLL, i have the DLL sourcecode,but exe's Application not pass to DLL, so i cannt read any class from exe mainform, i want read dbgrid content from exe mainform in DLL,how to resolve it???
LVL 1
sundayboysAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ginsonicCommented:
Can't! The exe must send the values to dll to can use inside dll.
0
sundayboysAuthor Commented:
no way???sigh...
0
Wim ten BrinkSelf-employed developerCommented:
It can be done but it requires a lot of knowledge of the Windows API and the Delphi VCL. You would have to find the window handle of the form that contains the grid, find the grid on this form, get the exact address of the grid itself and then use a typecast of the TDBGrid (if that is used) around the pointer that is pointing to the grid. You would have to be very aware of the memory manager in the main executable and see if you can connect to it too. (The use of Sharemem is useless since the EXE is probably NOT using it.) If you can't hook into the memory management of the main executable then you cannot use any strings in your communication between DLL and EXE since this would cause serious memory leaks and will crash the application.

I think it's easier to just rewrite that executable or just buy the source of it if someone made it for you. It might take too much time just to get it working correctly.
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

sundayboysAuthor Commented:
i want use ReadProcessMemory to find the content of grid,is it a good idea?
0
Wim ten BrinkSelf-employed developerCommented:
Use ReadProcessMemory if you want to read some memory area from another process. Since the DLL is injected in the same address space as the executable, you don't need it.
And I do consider this a very complex solution do do, what exactly? That application must be reading it's data from some database so why don't you read it from the same database?
0
DeerBearCommented:
Hi,

Once you've found the window handle, you should be able to send it the
correct control messages( there should be a bunch for DBGrid I suppose ).

why don't you look for that?

HTH,

Andrew
0
sundayboysAuthor Commented:
yeah, i can find DBGrid handle,but i dont know any control message about DBGrid,could someone helps me???

i dont know which database that exe used, username and password nobody knows :-(
0
DeerBearCommented:
Uhm... you might want to look at the Messages unit and the DBCtrls one to see if you can find any message.

Cheers,

Andrew
0
Wim ten BrinkSelf-employed developerCommented:
@Andrew,
I'm sorry to have to say this but the Grid control (including DBGrid) does NOT provide any messages to read the contents of the cells. With the DBGrid, the cells are even drawn dynamically and the grid is a virtual grid. The grid itself won't even know the contents of the cells! Therefore, even if you could get the address of the DBGrid control itself, you still won't be able to retrieve the contents from the cells. The contents from the database fields are drawn directly from the table to the canvas of the grid.

In other words, there is NO way to get the text on a DBGrid... But if it's a read TDBGrid component, you could go to the DataSource component that should be linked to it. From there you can go to the Dataset that is linked to the grid. And then you can walk through the contents of this dataset to read the whole table. Combined with other information that you might extract from the DBGrid, you might be able to determine which record/field is currently selected. But you will need to find the address of the DBGrid object for this and that's not easy. The grid handle is NOT it's address and doesn't even provide you any way to find the address. I wonder if it's even possible to find the grid's address...

It might be easier to just analyze this executable, though. There are rsource extractors that allow you to extract Delphi forms from an executable. There's a tool called Resource Hacker at http://swiss.torry.net/tools/project/resources/reshacker.zip which you can use to see the Delphi forms that are used in this executable. By looking at these forms, you might find the grid that is used and with it, the database (type) that it connects to. Unless the application uses some custom grid and no dataset components, this tool will provide you quite a lot of information. (Perhaps even username and password.)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.