Skip to content
⌘ NSIS Forum Archive

NSIS plugin load

4 posts

checkthestack#

NSIS plugin load

Hello!

We have a program that is downloaded around 1000 users per day. Installer is NSIS based. Recently we wrote a plugin for it and it seems that in some cases plugin can't be loaded/function can't be executed on some user machines. 1 of 4 installers fails.

Here is the function from plugin.

EXTERN_C void __declspec(dllexport) __cdecl test(HWND hwndParent, int string_size,
LPTSTR variables, stack_t **stacktop,
extra_parameters *extra, ...)
{
EXDLL_INIT();
{
pushstring("TEST");
}
}
That is how it called

Var VAL_TEST

Function .onInit
ourPlugin::test
Pop $VAL_TEST
FunctionEnd
That is how it sended to the server

Section "Main"
inetc::get /SILENT "https://ourcompanyurl.com/api/?test=$VAL_TEST" $TEMP\r /END
SectionEnd
And in 1 of 4 times test is empty. It means that plugin didn't return value, but installer didn't crashed because query is successfull. What could be the problem?

Only one thought - may be something with DLL loading? All plugins examples that I saw were compiled with /NODEFAULTLIB but I compiled with default libs, because my c++ code didn't compiled without it. Could it be the problem?
Anders#
Yes that can definitely be the problem.

If you have access to one of the machines where it fails you can check the .DLL with http://www.dependencywalker.com/

In general, if you are linking to a msvc####.dll then it will fail to load if the C-Run Time redist. matching that version is not installed.

You can use static linking to avoid this mess.
checkthestack#
Thank you for answering, Anders!

To check exactly what causes the problem I tried to load plugin dll directly from the script using LoadLibrary. On machines where it failed it failed with error code 126 (ERROR_MOD_NOT_FOUND) that confirms your assumption. Also Dependecy Walker showed dependecies KERNEL32.DLL, ADVAPI32.DLL, MSVCP140.DLL, RPCRT4.DLL, VCRUNTIME140.DLL

I changed /MD to /MT and got another error on failed machines. Now LoadLibrary sometimes returns error 998 (ERROR_NOACCESS) Dependecy Walker shows only 3 dependecies now: KERNEL32.DLL, ADVAPI32.DLL, RPCRT4.DLL
Anders#
Maybe you are doing something wrong in DllMain, very hard for me to tell.

You should try creating a new simple .DLL and keep adding code until it fails.