c++ - 无法识别 NSIS 插件功能

标签 c++ dll nsis

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

我的问题: 当我创建从 dll 调用函数的 .nsi 脚本时,出现编译错误,提示 Invalid command: 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

动态链接库代码:

#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;
}

最佳答案

Makensis 在编译时会列出所有插件及其导出的函数。

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

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

关于c++ - 无法识别 NSIS 插件功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11425915/

相关文章:

c++ - MacOS X- C++ 中的段错误 11

c++ - 如何在 C++ 中使用来自 dll 的结构?

c++ - 如何导出类函数,而不是 DLL 中的整个类

windows-7 - Windows-7 上的 nsis 重新启动以进行 .NET 4 安装不会继续安装

c++ - glOrtho 不工作?

c++ - c++中的图像哈希,具有相似的图像特征

c++ - OpenGL 红皮书示例中的无效代码。我该如何解决?

c++ - Visual Studio C++ : Debug Assertion Failed

nsis - "Exec"进入特定文件夹

NSIS 卸载程序不会删除文件/文件夹