资源释放 和创建进程
ReleaseRes(szVerFile,(WORD)IDR_VER1,"VER");
BOOL ReleaseRes(CHAR* strFileName,WORD wResID,CHAR* strFileType) { // 资源大小 DWORD dwWrite=0; // 创建文件 HANDLE hFile = CreateFile(strFileName, GENERIC_WRITE,FILE_SHARE_WRITE,NULL, CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL); if ( hFile == INVALID_HANDLE_VALUE ) { LOG(RSLOG_ACTION,"CreateFile Failed! File=%s",strFileName); return FALSE; } // 查找资源文件中、加载资源到内存、得到资源大小 HRSRC hrsc = FindResource(NULL, MAKEINTRESOURCE(wResID), strFileType); HGLOBAL hG = LoadResource(NULL, hrsc); DWORD dwSize = SizeofResource( NULL, hrsc); // 写入文件 WriteFile(hFile,hG,dwSize,&dwWrite,NULL); CloseHandle( hFile ); return TRUE; }
BOOL RunAPP(LPSTR szMakeFile ,LPSTR batparam );
BOOL RunAPP(LPSTR szMakeFile ,LPSTR batparam ){ STARTUPINFO stStartInfo; PROCESS_INFORMATION stProcessInfo; ZeroMemory(&stStartInfo, sizeof(STARTUPINFO)); stStartInfo.cb = sizeof(STARTUPINFO); GetStartupInfo(&stStartInfo); CHAR AppName[RSMAX_PATH]={0}; sprintf(AppName,"%s %s",szMakeFile,batparam); LOG(RSLOG_ACTION,"Run exe %s param %s",szMakeFile,batparam); DWORD dwReturn; if( CreateProcess(NULL,AppName, NULL, NULL, FALSE, 0, NULL, NULL, &stStartInfo, &stProcessInfo) ) { WaitForSingleObject(stProcessInfo.hProcess, INFINITE); GetExitCodeProcess(stProcessInfo.hProcess, &dwReturn); if (dwReturn!=0) { LOG(RSLOG_ACTION,"Process Exit ,ExitCode=%d",dwReturn); return FALSE; }else{ LOG(RSLOG_ACTION,"Process %s Success.",szMakeFile); } return TRUE; } return FALSE; }