sazr
sazr

Reputation: 25928

NSIS Plugin Function not recognised

I have made a very simple NSIS plugin that has one function in it. I have successfully compiled the Win32 DLL project into a DLL then copied it to the directory C:\Program Files (x86)\NSIS\Plugins

My Problem: When I create .nsi script that calls a function from the dll I get a compile error saying Invalid command: tbox::myFunction

What am I doing wrong? Do I need to copy the tbox.lib file to the NSIS directory aswell or create a tbox.nsh file to include?

My dll's name is tbox.dll, my nsi script is below and below that is my C++ DLL code:

    !include MUI2.nsh
    !include WinMessages.nsh

    Name    "aa.nsi"
    OutFile "aa.exe"
    Caption "${^Name}"
    ShowInstDetails show
    !define MUI_CUSTOMFUNCTION_GUIINIT   MyGUIInit

    Section "Dummy"
        MessageBox MB_ICONINFORMATION|MB_OKCANCEL "dvkjdkj"
        tbox::myFunction "abc" "def"
    SectionEnd

DLL Code:

#include "targetver.h"
#define WIN32_LEAN_AND_MEAN
#include <windows.h>

#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h>
#pragma comment(lib, "msimg32.lib")
#include <commctrl.h>
#include "TransparentCheckbox.h"
#include "NSIS/pluginapi.h"

HINSTANCE g_hInstance;
HWND g_hwndParent;
unsigned int g_stringsize;
stack_t **g_stacktop;
TCHAR *g_variables;

// To work with Unicode version of NSIS, please use TCHAR-type functions for accessing the variables and the stack.
HWND __declspec(dllexport) myFunction(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop, extra_parameters *extra)
{
  g_hwndParent=hwndParent;
  EXDLL_INIT();

  {
    TCHAR buf[1024];
    wsprintf(buf,TEXT("string_size=%d, variables=%s\n"), string_size, variables);
    MessageBox(g_hwndParent,buf,0,MB_OK);
  }

  return g_hwndParent;
}

BOOL WINAPI DllMain(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved)
{
  g_hInstance = (HINSTANCE)hInst;
  return TRUE;
}

Upvotes: 3

Views: 1226

Answers (2)

Slappy
Slappy

Reputation: 5472

If you want to load plug-in in current script directory use this command:

 !addplugindir "."

Upvotes: 0

Anders
Anders

Reputation: 101569

Makensis lists all plugins and their exported functions when you compile.

If your plugin is not listed then it is not in the correct directory or has no exports at all. If it is listed but has the wrong name (tbox::_myFunction or tbox::myFunction@xyz) then you have a decoration problem. You can try extern "C" HWND __declspec(dllexport) __cdecl myFunction(..., if that is not enough you might need a .def file.

You can also take a look at the exports with Dependency Walker...

Upvotes: 6

Related Questions