lloydtech
15th March 2011 15:48 UTC
VS 2010 NSIS Plugin command not found
Hi,
I am trying to write a new plug-in. The sample plugin source is given below.
[CPP]
#include "Windows.h"
#include "nsis/pluginapi.h" // nsis plugin
#pragma comment(lib,"nsis/pluginapi.lib")
HINSTANCE g_hInstance;
HWND g_hwndParent;
void __declspec(dllexport) InitStorage(HWND hwndParent, int string_size,char *variables, stack_t **stacktop,extra_parameters *extra)
{
g_hwndParent=hwndParent;
EXDLL_INIT();
{
}
}
BOOL WINAPI DllMain(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved)
{
return TRUE;
}[/CPP]
This plugin is compiled using MS Visual Studio 2010, and put in the plugins directory of NSIS. But when the SCRIPT is compiled with
StorageNSISPlugin::InitStorage
it returns an error "Invalid command StorageNSISPlugin::InitStorage". StorageNSISPlugin is the dll name of the plug-in. All other plugins I download from the NSIS web site is working properly (I am using the prebuilt plugins).
What could be the reason? How can I resolve this?
Thanks,
Lloyd
Anders
15th March 2011 18:08 UTC
My first guess would be wrong calling convention or decorated function exports, nsis export functions are cdecl with no decoration, you could try adding __cdecl after __declspec(dllexport)
(NSIS prints every plugin export at the top of its output when compiling a script)
lloydtech
16th March 2011 04:48 UTC
I have added __cdecl like
void __declspec(dllexport) __cdecl InitStorage(HWND hwndParent, int string_size,char *variables, stack_t **stacktop,extra_parameters *extra)
Now the NSIS compiler is able to find the exported function like this...
"StorageNSISPlugin::?InitStorage@@YAXPAUHWND_@@HPADPAPAU_stack_t@@PAUextra_parameters@@@Z"
This is not as expected. The expected output is "StorageNSISPlugin::InitStorage"
So where could be the mistake?
Does Visaual Studio 2010 has anything to do with this?
Thanks
Lloyd
lloydtech
16th March 2011 05:08 UTC
Solved the problem. As it is a C++ file, the compiler generates that long function name. added the keyword extern "C" in front of the function to solve this.
extern "C" void __declspec(dllexport) InitStorage(HWND hwndParent, int string_size,char *variables, stack_t **stacktop,extra_parameters *extra)
Thanks
Lloyd