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:

  1. Perhaps it is possible to convert from static to dynamic library?
  2. How to fix the error?

    0