Win32DynamicLibraryManager.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #include <cppunit/Portability.h>
  2. #if defined(CPPUNIT_HAVE_WIN32_DLL_LOADER)
  3. #include <cppunit/plugin/DynamicLibraryManager.h>
  4. #define WIN32_LEAN_AND_MEAN
  5. #define NOGDI
  6. #define NOUSER
  7. #define NOKERNEL
  8. #define NOSOUND
  9. #define NOMINMAX
  10. #define BLENDFUNCTION void // for mingw & gcc
  11. #include <windows.h>
  12. CPPUNIT_NS_BEGIN
  13. DynamicLibraryManager::LibraryHandle
  14. DynamicLibraryManager::doLoadLibrary( const std::string &libraryName )
  15. {
  16. return ::LoadLibraryA( libraryName.c_str() );
  17. }
  18. void
  19. DynamicLibraryManager::doReleaseLibrary()
  20. {
  21. ::FreeLibrary( (HINSTANCE)m_libraryHandle );
  22. }
  23. DynamicLibraryManager::Symbol
  24. DynamicLibraryManager::doFindSymbol( const std::string &symbol )
  25. {
  26. return (DynamicLibraryManager::Symbol)::GetProcAddress(
  27. (HINSTANCE)m_libraryHandle,
  28. symbol.c_str() );
  29. }
  30. std::string
  31. DynamicLibraryManager::getLastErrorDetail() const
  32. {
  33. LPVOID lpMsgBuf;
  34. ::FormatMessageA(
  35. FORMAT_MESSAGE_ALLOCATE_BUFFER |
  36. FORMAT_MESSAGE_FROM_SYSTEM |
  37. FORMAT_MESSAGE_IGNORE_INSERTS,
  38. NULL,
  39. GetLastError(),
  40. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
  41. (LPSTR) &lpMsgBuf,
  42. 0,
  43. NULL
  44. );
  45. std::string message = (LPCSTR)lpMsgBuf;
  46. // Display the string.
  47. // ::MessageBoxA( NULL, (LPCSTR)lpMsgBuf, "Error", MB_OK | MB_ICONINFORMATION );
  48. // Free the buffer.
  49. ::LocalFree( lpMsgBuf );
  50. return message;
  51. }
  52. CPPUNIT_NS_END
  53. #endif // defined(CPPUNIT_HAVE_WIN32_DLL_LOADER)