我制作了一个非常简单的 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::_myFunction
或 tbox::myFunction@xyz
),那么您遇到了装饰问题。您可以尝试 extern "C"HWND __declspec(dllexport) __cdecl myFunction(...
,如果这还不够,您可能需要一个 .def 文件。
您还可以使用 Dependency Walker 查看导出...
关于c++ - 无法识别 NSIS 插件功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11425915/