NSIS插件功能无法识别

NSIS Plugin Function not recognised

本文关键字:识别 功能 插件 NSIS      更新时间:2023-10-16

我制作了一个非常简单的NSIS插件,其中有一个函数。我已经成功地将Win32 DLL项目编译成DLL,然后将其复制到目录C:\Program Files(x86)\NSIS\Plugins

我的问题:当我创建从dll调用函数的.nsi脚本时,我收到一个编译错误,说无效命令:tbox::myFunction

我做错了什么我需要将tbox.lib文件也复制到NSIS目录中,还是创建一个tbox.nsh文件来包含

我的dll的名称是tbox.dll,我的nsi脚本在下面,下面是我的C++dll代码:

    !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代码:

#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=%sn"), 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;
}
编译时Makensis列出了所有插件及其导出的函数。

如果你的插件没有列出,那么它不在正确的目录中,或者根本没有导出。如果它已列出,但名称(tbox::_myFunctiontbox::myFunction@xyz)错误,则说明存在装饰问题。您可以尝试extern "C" HWND __declspec(dllexport) __cdecl myFunction(...,如果这还不够,您可能需要一个.def文件。

您还可以使用Dependency Walker查看导出。。。

如果您想在当前脚本目录中加载插件,请使用以下命令:

 !addplugindir "."