Dll in debug mode, calling the program in release mode (and vice versa)

I am writing a small C ++ program that tests a C dll containing some functions. These DLLs exist in the debug version and release version, and I would like to download them both with the same program, and compare them with the previous version.

The problem is that when I compile my program using the release configuration, it can only use DLLs that are also released, and when I compile the program using debug configuration, it can only use DLLs that are also debugged.

I load dlls / functions using the LoadLibrary and GetProcAddress functions.

There are two types of functions: void type1(int&) and void type2(vector<string>*) . Type 1 works great regardless of configuration. But type 2 only works if the configuration matches.

the code:

 typedef void(*GetNames)(vector <string>* ); GetNames get_var_names = (* GetNames) GetProcAddress (dll, "get_var_names" ); vector <string> var_names; get_var_names (& var_names); 
>

The last line is the error in which the program crashes with an error like "0xC0000005: location of the violation of access 0xbaadf008". if the configuration of the calling program and the dll do not match. An error is a read violation when the program is freed and the dll is being debugged, but a write violation when the program is debugged and the dll is being freed.

The function is supposed to just call push_back ("x") several times with different lines.

It seems not entirely impossible to use the debugging DLL in the release configuration program, or all type 1 functions will not work either, so it seems to have something to do with the vector or string class.

Does anyone know how to solve this or use two executables with different configurations, my only choice?

+4
source share
1 answer

Many (if not all) STL classes use a different layout for DEBUG assemblies. Therefore, you cannot use such a class compiled by DEBUG from dll (for example, std :: string and std :: vector) in the RELEASE version for the program and vice versa.

Avoid using STL types / classes in your interface of your DLL and use built-in types instead. In this case, you will never have these problems.

By the way: I'm talking about MSVC ++, of course (other compilers that I don't know about).

+4
source

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


All Articles