1 HMODULE GetSelfModuleHandle() 2 { 3 MEMORY_BASIC_INFORMATION mbi; 4 return ((::VirtualQuery(GetSelfModuleHandle, &mbi, sizeof(mbi)) != 0) ? (HMODULE)mbi.AllocationBase : NULL); 5 } 6 7 CString GetCurrentPath(void) 8 { 9 TCHAR path[MAX_PATH] = {0}; 10 memset(path, 0, sizeof(path)); 11 GetModuleFileName(GetSelfModuleHandle(),path,sizeof(path)); 12 int l = _tcslen(path); 13 TCHAR ch = 0; 14 while ('\' != (ch = *(path + --l))); 15 *(path + l + 1) = 0; 16 return CString(path); 17 }
注意,GetSelfModuleHandle函数必须是全局的,或者类的静态成员方法。