Old 15th February 2019, 11:18   #1
checkthestack
Junior Member
 
Join Date: Feb 2019
Posts: 2
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.

code:
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
code:

Var VAL_TEST

Function .onInit
ourPlugin::test
Pop $VAL_TEST
FunctionEnd



That is how it sended to the server
code:

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?
checkthestack is offline   Reply With Quote
Old 15th February 2019, 14:02   #2
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,013
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.

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 18th February 2019, 07:43   #3
checkthestack
Junior Member
 
Join Date: Feb 2019
Posts: 2
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
checkthestack is offline   Reply With Quote
Old 18th February 2019, 10:28   #4
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,013
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.

IntOp $PostCount $PostCount + 1
Anders 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