Page 1 of 1

Can DLL produce a message after loading executable?

Posted: Thu Dec 28, 2023 7:30 pm
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

Re: Can DLL produce a message after loading executable?

Posted: Thu Dec 28, 2023 11:21 pm
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.

Re: Can DLL produce a message after loading executable?

Posted: Thu Dec 28, 2023 11:48 pm
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

Re: Can DLL produce a message after loading executable?

Posted: Fri Dec 29, 2023 5:44 am
by wombats

Code: Select all

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

Re: Can DLL produce a message after loading executable?

Posted: Fri Dec 29, 2023 1:07 pm
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.

Re: Can DLL produce a message after loading executable?

Posted: Fri Dec 29, 2023 4:09 pm
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.

Re: Can DLL produce a message after loading executable?

Posted: Fri Dec 29, 2023 5:29 pm
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!

Re: Can DLL produce a message after loading executable?

Posted: Fri Dec 29, 2023 5:53 pm
by mk-soft
Write your own ProcedureDLL InitDLL() and call it after creating the window.

Re: Can DLL produce a message after loading executable?

Posted: Sat Dec 30, 2023 3:39 pm
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.

Re: Can DLL produce a message after loading executable?

Posted: Sat Dec 30, 2023 4:19 pm
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

Re: Can DLL produce a message after loading executable?

Posted: Sat Dec 30, 2023 8:37 pm
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_())

Re: Can DLL produce a message after loading executable?

Posted: Mon Jan 01, 2024 9:04 am
by Maya
Thank you all for the great support.
I wish I can do that using the "Threads".