我有一个带有外部方法的dll
extern "C" HAL_HASH_API basic_hash* getAlgorithmInstance( int algorithm );
而basic_hash有下一个方法
// resets to the initial condition of the algorithm,
// reset the counter and the current values
virtual void reset() = 0;
// performs all encryption cycle.
virtual void hash( const byte*, uint64, vector_byte& ) = 0;
第一参数<data>
是指向数据开头的指针,第二参数<size>
指定散列数据的大小,第三参数<hash>
是存储散列值的缓冲器。矢量大小会自动更改。
我有下一种
typedef unsigned char byte;
typedef unsigned long long uint64;
typedef std::vector< byte > vector_byte;
当我初始化变量并调用hash
时
RUNSCRIPT_FUNCTION runScript;
basic_hash* pointerBasicHash;
// Load the DLL
HINSTANCE dll = LoadLibrary(L"HAL.dll");
if (dll == NULL)
{
printf("Unable to load libraryn");
}
// Get the function pointer
runScript = (RUNSCRIPT_FUNCTION)GetProcAddress(dll, "getAlgorithmInstance");
if (runScript == NULL)
{
FreeLibrary(dll);
printf("Unable to load functionn");
}
// Call the function
pointerBasicHash= (runScript)(0);
vector_byte hashresult;
hashresult.reserve(1024);
uint64 size = 8;
byte myString[] = "1234567";
const byte* buff = &myString[0];
pointerBasicHash->reset();
pointerBasicHash->hash(buff, size, hashresult);
变量hashresult
不正确,它包含系统变量PATH和垃圾。
编辑基本_现金类
extern "C" class basic_hash
{
public:
virtual ~basic_hash() {}
virtual void reset() = 0;
virtual void hash(const byte*, uint64, vector_byte&) = 0;
};
一些可能性:
-
DLL是针对不同版本的c++运行库编译的
-
DLL已针对c++运行库静态链接
-
您的应用程序已针对c++运行库进行静态链接
-
DLL中有一个错误。
注意。在DLL的接口中提供c++标准库类型通常是一个非常严重的错误。
当标准库发生变化时(例如,编译器升级),您可能需要重新编译库和所有使用它的应用程序……这首先违背了使用共享库的目标。