michael@0: // Windows/DLL.cpp michael@0: michael@0: #include "StdAfx.h" michael@0: michael@0: #include "DLL.h" michael@0: #include "Defs.h" michael@0: #ifndef _UNICODE michael@0: #include "../Common/StringConvert.h" michael@0: #endif michael@0: michael@0: #ifndef _UNICODE michael@0: extern bool g_IsNT; michael@0: #endif michael@0: michael@0: namespace NWindows { michael@0: namespace NDLL { michael@0: michael@0: CLibrary::~CLibrary() michael@0: { michael@0: Free(); michael@0: } michael@0: michael@0: bool CLibrary::Free() michael@0: { michael@0: if (_module == 0) michael@0: return true; michael@0: // MessageBox(0, TEXT(""), TEXT("Free"), 0); michael@0: // Sleep(5000); michael@0: if (!::FreeLibrary(_module)) michael@0: return false; michael@0: _module = 0; michael@0: return true; michael@0: } michael@0: michael@0: bool CLibrary::LoadOperations(HMODULE newModule) michael@0: { michael@0: if (newModule == NULL) michael@0: return false; michael@0: if(!Free()) michael@0: return false; michael@0: _module = newModule; michael@0: return true; michael@0: } michael@0: michael@0: bool CLibrary::LoadEx(LPCTSTR fileName, DWORD flags) michael@0: { michael@0: // MessageBox(0, fileName, TEXT("LoadEx"), 0); michael@0: return LoadOperations(::LoadLibraryEx(fileName, NULL, flags)); michael@0: } michael@0: michael@0: bool CLibrary::Load(LPCTSTR fileName) michael@0: { michael@0: // MessageBox(0, fileName, TEXT("Load"), 0); michael@0: // Sleep(5000); michael@0: // OutputDebugString(fileName); michael@0: // OutputDebugString(TEXT("\n")); michael@0: return LoadOperations(::LoadLibrary(fileName)); michael@0: } michael@0: michael@0: #ifndef _UNICODE michael@0: static inline UINT GetCurrentCodePage() { return ::AreFileApisANSI() ? CP_ACP : CP_OEMCP; } michael@0: CSysString GetSysPath(LPCWSTR sysPath) michael@0: { return UnicodeStringToMultiByte(sysPath, GetCurrentCodePage()); } michael@0: michael@0: bool CLibrary::LoadEx(LPCWSTR fileName, DWORD flags) michael@0: { michael@0: if (g_IsNT) michael@0: return LoadOperations(::LoadLibraryExW(fileName, NULL, flags)); michael@0: return LoadEx(GetSysPath(fileName), flags); michael@0: } michael@0: bool CLibrary::Load(LPCWSTR fileName) michael@0: { michael@0: if (g_IsNT) michael@0: return LoadOperations(::LoadLibraryW(fileName)); michael@0: return Load(GetSysPath(fileName)); michael@0: } michael@0: #endif michael@0: michael@0: bool MyGetModuleFileName(HMODULE hModule, CSysString &result) michael@0: { michael@0: result.Empty(); michael@0: TCHAR fullPath[MAX_PATH + 2]; michael@0: DWORD size = ::GetModuleFileName(hModule, fullPath, MAX_PATH + 1); michael@0: if (size <= MAX_PATH && size != 0) michael@0: { michael@0: result = fullPath; michael@0: return true; michael@0: } michael@0: return false; michael@0: } michael@0: michael@0: #ifndef _UNICODE michael@0: bool MyGetModuleFileName(HMODULE hModule, UString &result) michael@0: { michael@0: result.Empty(); michael@0: if (g_IsNT) michael@0: { michael@0: wchar_t fullPath[MAX_PATH + 2]; michael@0: DWORD size = ::GetModuleFileNameW(hModule, fullPath, MAX_PATH + 1); michael@0: if (size <= MAX_PATH && size != 0) michael@0: { michael@0: result = fullPath; michael@0: return true; michael@0: } michael@0: return false; michael@0: } michael@0: CSysString resultSys; michael@0: if (!MyGetModuleFileName(hModule, resultSys)) michael@0: return false; michael@0: result = MultiByteToUnicodeString(resultSys, GetCurrentCodePage()); michael@0: return true; michael@0: } michael@0: #endif michael@0: michael@0: }}