📄 rapiserv.cpp
字号:
//====================================================================
// RapiServ - A RAPI block mode server DLL
//
// Written for the book Programming Windows CE
// Copyright (C) 2003 Douglas Boling
//====================================================================
#include <windows.h> // For all that Windows stuff
// The following ensures that the function will be exported from the DLL
// and that any C++ compilers used won't mangle the name.
#ifdef __cplusplus
extern "C" {
#endif
__declspec (dllexport) INT RAPIGetDiskSize (DWORD, BYTE *, DWORD *,
BYTE **, PVOID);
#ifdef __cplusplus
}
#endif
//====================================================================
// DllMain - DLL initialization entry point
//
BOOL WINAPI DllMain (HANDLE hinstDLL, DWORD dwReason,
LPVOID lpvReserved) {
return TRUE;
}
//====================================================================
// RAPIGetDiskSize - Returns the disk size and free space. Called from
// PC application using RAPI.
//
INT RAPIGetDiskSize (DWORD cbInput, BYTE *pInput, DWORD *pcbOutput,
BYTE **ppOutput, PVOID reserved) {
PDWORD pdwLocal;
LPTSTR pPtr;
DWORD i;
int rc = 0;
ULARGE_INTEGER lnFree, lnTotal;
printf ("RAPIGetDiskSize called\r\n");
*pcbOutput = 0; // Zero output bytes for now.
if (!pInput) return -1; // Make sure there is an input buffer.
// See if proper zero-terminated string.
pPtr = (LPTSTR)pInput;
for (i = 0; i < cbInput / 2; i++)
if (!*pPtr++)
break;
// If not zero terminated or if zero length, return error.
if ((i >= cbInput / 2) || (i == 0)) {
LocalFree (pInput);
return -2;
}
// Call the function.
if (GetDiskFreeSpaceEx ((LPTSTR)pInput, NULL, &lnTotal, &lnFree)) {
// Allocate memory for the return buffer.
pdwLocal = (PDWORD) LocalAlloc (LPTR, 2 * sizeof (DWORD));
if (pdwLocal) {
// Copy data from function to output buffer.
pdwLocal[0] = lnTotal.LowPart;
pdwLocal[1] = lnFree.LowPart;
// Specify size and buffer.
*pcbOutput = 2 * sizeof (DWORD);
*ppOutput = (PBYTE)pdwLocal;
} else
rc = GetLastError();
} else
rc = GetLastError();
// The function is responsible for freeing the input buffer.
LocalFree (pInput);
return rc;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -