簡體   English   中英

從dll使用std :: vector從其他dll進行C ++調用

[英]C++ call from dll other dll with std::vector

我有一個使用外部方法的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;
    };

一些可能性:

  1. DLL是針對不同版本的C ++運行時庫編譯的

  2. DLL已與c +運行時庫靜態鏈接

  3. 您的應用程序已與c ++運行時庫靜態鏈接

  4. DLL中有一個錯誤。

注意。 在DLL的接口中提供c ++標准庫類型通常是一個非常嚴重的錯誤。

當標准庫更改時(例如,升級了編譯器),您可能需要重新編譯該庫以及使用該庫的所有應用程序……這首先使使用共享庫的目標告吹。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM