Old 28th June 2015, 14:01   #1
parasoul
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.
parasoul is offline   Reply With Quote
Old 28th June 2015, 14:29   #2
LoRd_MuldeR
Major Dude
 
LoRd_MuldeR's Avatar
 
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
LoRd_MuldeR is offline   Reply With Quote
Old 28th June 2015, 14:59   #3
LoRd_MuldeR
Major Dude
 
LoRd_MuldeR's Avatar
 
Join Date: Sep 2005
Location: Somewhere over the Slaughterhouse
Posts: 797
See also:
https://groups.google.com/d/msg/micr...o/5ufXiA7ExwoJ

My Plugins: StdUtils | NSISList | CPUFeatures | ExecTimeout | KillProc
My source of inspiration: http://youtu.be/lCwY4_0W1YI
LoRd_MuldeR is offline   Reply With Quote
Old 28th June 2015, 15:29   #4
parasoul
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
parasoul is offline   Reply With Quote
Old 28th June 2015, 15:35   #5
LoRd_MuldeR
Major Dude
 
LoRd_MuldeR's Avatar
 
Join Date: Sep 2005
Location: Somewhere over the Slaughterhouse
Posts: 797
Quote:
Originally Posted by parasoul View Post
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

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
LoRd_MuldeR is offline   Reply With Quote
Old 28th June 2015, 16:58   #6
Anders
Moderator
 
Anders's Avatar
 
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
Anders is offline   Reply With Quote
Old 30th June 2015, 01:29   #7
parasoul
Senior Member
 
Join Date: Aug 2007
Posts: 117
Great thanks for the explanations Mulder and Anders very helpful
parasoul is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump