10/28/2012

在SDCard上自動執行指定之應用程式

最近寫了一個在SD card上自動執行某應用程式的小程式
這程式可以以不透過定義autorun.ini 或是 regidit的方式,在硬體插入SD card後自動進入指定的application
稍微看了一下網上的資料大多都是英文的,中文也以簡體居多,所以決定順手記錄下來

Visual Studio 2005 C++ for WinCE
Windows smart device program, Windows application program
透過Wizard產生project會產出很多程式碼,這邊只寫出這項功能必要加上的部分,可以自己去決定該加在cpp的哪個位置

//定義application在SD card路徑
#define APP_PATH (L"\Storage Card\\APP.exe")
//可以定義若application開啟不成功的需要文件
#define APP_STARTUP_PATH (L"\Storage Card\\APP.exe")

int WINAPI WinMain( HINSTANCE hinstance,
                    HINSTANCE hPrevlnstance,
                    LPTSTR lpCmdLine,
                    int nCmdShow)
{

   SHELLEXECUTEINFO sheExeInfo = {0};
   //exe APP.exe
   sheExeInfo.cbSize = sizeof(SHELLEXECUTEINFO);
   sheExeInfo.fMask = SEE_MASK_NCLOSEPROCESS;
   sheExeInfo.hwnd = NULL;
   sheExeInfo.lpVerb = NULL;
   sheExeInfo.lpFile = APP_PATH;
   sheExeInfo.lpParameters = L"";
   sheExeInfo.lpDirectory = NULL;
   sheExeInfo.nShow = SW_SHOW;
   sheExeInfo.hlnstApp = NULL;
   ShellExecuteEx(&sheExeInfo);

}




沒有留言:

張貼留言