Very Simple Autorun example code on Pocket 2003 ~ WM6

// SimpleAutorun.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include "SimpleAutorun.h"
#include <windows.h>
#include <commctrl.h>

#define MAX_LOADSTRING 100

// Global Variables:
HINSTANCE            g_hInst = NULL;            // current instance
#define INSTALL_ARGUMENT    _T("install")
#define UNINSTALL_ARGUMENT  _T("uninstall")
#define RunappName            _T("example.cab")
#define GetInstance()        (g_hInst)

static void Launch(const LPCTSTR pPath)
{
    // Specify an action for the application to perform,
    // flags and other parameters
    SHELLEXECUTEINFO info;
    //TCHAR    buff[256];
    ZeroMemory(&info, sizeof(info));
    info.cbSize = sizeof(info);
    info.fMask = SEE_MASK_FLAG_NO_UI;
    info.hwnd = NULL;
    info.lpVerb = _T("open");
    info.lpFile = pPath;
    info.lpParameters = _T("");
    info.lpDirectory = _T("");
    info.nShow = SW_SHOWNORMAL;
    // Call to perform an action
    ShellExecuteEx(&info);

}

static TCHAR * GetCardPath(const LPCTSTR pPath)
{
    TCHAR Buff1[MAX_PATH+1] = { _T(“) };
    static TCHAR Buff2[MAX_PATH+1] = { _T(“) };
    TCHAR    *ptcFind = NULL;

    _tcscpy(Buff1, pPath);
    _tcsupr(Buff1);

    ptcFind = _tcsstr(Buff1, _T("AUTORUN"));
    if (NULL != ptcFind)
    {
        *ptcFind = _T(“);
        _tcscpy(Buff2, Buff1);
        return Buff2;
    }
    return NULL;
}

int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPTSTR    lpCmdLine,
                   int       nCmdShow)
{
    g_hInst = hInstance;
    bool    bRun = false;
    TCHAR   AutoPath[MAX_PATH + 1] = { _T(“) };
    TCHAR   RunApp[MAX_PATH + 1] = { _T(“) };
    if (0 == lstrcmp(lpCmdLine, INSTALL_ARGUMENT))
    {
        if (SHGetAutoRunPath(AutoPath))
        {
            bRun = true;
        }
        //MessageBox( NULL, _T("Card Insertion!!"),
        //    _T("System Tips"), MB_ICONINFORMATION | MB_OK );
    }
    else if (0 == lstrcmp(lpCmdLine, UNINSTALL_ARGUMENT))
    {
        //MessageBox( NULL, _T("Card Removed!!"),
        //    _T("System Tips"), MB_ICONINFORMATION | MB_OK );
    }
    else
    {
        //bRun = true;
        //MessageBox( NULL, _T("Unknown state"),
        //    _T("System Tips"), MB_ICONSTOP | MB_OK );
        MessageBox(NULL, _T("Not implement directly run"), _T("ERROR"), MB_ICONERROR | MB_OK);
        // Tips. using GetModuleFileName() function
    }

    if (bRun)
    {
        int iRet = MessageBox( NULL, _T("Do want to launch an install process?"),
            _T("DriversSetup"), MB_YESNO | MB_ICONINFORMATION);

        if (IDYES == iRet)
        {
            _stprintf(RunApp, _T("%s%s"), GetCardPath(AutoPath), RunappName);

            Launch(RunApp);
        }
    }
    return 0;
}

 

Ref:

Managing Applications on Storage Cards with Autorun.exe

Windows Mobile SDK Code Sample : Card Autorun

QA: How to implement autorun from a storage card

Autorun installation

Technorati tags: , , ,
廣告

發表迴響

在下方填入你的資料或按右方圖示以社群網站登入:

WordPress.com Logo

您的留言將使用 WordPress.com 帳號。 登出 / 變更 )

Twitter picture

您的留言將使用 Twitter 帳號。 登出 / 變更 )

Facebook照片

您的留言將使用 Facebook 帳號。 登出 / 變更 )

Google+ photo

您的留言將使用 Google+ 帳號。 登出 / 變更 )

連結到 %s

%d 位部落客按了讚: