📄 libmanager.cpp
字号:
// LibManager.cpp: implementation of the CLibManager class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Compress.h"
#include "LibManager.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CLibManager::CLibManager(LPCTSTR szPath)
{
HANDLE hFindFile;
WIN32_FIND_DATA FindFileData;
CString FileName,FullPath=szPath;
if (FullPath[lstrlen(FullPath)-1]!='\\') FullPath+='\\';
FileName=FullPath+"*.cdl";
if ((hFindFile=FindFirstFile((LPCTSTR)FileName,&FindFileData))
==INVALID_HANDLE_VALUE)
{ //找不到库
m_lpAllInfo=NULL;
m_nNoCDL=0;
}
else
{
int n=1;
HMODULE hModule;
LPFNGETDLLINFO GetDllInfo;
//有多少库
while (FindNextFile(hFindFile,&FindFileData)) n++;
FindClose(hFindFile);
m_lpAllInfo=new EVERYLIBINFO[n];
m_nNoCDL=0;
hFindFile=FindFirstFile((LPCTSTR)FileName,&FindFileData);
do{
if ((hModule=(HMODULE)LoadLibrary
(LPCTSTR(FullPath+FindFileData.cFileName)))==0)
continue;
GetDllInfo=(LPFNGETDLLINFO)GetProcAddress(hModule,"GetDllInfo");
if (GetDllInfo)
{
GetDllInfo(&m_lpAllInfo[m_nNoCDL].CDLInfo);
if ((m_lpAllInfo[m_nNoCDL].CDLInfo.dwVersion&0xFF000000)
<=CDL_CUR_VERSION_NUMBER) //可以使用低版本库
{
m_lpAllInfo[m_nNoCDL].hModule=0;
m_lpAllInfo[m_nNoCDL].szFileName=FullPath+FindFileData.cFileName;
m_nNoCDL++;
}
}
FreeLibrary(hModule);
}while(FindNextFile(hFindFile,&FindFileData));
FindClose(hFindFile);
}
}
CLibManager::~CLibManager()
{
if (m_lpAllInfo)
delete m_lpAllInfo;
}
int CLibManager::LoadLib(int nIndex)
{
if (nIndex<0 || nIndex>=m_nNoCDL) return -1;
if (m_lpAllInfo[nIndex].hModule) //已经装入
return nIndex;
m_lpAllInfo[nIndex].hModule
=LoadLibrary((LPCTSTR)m_lpAllInfo[nIndex].szFileName);
return nIndex;
}
int CLibManager::LoadLib(LPCTSTR szExtName)
{
if (!szExtName || !szExtName[0]) return -1;
CString filter,ext(szExtName);
ext.MakeLower();
for (int i=0;i<m_nNoCDL;i++)
{
filter=m_lpAllInfo[i].CDLInfo.szFileFilter;
filter.MakeLower();
if (filter.Find(ext)>=0) break;
}
return LoadLib(i);
}
void CLibManager::FreeLib(int nIndex)
{
if (nIndex<0 && nIndex>=m_nNoCDL) return;
if (m_lpAllInfo[nIndex].hModule) FreeLibrary(m_lpAllInfo[nIndex].hModule);
m_lpAllInfo[nIndex].hModule=0;
}
void CLibManager::FreeAll()
{
for (int i=0;i<m_nNoCDL;i++) FreeLib(i);
}
void CLibManager::GetFuncInfo(int nIndex,LPFUNCTIONINFO lpfi)
{
lpfi->lpfnCreate=NULL;
lpfi->lpfnRelease=NULL;
lpfi->lpfnGetNoEntries=NULL;
lpfi->lpfnGetFileInfo=NULL;
lpfi->lpfnAddNewFile=NULL;
lpfi->lpfnExtractFile=NULL;
lpfi->lpfnDeleteFiles=NULL;
lpfi->lpfnTestFile=NULL;
lpfi->lpfnSetPassword=NULL;
lpfi->lpfnGetComment=NULL;
lpfi->lpfnSetComment=NULL;
if (!IsLoaded(nIndex)) return;
LPFNGETFUNCTIONINFO GetFunctionInfo=(LPFNGETFUNCTIONINFO)
GetProcAddress(m_lpAllInfo[nIndex].hModule,"GetFunctionInfo");
GetFunctionInfo(lpfi);
}
LPFNCDLABOUTBOX CLibManager::GetFnGetAboutBox(int nIndex)
{
if (!IsLoaded(nIndex)) return NULL;
return (LPFNCDLABOUTBOX)
GetProcAddress(m_lpAllInfo[nIndex].hModule,"CDLAboutBox");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -