There is a library with static linking (no source) and header files for C ++. I need to make a dynamic link library out of it.
Made a dynamic library with export functions.
#pragma comment(lib, "rtl2.lib") D3RTL_API msp_ERROR sp_Startup(void); D3RTL_API msp_ERROR sp_Startup() { return msp_Startup(); // ΠΠΎΡ ΡΡΡ Π²ΠΎΠ·Π½ΠΈΠΊΠ°Π΅Ρ ΠΎΡΠΈΠ±ΠΊΠ° } Created a console application with a dynamic library connection.
typedef msp_ERROR (*TESTFUNCTION)(void); DWORD err; HINSTANCE hDll = LoadLibrary(L"F:\\Projects\\msp\\Debug\\msp.dll"); if (hDll != NULL) { printf("Library was loaded\n"); } else { err = GetLastError(); printf("Couldn't load dll. Error code %d\n", err); return -1; } // ΠΏΠΎΠ»ΡΡΠ΅Π½ΠΈΠ΅ ΡΠΊΠ°Π·Π°ΡΠ΅Π»Ρ Π½Π° ΡΡΠ½ΠΊΡΠΈΡ Π±ΠΈΠ±Π»ΠΈΠΎΡΠ΅ΠΊΠΈ TESTFUNCTION lpTestFunction = (TESTFUNCTION)GetProcAddress(hDll, "?sp_Startup@@YAHXZ"); if (lpTestFunction != NULL) { msp_ERROR e = lpTestFunction(); cout << "error = " << e << endl; } // ΠΎΡΠ²ΠΎΠ±ΠΎΠΆΠ΄Π΅Π½ΠΈΠ΅ Π΄Π΅ΡΠΊΡΠΈΠΏΡΠΎΡΠ° FreeLibrary(hDll); return 0; At home, the project under Win 7 and MS VC 2012 works, and at work Win XP MS VC 2010 does not work. Produces the following error:
Unhandled exception in "0x1001c462 (msp.dll)" in "test.exe": 0xC0000005: Access violation when reading "0x00000000".
In this case, if you connect the static library msp.lib (without dynamic) in the console application, then everything works.
Therefore, two questions:
- Perhaps it is possible to convert from static to dynamic library?
- How to fix the error?