【发布时间】:2018-12-01 22:47:05
【问题描述】:
我有一个外部方法的 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 library\n");
}
// Get the function pointer
runScript = (RUNSCRIPT_FUNCTION)GetProcAddress(dll, "getAlgorithmInstance");
if (runScript == NULL)
{
FreeLibrary(dll);
printf("Unable to load function\n");
}
// 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和垃圾。
编辑 basic_hash 它的类
extern "C" class basic_hash
{
public:
virtual ~basic_hash() {}
virtual void reset() = 0;
virtual void hash(const byte*, uint64, vector_byte&) = 0;
};
【问题讨论】:
-
请贴上pointerBasicHash::hash()的签名
-
对不起,我编辑了代码指针基本哈希它是
basic_hash* pointerBasicHash; -
你测试得到
pointerBasicHash类的hash函数了吗?