Can DLL produce a message after loading executable?

Just starting out? Need help? Post your questions and find answers here.
Maya

Can DLL produce a message after loading executable?

Post by Maya »

Good Evening All,
As far as I know, DLL can be launched using attached/detach process or thread.
Is it possible for attached DLL, to wait for an Executable window, then after that, generates "Hello World" Message?
Image
Last edited by Maya on Thu Dec 28, 2023 11:33 pm, edited 2 times in total.
Olli
Addict
Addict
Posts: 1198
Joined: Wed May 27, 2020 12:26 pm

Re: Can DLL produce a message after loading executable?

Post by Olli »

Maya wrote:Good evening All,
As far as I know, DLL can be launched using attached/detach process or thread.
No !
A DLL file can be launched, using LoadLibrary().

[LOAD] ---> [Execute AttachProcess() if it exists]

Let us bypass threads for now. Even if it is not very complex : it is a similar calling concept. Let us stay to the main load of a library.
Maya wrote:Is it possible for attached DLL, to wait for an Executable until it completely loaded in memory, then after that only, it generates "Hello World" Message?
What does this executable completely load in memory ?
-> its own memory buffer ?
-> its own file total content ?
-> the DLL it has loaded ?

The executable must send a flag. For example, call a specific function in the DLL.
Maya

Re: Can DLL produce a message after loading executable?

Post by Maya »

Hi,
DLL is attached to the Executable using one of the "attach/detach process/thread" methods (not sure which one).

Is the following sequence possible?

1- Executable starts.
2- DLL starts but doesn't do anything (waiting executable to be fully loaded).
3- Executable main window appears on the Desktop (fully loaded).
4- DLL generates "Hello World" Message over the Executable main window.

Image
wombats
Enthusiast
Enthusiast
Posts: 716
Joined: Thu Dec 29, 2011 5:03 pm

Re: Can DLL produce a message after loading executable?

Post by wombats »

Code: Select all

ProcedureDLL AttachProcess(Instance)
  MessageRequester("", "Attach")
EndProcedure
That pops up the message requester when I open the library.
Maya

Re: Can DLL produce a message after loading executable?

Post by Maya »

wombats wrote: Fri Dec 29, 2023 5:44 am

Code: Select all

ProcedureDLL AttachProcess(Instance)
  MessageRequester("", "Attach")
EndProcedure
That pops up the message requester when I open the library.
Hi,
"AttachProcess" pops up the Message, then it disappeared, then after, the main window appears, which is not the required sequence.
DarkDragon
Addict
Addict
Posts: 2344
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

Re: Can DLL produce a message after loading executable?

Post by DarkDragon »

Maya wrote: Fri Dec 29, 2023 1:07 pm
wombats wrote: Fri Dec 29, 2023 5:44 am

Code: Select all

ProcedureDLL AttachProcess(Instance)
  MessageRequester("", "Attach")
EndProcedure
That pops up the message requester when I open the library.
Hi,
"AttachProcess" pops up the Message, then it disappeared, then after, the main window appears, which is not the required sequence.
You could create a thread in attach, wait for the required objects to be there (Window) and execute it then. However the better way would be to have some init function called from inside the main executable.
bye,
Daniel
Maya

Re: Can DLL produce a message after loading executable?

Post by Maya »

DarkDragon wrote: Fri Dec 29, 2023 4:09 pm
Maya wrote: Fri Dec 29, 2023 1:07 pm
wombats wrote: Fri Dec 29, 2023 5:44 am

Code: Select all

ProcedureDLL AttachProcess(Instance)
  MessageRequester("", "Attach")
EndProcedure
That pops up the message requester when I open the library.
Hi,
"AttachProcess" pops up the Message, then it disappeared, then after, the main window appears, which is not the required sequence.
You could create a thread in attach, wait for the required objects to be there (Window) and execute it then. However the better way would be to have some init function called from inside the main executable.
You are right, the solution in the 'Threads', but unfortunately, I have no idea about it.
Could you please write me a sample.
Thank you!
User avatar
mk-soft
Always Here
Always Here
Posts: 6202
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Can DLL produce a message after loading executable?

Post by mk-soft »

Write your own ProcedureDLL InitDLL() and call it after creating the window.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Maya

Re: Can DLL produce a message after loading executable?

Post by Maya »

mk-soft wrote: Fri Dec 29, 2023 5:53 pm ... call it after creating the window.
I wish I can do this by the DLL itself.
Olli
Addict
Addict
Posts: 1198
Joined: Wed May 27, 2020 12:26 pm

Re: Can DLL produce a message after loading executable?

Post by Olli »

No, you cannot. An explicite flag must be passed in the executable source :

Code: Select all

; blabla
; code before the executable wants to tell the DLL.
tellTheDLL()
; code after the executable have told the DLL
DLL source :

Code: Select all

ProcedureDLL tarteAuxPoireaux()
EndProcedure

ProcedureDLL tellTheDLL()
 MessageRequester("Uh?", "The DLL received a call from the executable, by simply executing this procedure.")
EndProcedure
Smitis
New User
New User
Posts: 5
Joined: Mon Sep 04, 2023 11:58 am

Re: Can DLL produce a message after loading executable?

Post by Smitis »

Maya wrote: Thu Dec 28, 2023 7:30 pm Is it possible for attached DLL, to wait for an Executable window, then after that, generates "Hello World" Message?
Use SetWinEventHook from AttachProcess and track the creation of windows

Code: Select all

hCBTHook = SetWindowsHookEx_(#WH_CBT,@CBTProc(),#Null,GetCurrentThreadId_())
Maya

Re: Can DLL produce a message after loading executable?

Post by Maya »

Thank you all for the great support.
I wish I can do that using the "Threads".
Post Reply