#include <atlbase.h> #define FLASHGETREG L"SOFTWARE//FlashGet Network//FlashGet 3" #define FLASHGETPATHREG L"Path" #define FLASHGETFORWORDPATH L"dat" #define FLASHGETCFGFILENAME L"Appsetting.cfg" #define FLASHGETCFGAPPNAME L"FlashGet3 Setting Value" #define FLASHGETCFGISANTIVIRUS L"IsAntiVirus" #define FLASHGETCFGANTIVIRUS L"AntiVirus " #define FLASHGETCFGANTIVIRUSPARAM L"AntiVirusParam" //从注册表中获取cfg文件的路径 BOOL GetFlashGetCfgFilePath(LPTSTR lpfilepath, DWORD& dwSize) { CRegKey RegFlashGet; WCHAR wchFlashGetCfgPath[256] = {0}; if( ERROR_SUCCESS == RegFlashGet.Open( HKEY_LOCAL_MACHINE, FLASHGETREG, KEY_ALL_ACCESS) ) { ULONG ulPathlength = ulPathlength=sizeof(wchFlashGetCfgPath)/sizeof(WCHAR); if( ERROR_SUCCESS == RegFlashGet.QueryStringValue( FLASHGETPATHREG, wchFlashGetCfgPath, &ulPathlength) ) { if( NULL != PathCombine( wchFlashGetCfgPath, wchFlashGetCfgPath, FLASHGETFORWORDPATH) ) { if( NULL != PathCombine( wchFlashGetCfgPath, wchFlashGetCfgPath, FLASHGETCFGFILENAME) ) { if( TRUE == PathFileExists(wchFlashGetCfgPath)) { if( dwSize < sizeof(wchFlashGetCfgPath)/sizeof(WCHAR)) { wmemcpy( lpfilepath,wchFlashGetCfgPath, dwSize); dwSize = sizeof(wchFlashGetCfgPath)/sizeof(WCHAR); return FALSE; } else { dwSize = sizeof(wchFlashGetCfgPath)/sizeof(WCHAR); wmemcpy( lpfilepath,wchFlashGetCfgPath, dwSize); return TRUE; } } } } } } return FALSE; } //获取cfg文件中IsAntiVirus数据 BOOL GetFlashGetCfgIsAntiVirusInfor( LPCTSTR lpfilepath, LPTSTR lpIsAntiVirus, DWORD& dwSize ) { if( FALSE == PathFileExists(lpfilepath) ) { return FALSE; } if( dwSize == 0 ) { return FALSE; } WCHAR *wchFlashGetIsAntiVirus = new WCHAR[dwSize]; wmemset( wchFlashGetIsAntiVirus, WCHAR("0") , dwSize); dwSize = GetPrivateProfileString( FLASHGETCFGAPPNAME, FLASHGETCFGISANTIVIRUS, NULL, wchFlashGetIsAntiVirus, dwSize, lpfilepath); wmemcpy( lpIsAntiVirus, wchFlashGetIsAntiVirus, dwSize); delete [] wchFlashGetIsAntiVirus; wchFlashGetIsAntiVirus = NULL; return TRUE; } //设置cfg文件中IsAntiVirus数据 BOOL SetFlashGetCfgIsAntiVirusInfor( LPCTSTR lpfilepath, LPTSTR lpIsAntiVirus ) { if( FALSE == PathFileExists(lpfilepath) ) { return FALSE; } return WritePrivateProfileString( FLASHGETCFGAPPNAME, FLASHGETCFGISANTIVIRUS, lpIsAntiVirus, lpfilepath); } //获取cfg文件中AntiVirus数据 BOOL GetFlashGetCfgAntiVirusInfor( LPCTSTR lpfilepath, LPTSTR lpAntiVirus, DWORD& dwSize ) { if( FALSE == PathFileExists(lpfilepath) ) { return FALSE; } if( dwSize == 0 ) { return FALSE; } WCHAR *wchFlashGetAntiVirus = new WCHAR[dwSize]; wmemset( wchFlashGetAntiVirus, WCHAR("0") , dwSize); dwSize = GetPrivateProfileString( FLASHGETCFGAPPNAME, FLASHGETCFGANTIVIRUS, NULL, wchFlashGetAntiVirus, dwSize, lpfilepath); wmemcpy( lpAntiVirus, wchFlashGetAntiVirus, dwSize); delete []wchFlashGetAntiVirus; wchFlashGetAntiVirus = NULL; return TRUE; } //设置cfg文件中AntiVirus数据 BOOL SetFlashGetCfgAntiVirusInfor( LPCTSTR lpfilepath, LPTSTR lpAntiVirus ) { if( FALSE == PathFileExists(lpfilepath) ) { return FALSE; } return WritePrivateProfileString( FLASHGETCFGAPPNAME, FLASHGETCFGANTIVIRUS, lpAntiVirus, lpfilepath); } //获取cfg文件中AntiVirusParam数据 BOOL GetFlashGetCfgAntiVirusParamInfor( LPCTSTR lpfilepath, LPTSTR lpAntiVirusParam, DWORD& dwSize ) { if( FALSE == PathFileExists(lpfilepath) ) { return FALSE; } if( dwSize == 0 ) { return FALSE; } WCHAR *wchFlashGetAntiVirusParam = new WCHAR[dwSize]; wmemset( wchFlashGetAntiVirusParam, WCHAR("0") , dwSize); dwSize = GetPrivateProfileString( FLASHGETCFGAPPNAME, FLASHGETCFGANTIVIRUSPARAM, NULL, wchFlashGetAntiVirusParam, dwSize, lpfilepath); wmemcpy( lpAntiVirusParam, wchFlashGetAntiVirusParam, dwSize); delete [] wchFlashGetAntiVirusParam; wchFlashGetAntiVirusParam = NULL; return TRUE; } //设置cfg文件中AntiVirusParam数据 BOOL SetFlashGetCfgAntiVirusParamInfor( LPCTSTR lpfilepath, LPTSTR lpAntiVirusParam ) { if( FALSE == PathFileExists(lpfilepath) ) { return FALSE; } return WritePrivateProfileString( FLASHGETCFGAPPNAME, FLASHGETCFGANTIVIRUSPARAM, lpAntiVirusParam, lpfilepath); } int _tmain(int argc, _TCHAR* argv[]) { WCHAR wchFlashGetCfgPath[256] = {0}; DWORD dwsize = sizeof(wchFlashGetCfgPath)/sizeof(WCHAR) ; GetFlashGetCfgFilePath(wchFlashGetCfgPath, dwsize); WCHAR wchFlashGetIsAntiVirus[4] = {0}; dwsize = sizeof(wchFlashGetIsAntiVirus)/sizeof(WCHAR); GetFlashGetCfgIsAntiVirusInfor( wchFlashGetCfgPath, wchFlashGetIsAntiVirus, dwsize ); WCHAR wchFlashGetAntiVirus[256] = {0}; dwsize = sizeof(wchFlashGetAntiVirus)/sizeof(WCHAR); GetFlashGetCfgAntiVirusInfor( wchFlashGetCfgPath, wchFlashGetAntiVirus, dwsize); WCHAR wchFlashGetAntiVirusParam[1024] = {0}; dwsize = sizeof(wchFlashGetAntiVirus)/sizeof(WCHAR); GetFlashGetCfgAntiVirusParamInfor( wchFlashGetCfgPath, wchFlashGetAntiVirusParam, dwsize ); SetFlashGetCfgIsAntiVirusInfor(wchFlashGetCfgPath, L"N"); SetFlashGetCfgAntiVirusInfor(wchFlashGetCfgPath, L"C://good.exe"); SetFlashGetCfgAntiVirusParamInfor(wchFlashGetCfgPath, L"/good"); return 0; }