?? rapifind.cpp
字號:
//======================================================================
// RapiFind - Searches for a file or files on a Windows CE system
//
// Written for the book Programming Windows CE
// Copyright (C) 1998 Douglas Boling
//======================================================================
#include <windows.h> // For all that Windows stuff
#include <stdio.h>
#include <rapi.h> // RAS includes
//======================================================================
// main - Program entry point
//
int main (int argc, char **argv) {
RAPIINIT ri;
char szSrch[MAX_PATH], *pPtr;
WCHAR szwDir[MAX_PATH];
WCHAR szName[MAX_PATH];
DWORD i, dwTotal = 0, dwFiles = 0, dwIn, dwOut, cbBytes;
IRAPIStream *pIRAPIStream;
PBYTE pInput, pOut;
HRESULT hr;
INT rc, nCmd, nSize;
// If no argument, fail.
if (argc < 2) {
printf ("\r\nUSAGE: %s <search spec>\r\n\r\n", argv[0]);
return -1;
}
lstrcpy (szSrch, argv[1]);
// Call RapiInitEx to asynchronously start RAPI session.
ri.cbSize = sizeof (ri);
rc = CeRapiInitEx (&ri);
if (rc != NOERROR) {
printf (TEXT ("Rapi Initialization failed\r\n"));
return 0;
}
// Wait 5 seconds for connect.
rc = WaitForSingleObject (ri.heRapiInit, 5000);
if (rc == WAIT_OBJECT_0) {
if (ri.hrRapiInit != NOERROR) {
printf (TEXT ("Rapi Initialization failed\r\n"));
return 0;
}
} else if (rc == WAIT_TIMEOUT) {
printf (TEXT ("Rapi Initialization timed out.\r\n"));
return 0;
}
// Point to end of name.
pPtr = szSrch + lstrlen (szSrch) - 1;
// Strip any trailing backslash.
if (*pPtr == '\\')
*pPtr = '\0';
// Look for wildcards in filename. pPtr points to string end.
for (i = 0; (pPtr >= szSrch) && (*pPtr != '\\'); pPtr--) {
if ((*pPtr == '*') || (*pPtr == '?'))
i++;
}
if (pPtr <= szSrch) {
lstrcpy (szSrch, TEXT ("\\"));
lstrcat (szSrch, argv[1]);
}
if (i) {
printf (TEXT ("\r\n Searching for %s\r\n\r\n"), pPtr+1);
} else
printf (TEXT ("\r\n Searching in %s\r\n\r\n"), szSrch);
// No wildcards, append *.*
if (i == 0)
lstrcat (szSrch, "\\*.*");
// Convert ANSI string to Unicode. At the same time, copy it
// into a discardable buffer for CeRapiInvoke.
dwIn = lstrlen (szSrch)+1;
pInput = (PBYTE)LocalAlloc (LPTR, dwIn * sizeof (WCHAR));
if (!pInput) {
printf (TEXT ("\r\nOut of memory\r\n"));
return -1;
}
mbstowcs ((LPWSTR)pInput, szSrch, dwIn);
dwIn *= sizeof (WCHAR);
// RAPI call
hr = CeRapiInvoke (L"\\FindSrv", L"RAPIFindFile", dwIn,
pInput, &dwOut, &pOut, &pIRAPIStream, 0);
if (hr == S_OK) {
// Read command.
pIRAPIStream->Read (&nCmd, sizeof (nCmd), &cbBytes);
while (nCmd) {
switch (nCmd) {
// Display found file.
case 1:
// Read length of file.
pIRAPIStream->Read (&i, sizeof (i), &cbBytes);
dwTotal += i;
dwFiles++;
// Read length of filename.
pIRAPIStream->Read (&nSize, sizeof (nSize), &cbBytes);
// Read name itself.
pIRAPIStream->Read (szName, nSize, &cbBytes);
// Print directory and name.
printf (TEXT ("%9d\t%S%S\r\n"), i, szwDir, szName);
break;
// Display name of directory we're currently searching.
case 2:
// Read and discard dummy length value.
pIRAPIStream->Read (&nSize, sizeof (nSize), &cbBytes);
// Read length of directory.
pIRAPIStream->Read (&nSize, sizeof (nSize), &cbBytes);
// Read directory name itself.
pIRAPIStream->Read (szwDir, nSize, &cbBytes);
break;
}
// Read next command.
pIRAPIStream->Read (&nCmd, sizeof (nCmd), &cbBytes);
}
} else if (hr == ERROR_FILE_NOT_FOUND)
printf (TEXT ("The RAPI server DLL FindSrv could not be found \
on the CE target device.\r\n"));
else
printf (TEXT ("CeRapiInvoke returned %d"), hr);
printf (TEXT ("\r\nFound %d file(s). Total of %d bytes.\r\n\r\n"),
dwFiles, dwTotal);
// Clean up by uninitializing RAPI.
CeRapiUninit ();
return 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -