How NSIS plugins work

NSIS plugins are regular DLLs that export functions with typical def-files like this:

LIBRARY MY_NSIS_PLUGIN
EXPORTS
    AddUser      PRIVATE    
    CreateHive   PRIVATE
    ...

They should be put to “C:\Program Files\NSIS\Plugins\x86-ansi” directory for NSIS v3.x. From nsi-script their functions can be called like this:

Function MyFunc
  ...
  MY_NSIS_PLUGIN::CreateHive
  ...
FunctionEnd

and can be tested with C++ code like this:

typedef bool (*CreateHiveFunc)();

int main()
{
	auto h = ::LoadLibrary(L"C:\\Program Files\\NSIS\\Plugins\\x86-ansi\\MY_NSIS_PLUGIN.dll");

	auto e = ::GetLastError();

	FARPROC proc = GetProcAddress(h, "CreateHive");

	e = ::GetLastError();
	
	CreateHiveFunc func = (CreateHiveFunc)(proc);

	bool val = func();

	return 0;
}

Links:

Leave a Reply

Your email address will not be published. Required fields are marked *