QA: How to implement autorun from a storage card?
By Joao Paulo Figueira, June 02, 2003.
Print version
Question
I want to start an application when the user inserts or removes a storage card.
How do I implement such functionality?
Answer
You can execute an application when a storage card is inserted or removed from your
device. This may allow your users to install applications, perform backups, or other
action you like. The protocol is really simple:
- Create one directory under the root of the card named after your CPU's ID. For
instance, StrongARM is 2577, SH3 is 10003 and MIPS is 4000.
- Your application must be named autorun.exe and it must be in that directory.
- When the card is inserted, the application is called with 'install' as the
command line parameter. When the card is removed, the parameter is 'uninstall'.
Here is a skeleton application. You can create it using eVC's Wizard, choosing the
'WCE Pocket PC 2002 Application'.
TCHAR szCFPath [MAX_PATH+1]; // Compact Flash path
// OnCardInsert
//
// The compact flash card has been inserted
//
void OnCardInsert()
{
//
// Get the path from where we are starting up
//
if(!SHGetAutoRunPath(szCFPath))
{
return;
}
}
// OnCardRemove
//
// The compact flash card has been removed
//
void OnCardRemove()
{
}
// WinMain
//
// Main entry point
//
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
if(lstrcmpi(lpCmdLine, _T("install")) == 0)
{
//
// Card has been inserted
//
OnCardInsert();
}
else if(lstrcmpi(lpCmdLine, _T("uninstall")) == 0)
{
//
// Card has been removed
//
OnCardRemove();
}
return 0;
}
Note that your application does not know where it is starting. You cannot infer that the startup
path will be the one you are expecting.
Related resources:
Discuss
Discuss this article.
Here you can write your comments and read comments of other developers.
|