分类: C/C++
2008-04-03 13:34:22
/************************************************************************* ** 文件名: SetUp.cpp ** 主要类: SetUp.cpp ** ** Copyright (c) ** 创建人: liu_sir ** 日 期: 2004-07-29 ** 修改人: ** 日 期: ** 描 述: 安装PDA应用程序 Pocket PC (注意:根目录下必须有setup.ini文件) ** ×× 主要步骤: (1)确认条件 ** (2)取自身的路径,并取ini路径 ** (3)取CEAppMgr.exe的全路径 ** (4)开始安装 ** (5)退出 ** ** 版 本: 1.0.0 ** 备 注: 各个组件命名以及代码编写符合C++编码规范 ** * ***********************************************************************/ #include#include #include #include #include #include #include int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { //1.确认条件 if(MessageBox(NULL,
(LPCTSTR)_T("安装前请确认:\r\n
1.已经安装了ActiveSync. \r\n
2.PDA连接到PC上. \r\n上述条件满足吗?"),
(LPCTSTR)_T("询问条件"),
MB_YESNO|MB_ICONQUESTION)!=IDYES) { return 0;//不满足条件,退出 } //2.取自身的路径 TCHAR szPath[MAX_PATH]; GetModuleFileName(NULL, szPath, MAX_PATH-1); TCHAR tmpPath[MAX_PATH]; //转换成ini文件名 #if _UNICODE int iLen = wcslen(szPath);// #else int iLen = strlen(szPath); #endif #if _UNICODE wcscpy(&szPath[iLen-3], _T("ini")); wsprintf(tmpPath,_T("\"%s\""),szPath);//注意加"号 wcscpy(szPath,tmpPath); #else strcpy(&szPath[iLen-3], _T("ini")); sprintf(tmpPath,_T("\"%s\""),szPath); strcpy(szPath,tmpPath); #endif //3.取CEAppMgr.exe的全路径 HKEY hResult; TCHAR szCEAppMgr[]=_T
("software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\CEAppMgr.exe"); LONG iRet=RegOpenKeyEx
(HKEY_LOCAL_MACHINE, szCEAppMgr, NULL, KEY_READ, &hResult); BYTE szCEAppMgrExe[MAX_PATH*2+1]; if(iRet==ERROR_SUCCESS) { DWORD cbName, dwType; cbName = MAX_PATH; dwType = REG_SZ; iRet = RegQueryValueEx(hResult, NULL, NULL,
dwType, szCEAppMgrExe, &cbName); RegCloseKey(hResult); } if (iRet!=ERROR_SUCCESS) { MessageBox(NULL, _T("请先安装Microsoft ActiveSync软件!"),
_T("错误"), MB_ICONERROR); return 1; } TCHAR szExe[MAX_PATH*2+2]; #if _UNICODE wcscpy(szExe,(TCHAR*)szCEAppMgrExe); #else strcpy(szExe, (char *)szCEAppMgrExe); #endif //4.开始安装 SHELLEXECUTEINFO ExecInfo ; memset((TCHAR *)&ExecInfo, 0, sizeof(ExecInfo)); ExecInfo.cbSize = sizeof(ExecInfo); ExecInfo.hwnd = NULL; ExecInfo.lpDirectory = NULL; ExecInfo.hInstApp = hInstance; ExecInfo.lpVerb = _T("open"); ExecInfo.lpFile = szExe; ExecInfo.lpParameters = szPath; ExecInfo.nShow = SW_SHOW; ::ShellExecuteEx(&ExecInfo); //5.退出程序 return 0; }
3.Setup.ini文件内容:假设你的程序名称为PocketApp_PPC,那么应该编写如下:
[CEAppManager] Version = 1.0 Component = App [App] Description = Sample Pocket PC application. CabFiles = PocketApp_PPC.X86.CAB,
PocketApp_PPC.ARM.CAB,
PocketApp_PPC.ARMV4.CAB,
PocketApp_PPC.MIPS.CAB,
PocketApp_PPC.SH3.CAB,
PocketApp_PPC.WCE420X86.CAB