MSDN的说明:
This function will search for the first storage card and construct the path that is used to look for an autorun file. The autorun file and directory do not need to be present on the storage card, but a storage card must be inserted for this function to succeed.
Syntax
BOOL SHGetAutoRunPath(
LPTSTR pAutoRunPath
);
Parameters
-
pAutoRunPath
-
[out] Pointer to a user-allocated string allocated to at least MAX_PATH characters. If successful, the full path name to the autorun directory will be copied here (for example, /Storage Card 1/2577/autorun.exe).
Return Values
Returns TRUE if a path was successfully constructed and copied to pAutoRunPath. Returns FALSE if a path could not be copied. FALSE indicates that either the input parameter is invalid or a storage card is not currently inserted.
Remarks
This function returns a string in the form /Storage Card 1/2577/autorun.exe. The operating system (OS) looks for the file autorun.exe in an appropriate subdirectory, which should be named using the microprocessor ID number found in Winnt.h. The following table shows microprocessor IDs for some common microprocessor families.
Microprocessor family |
Microprocessor ID |
All x86 microprocessors |
486 |
MIPS II/MIPS32 |
4000 |
MIPS IV/MIPS64 |
5000 |
SH4 |
10005 |
You can call GetSystemInfo to determine the microprocessor type and architecture for your device.
Windows Mobile Remarks
The following table provides processor values for each of the supported processor types.
CPU name |
CPU type value |
SH3 |
10003 |
MIPS |
4000 |
ARM (SA1100) |
2577 |
ARM (720) |
1824 |
x86 |
686 |
In addition, if autorun.exe is not found in the processor-specific subdirectory, SHGetAutoRunPath will return /<Storage Card>/0/autorun.exe, which indicates a special processor type of 0 for a CEF executable. For example, if the storage card contained 4000/autorun.exe and 0/autorun.exe, the executable file in 4000/ would be run on a MIPS device; on an SH3 device, the executable file in 0/ would be run. As with the old name-based implementation, you may make these folders hidden to avoid cluttering up the folder view in applications like the File Explorer.
After autorun.exe begins to run, it is sometimes useful for it to know which directory it is running from. Autorun.exe can then determine how to manage files or take actions based on its location in the system.
Requirements
OS Versions: Windows CE .NET 4.2 and later
Header: windows.h.
Library: aygshell.lib
Windows Mobile Requirements
Pocket PC: Pocket PC 2000 and later
Smartphone: Smartphone 2002 and later
OS Versions: Windows CE 3.0 and later
Header: aygshell.h
Library: aygshell.lib
===================================================================
用法:
QA: How to implement autorun from a storage card?
February 1st, 2005 by Joao Paulo Figueira
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.
http://windowsmobiledn.com/qa-how-to-implement-autorun-from-a-storage-card/