Good day!

There is a project in C ++, there is a static library that is connected to it. And there is a dll. The point is this: how to make an instance of a class defined in a stat libe created in a project, then a function from a dll is called, which accepts a reference to this instance as input, and processes it. Do I need to enable stat lib in dll? Here with the export / import of this class will not work. It should be used only dynamic connection dll, I work in MSVS, there LoadLibrary and GetProcessAddress. It is applied in general as follows: the project works, when an update to the dll comes up, the project does not restart, but only pauses, there functions are reloaded from the dll. And another question: with such an organization, I should not specify the .lib file from the dll?

  • You should have a factory that returns you an instance of the class: g_someoneFabric->getFooInstance() - isnullxbh

1 answer 1

 #include <Windows.h> #include <tchar.h> int main() { HINSTANCE userHinstance = LoadLibrary(_TEXT("user32.dll")); //можно путь целиком, если не известно /*получаем указатель на функцию, которую хотим вызвать*/ FARPROC(WINAPI *LPMessageBox)(HWND, LPCWSTR, LPCWSTR, UINT); LPMessageBox = GetProcAddress(userHinstance, "MessageBoxW"); /*вызываем*/ LPMessageBox(NULL,_TEXT("Hello"), _TEXT("Как сам?"), MB_OK); /*выгружаем библиотеку*/ FreeLibrary(userHinstance); return 0; } 

The rest