![]() |
#1 |
Senior Member
Join Date: Aug 2007
Posts: 117
|
System plugin to call exported function in EXE
Hi,
I know you can use System::Call to call an exported function from a DLL, but when trying to call an exported function from an EXE, the installer just closes. Anyone know a way to do this? Thank you. |
![]() |
![]() |
![]() |
#2 |
Major Dude
Join Date: Sep 2005
Location: Somewhere over the Slaughterhouse
Posts: 797
|
I don't know if calling an exported function from an EXE file is possible at all!
When a DLL gets loaded into a process (or gets unloaded again), the DllMain() function of that DLL will be called by the OS, so that the DLL can do all the required initialization (shutdown) work - e.g. initialize the C++ Runtime, set up initial values of global variables, etc. But an EXE file does not have such DllMain() main function! It has an entry point, e.g. for C/C++ applications it's mainCRTStartup() - which will ultimately call main(). But that entry point clearly will not be called, if the EXE file does not get "executed" the normal way (but instead gets mapped into the address space of a running process). So you may end up with global variables not initialized at all and a C++ Runtime that hasn't been initialized either. That's almost certainly going to show "undefined behavior", including application (installer) crash... Don't do it! My Plugins: StdUtils | NSISList | CPUFeatures | ExecTimeout | KillProc My source of inspiration: http://youtu.be/lCwY4_0W1YI |
![]() |
![]() |
![]() |
#3 |
Major Dude
Join Date: Sep 2005
Location: Somewhere over the Slaughterhouse
Posts: 797
|
My Plugins: StdUtils | NSISList | CPUFeatures | ExecTimeout | KillProc My source of inspiration: http://youtu.be/lCwY4_0W1YI |
![]() |
![]() |
![]() |
#4 |
Senior Member
Join Date: Aug 2007
Posts: 117
|
Great thanks for the explanation! What's the point of some applications exporting functions then? Example: http://i.gyazo.com/124997fe87d9dc974d06aa186cf20da4.png
|
![]() |
![]() |
![]() |
#5 | |
Major Dude
Join Date: Sep 2005
Location: Somewhere over the Slaughterhouse
Posts: 797
|
Quote:
![]() But it's possible that an EXE file loads a DLL and then the DLL, in turn, will call an exported function from its "parent" EXE file. I think it's safe in this particular case, because the "parent" EXE has been started and initialized in the "proper" way. But it's certainly not safe to do this with any other EXE file. Also, the far better method to make a DLL call functions from the EXE is to simply make the EXE file pass the required function pointers to the DLL, when it calls the DLL function - so the called DLL function can use those pointers to "call home". My Plugins: StdUtils | NSISList | CPUFeatures | ExecTimeout | KillProc My source of inspiration: http://youtu.be/lCwY4_0W1YI |
|
![]() |
![]() |
![]() |
#6 |
Moderator
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,548
|
There are two scenarios where exporting exe functions are useful:
1) Providing optional API functions for plugins: GetProcAddress(GetModuleHandle(0), ...) 2) "User scripting" functionality where the syntax is module::function(...), then it does not matter if module is the main exe or a dll, the internal code is exactly the same. IntOp $PostCount $PostCount + 1 |
![]() |
![]() |
![]() |
#7 |
Senior Member
Join Date: Aug 2007
Posts: 117
|
Great thanks for the explanations Mulder and Anders
![]() |
![]() |
![]() |
![]() |
|
Thread Tools | Search this Thread |
Display Modes | |
|
|