【问题标题】:C++ call from dll other dll with std::vector使用 std::vector 从 dll 其他 dll 调用 C++
【发布时间】: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函数了吗?

标签: c++ vector dll stdvector


【解决方案1】:

一些可能性:

  1. 已针对不同版本的 c++ 运行时库编译 DLL

  2. DLL 已静态链接到 c+ 运行时库

  3. 您的应用程序已与 c++ 运行时库静态链接

  4. DLL 中有错误。

注意。在 DLL 的接口中提供 c++ 标准库类型通常是一个非常严重的错误。

当标准库发生变化(例如编译器升级)时,您可能需要重新编译该库和所有使用它的应用程序......这首先破坏了使用共享库的目标。

【讨论】:

  • 什么意思? “静态反对”
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多