Dynamic Linking in Visual Studio

I need to dynamically contact OpenSSL libeay32.dll. I am writing my own C ++ console application using Visual C ++ Express 2008.

I include the evp.h header from the OpenSSL distribution. The building and ...:

error LNK2001: unresolved external symbol _EVP_aes_256_cbc
error LNK2001: unresolved external symbol _EVP_DecryptInit
error LNK2001: unresolved external symbol _EVP_CIPHER_CTX_init

How to call libeay32.dll methods? I do not know where to indicate its file name

+3
source share
5 answers

In the project properties, configuration properties, linker, input - add the library name under "additional dependencies".

[ , STATICALLY . , LoadLibrary() DLL, , , GetProcAddress().

.

http://msdn.microsoft.com/en-us/library/ms886736.aspx

http://msdn.microsoft.com/en-us/library/ms885634.aspx

+2

, .lib, . , .

+3

LoadLibrary Win32 API, :

+3

, 2 .lib. , , -, . , DLL , .

+3

dll, explict.

: evp.h DLL OpenSSL

, .h DLL .

  • :
    • LoadLibrary ( "libeay32.dll" );/* : */
    • , , .

,

Let your libeay32.dll have an exported function: int add(int x, int y);

Then, to call it in your project, declare a pointer to a function, and then call the add method as follows:

    typedef int (*AddfnPtr)(int num1, int num2);
    int num1 = 2, num2 = 3 ;

    HMODULE handle = NULL;
    handle = LoadLibrary("libeay32.dll");

    if (handle != NULL)
    {
        AddfnPtr addfnptr = (AddfnPtr)GetProcAddr(handle, NULL); 
        if (addfnptr != NULL)
        {
            int res = addfnptr(num1,num2);
            cout << "res = "<<res;
        } 
   }
0
source

Source: https://habr.com/ru/post/1740940/


All Articles