#include <WinDLLTool.h>
Public Member Functions | |
DLLModuleTBL (LPCTSTR dirn) | |
DLLModuleTBL () | |
virtual | ~DLLModuleTBL () |
void | init (LPCTSTR dirn=NULL) |
void | free () |
BOOL | load_module (LPCTSTR dirn=NULL) |
void | make_module_tbl (LPCTSTR fname, int n) |
Public Attributes | |
int | vnum |
DLLModule ** | dllmod |
bool | loaded |
Protected Member Functions | |
tList * | get_dir_module (LPCTSTR dirn) |
virtual DLLModule * | new_module (LPCTSTR fname, int n) |
virtual void | set_module_function () |
Protected Attributes | |
int | tnum |
tList * | lp |
CString | dirname |
Definition at line 91 of file WinDLLTool.h.
DLLModuleTBL | ( | LPCTSTR | dirn | ) | [inline] |
Definition at line 105 of file WinDLLTool.h.
References DLLModuleTBL::init().
00105 { init(dirn);}
DLLModuleTBL | ( | ) | [inline] |
Definition at line 106 of file WinDLLTool.h.
References DLLModuleTBL::init().
00106 { init(NULL);}
virtual ~DLLModuleTBL | ( | ) | [inline, virtual] |
Definition at line 107 of file WinDLLTool.h.
References DLLModuleTBL::free().
00107 { free();}
void free | ( | void | ) |
機能:クラス中のデータを解放する.
Definition at line 186 of file WinDLLTool.cpp.
References DLLModuleTBL::dllmod, DLLModule::free(), DLLModuleTBL::loaded, DLLModuleTBL::lp, DLLModuleTBL::tnum, and DLLModuleTBL::vnum.
Referenced by DLLModuleTBL::~DLLModuleTBL().
00187 { 00188 00189 if (dllmod!=NULL) { 00190 for (int i=0; i<vnum; i++) { 00191 if (dllmod[i]!=NULL) { 00192 dllmod[i]->free(); 00193 delete(dllmod[i]); 00194 dllmod[i] = NULL; 00195 } 00196 } 00197 } 00198 00199 tList* lt = lp; 00200 while (lt!=NULL) { 00201 if (lt->ldat.ptr!=NULL) { 00202 FreeLibrary((HMODULE)(lt->ldat.ptr)); // 関数へのハンドル 00203 lt->ldat.ptr = NULL; 00204 lt->ldat.sz = 0; 00205 } 00206 lt = lt->next; 00207 } 00208 del_all_tList(&lp); 00209 00210 tnum = vnum = 0; 00211 if (dllmod!=NULL) ::free(dllmod); 00212 dllmod = NULL; 00213 loaded = false; 00214 }
tList * get_dir_module | ( | LPCTSTR | dirn | ) | [protected] |
機能:ディレクトリ dirn にあるファイルを検索して,DLLファイルなら読み込みを行いリストに格納する. DLLのチェックは行わない.
引数:dirn -- 読み込むDLLがあるディレクトリ.通常はアプリケーションからの相対パス. NULL の場合は,読み込みを行わない.
戻り値:情報を格納したリストへのポインタ.エラーの場合は NULL. lp->ldat.key.buf : DLL名 lp->ldat.val.buf : DLLファイル名(ディレクトリを含む) lp->ldat.ptr : モジュールハンドラ
Definition at line 261 of file WinDLLTool.cpp.
References jbxwl::get_dir_files_t(), and jbxwl::mbs2ts().
Referenced by DLLModuleTBL::load_module().
00262 { 00263 tList* lm; 00264 tList* lt; 00265 00266 if (dirn==NULL) return NULL; 00267 lm = lt = get_dir_files_t(dirn); 00268 if (lm==NULL) return NULL; 00269 00270 while (lt!=NULL) { 00271 HMODULE hmod = LoadLibrary((LPCTSTR)mbs2ts((char*)(lt->ldat.val.buf))); 00272 lt->ldat.ptr = (void*)hmod; 00273 char* fn = get_file_name((char*)(lt->ldat.val.buf)); 00274 lt->ldat.key = make_Buffer_bystr(fn); 00275 lt = lt->next; 00276 } 00277 00278 // ハンドラが NULLの場合は削除 00279 lt = lm; 00280 while (lt!=NULL) { 00281 if (lt->ldat.ptr==NULL) { 00282 tList* ln = lt; 00283 if (lm==lt) lm = lt->next; 00284 lt = lt->next; 00285 del_tList_node(&ln); 00286 } 00287 else lt = lt->next; 00288 } 00289 00290 return lm; 00291 }
void init | ( | LPCTSTR | dirn = NULL |
) |
機能:クラスの初期化.ディレクトリdirnにある DLLを自動的に読み込む. dirn に NULLを指定した場合は DLLを読み込まないので,load_module() を改めて実行しなければならない.
引数:dirn -- 読み込むDLLがあるディレクトリ.通常はアプリケーションからの相対パス.
Definition at line 170 of file WinDLLTool.cpp.
References DLLModuleTBL::dirname, DLLModuleTBL::dllmod, DLLModuleTBL::load_module(), DLLModuleTBL::loaded, DLLModuleTBL::lp, DLLModuleTBL::tnum, and DLLModuleTBL::vnum.
Referenced by DLLModuleTBL::DLLModuleTBL().
00171 { 00172 tnum = vnum = 0; 00173 loaded = false; 00174 lp = NULL; 00175 dllmod = NULL; 00176 dirname = _T(""); 00177 00178 if (dirn!=NULL) load_module(dirn); 00179 }
BOOL load_module | ( | LPCTSTR | dirn = NULL |
) |
機能:ディレクトリdirnにある DLLを読み込む.DLLのチェック(使用できるものかどうか)は行わない. dirn に NULLを指定した場合は カレントディレクトリのDLLを読み込む.
引数:dirn -- 読み込むDLLがあるディレクトリ.通常はアプリケーションからの相対パス. NULL の場合は,カレント "."を指定したことになる.
戻り値:TRUE -- 読み込み完了.tnum に読み込んだDLLの数が入る. FLASE -- DLLは存在しない.または読み込み失敗.
Definition at line 228 of file WinDLLTool.cpp.
References DLLModuleTBL::dirname, DLLModuleTBL::get_dir_module(), DLLModuleTBL::loaded, DLLModuleTBL::lp, and DLLModuleTBL::tnum.
Referenced by DLLModuleTBL::init().
00229 { 00230 if (dirn!=NULL) dirname = dirn; 00231 else dirname = _T("."); 00232 00233 lp = get_dir_module((LPCTSTR)dirname); 00234 if (lp==NULL) return FALSE; 00235 00236 tnum = 0; 00237 tList* lt = lp; 00238 while (lt!=NULL) { 00239 tnum++; 00240 lt = lt->next; 00241 } 00242 loaded = true; 00243 00244 return TRUE; 00245 }
void make_module_tbl | ( | LPCTSTR | fname, | |
int | m | |||
) |
機能:モジュールの一覧を格納したリストlp から,モジュールテーブル(配列)を作成する. 関数名fname で示した関数 fname(0) からタイトル名が獲得できない場合は,テーブル から削除する.
引数:fname -- モジュールの情報を返す関数名.引数 (int)0 でタイトル(char*)を返えさなければならない. m -- 読み込むDLL中の使用できる関数の数
Definition at line 303 of file WinDLLTool.cpp.
References DLLModuleTBL::dllmod, DLLModule::get_module_info(), DLLModuleTBL::lp, DLLModuleTBL::new_module(), DLLModuleTBL::set_module_function(), DLLModuleTBL::tnum, and DLLModuleTBL::vnum.
00304 { 00305 tList* lm = lp; 00306 00307 vnum = 0; 00308 if (fname==NULL) return; 00309 00310 dllmod = (DLLModule**)malloc(sizeof(DLLModule*)*tnum); 00311 if (dllmod==NULL) return; 00312 00313 int n = 0; 00314 if (m<=0) m = 1; 00315 while (lm!=NULL) { 00316 dllmod[n] = this->new_module(fname, m); 00317 int ret = dllmod[n]->get_module_info(lm); 00318 if (ret) { 00319 n++; 00320 if (n>=tnum) break; 00321 } 00322 else { 00323 delete(dllmod[n]); 00324 dllmod[n] = NULL; 00325 } 00326 lm = lm->next; 00327 } 00328 vnum = n; 00329 00330 this->set_module_function(); 00331 return; 00332 }
virtual DLLModule* new_module | ( | LPCTSTR | fname, | |
int | n | |||
) | [inline, protected, virtual] |
Definition at line 118 of file WinDLLTool.h.
Referenced by DLLModuleTBL::make_module_tbl().
virtual void set_module_function | ( | ) | [inline, protected, virtual] |
Definition at line 119 of file WinDLLTool.h.
Referenced by DLLModuleTBL::make_module_tbl().
CString dirname [protected] |
Definition at line 102 of file WinDLLTool.h.
Referenced by DLLModuleTBL::init(), and DLLModuleTBL::load_module().
Definition at line 95 of file WinDLLTool.h.
Referenced by DLLModuleTBL::free(), DLLModuleTBL::init(), and DLLModuleTBL::make_module_tbl().
bool loaded |
Definition at line 97 of file WinDLLTool.h.
Referenced by DLLModuleTBL::free(), DLLModuleTBL::init(), and DLLModuleTBL::load_module().
tList* lp [protected] |
Definition at line 101 of file WinDLLTool.h.
Referenced by DLLModuleTBL::free(), DLLModuleTBL::init(), DLLModuleTBL::load_module(), and DLLModuleTBL::make_module_tbl().
int tnum [protected] |
Definition at line 100 of file WinDLLTool.h.
Referenced by DLLModuleTBL::free(), DLLModuleTBL::init(), DLLModuleTBL::load_module(), and DLLModuleTBL::make_module_tbl().
int vnum |
Definition at line 94 of file WinDLLTool.h.
Referenced by DLLModuleTBL::free(), DLLModuleTBL::init(), and DLLModuleTBL::make_module_tbl().