我创建了自己的 dll
,它公开了一种实用方法,即 GenarateID
。头文件看起来像这样:
#ifndef GENERATE_ID_H
#define GENERATE_ID_H
#include <windows.h>
#include <string>
#include <fstream>
#include <stdio.h>
#include "openssl/sha.h"
int __declspec(dllexport) GenerateID(const char* fileName, char* retVal);
// some additional helper methods declared here, but omitted for brevity
// ...
#endif // GENERATE_ID_H
这个方法有什么作用?
它读取作为第一个参数传递的二进制文件,获取一些数据,生成该数据的 SHA256 哈希,并通过第二个参数返回它。成功时,返回的 int 值为 0,否则为负值。这里值得一提的是,我为此目的使用了 OpesSSL 库。
现在,问题就从这里开始了。正如标题所说,我无法使用 System::Call
从 NSIS 调用我的 dll
。 (我创建了简单的控制台测试可执行文件,可以毫无问题地调用该库。)
这是我根据 this short tutorial 尝试过的:
# copy the files
SetOutPath $INSTDIR
SetOverwrite on
File C:\Users\Strahinja\Desktop\CRX\testfile.zip # copy the binary
File C:\OpenSSL-Win32\libeay32.dll # copy OpenSSL library
File C:\Users\Strahinja\Desktop\CRX\IDGenerator\Release\IDGenerator.dll # copy my dll
# generate id
StrCpy $R0 "testfile.zip"
StrCpy $R1 ${NSIS_MAX_STRLEN} ;assign memory to out parameter ?
StrCpy $R2 -1
#System::Call 'IDGenerator::GenerateID(t, t)i (r10, .r11).r12'
System::Call 'IDGenerator::GenerateID(t r10,t .r11)i.r12'
DetailPrint "File parameter: $R0"
DetailPrint "Generated ID: $R1"
DetailPrint "Return value: $R2"
NSIS 说返回值是error
。有没有办法检查错误是什么,更重要的是 - 我使用这个正确吗?
作为旁注:我尝试使用 exe
而不是 dll
,以相同的方式将其复制到与 dll
相同的目录中,并调用它:
nsExec::ExecToStack '"myidgen.exe"'
Pop $R2
Pop $R1
此处的可执行文件工作正常,但我仍然更喜欢 dll。
我感觉它可能与调用约定或 dllexport
有关(因为它使用名称修改,AFAIK)
有什么建议吗?
最佳答案
错误通常表示语法错误,但也可能表示 LoadLibrary 或 GetProcAddress 失败。使用 Dependency Walker检查导出的函数是否有修饰名。
您可能希望使用 DEF 文件导出函数。
如果您使用 EXTERN_C int __cdecl __declspec(dllexport) foo()
它也应该不带修饰地导出,但是您需要将 ?c
附加到系统调用...
关于c++ - NSIS System::Call - 调用方法失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13909980/