Winamp & Shoutcast Forums

Winamp & Shoutcast Forums (http://forums.winamp.com/index.php)
-   NSIS Discussion (http://forums.winamp.com/forumdisplay.php?f=65)
-   -   System plugin to call exported function in EXE (http://forums.winamp.com/showthread.php?t=381412)

parasoul 28th June 2015 13:01

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.

LoRd_MuldeR 28th June 2015 13:29

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!

LoRd_MuldeR 28th June 2015 13:59

See also:
https://groups.google.com/d/msg/micr...o/5ufXiA7ExwoJ

parasoul 28th June 2015 14:29

Great thanks for the explanation! What's the point of some applications exporting functions then? Example: http://i.gyazo.com/124997fe87d9dc974d06aa186cf20da4.png

LoRd_MuldeR 28th June 2015 14:35

Quote:

Originally Posted by parasoul (Post 3026962)
Great thanks for the explanation! What's the point of some applications exporting functions then? Example: http://i.gyazo.com/124997fe87d9dc974d06aa186cf20da4.png

Not quite sure :confused:

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".

Anders 28th June 2015 15:58

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.

parasoul 30th June 2015 00:29

Great thanks for the explanations Mulder and Anders :D very helpful


All times are GMT. The time now is 17:19.

Copyright © 1999 - 2010 Nullsoft. All Rights Reserved.