?? rapi.cpp
字號:
// RAPI.cpp: implementation of the CRAPI class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "RAPI.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CRAPI::CRAPI()
{
InitializeSettings();
}
CRAPI::~CRAPI()
{
if( !hInst )
{
FreeLibrary(hInst);
}
}
void CRAPI::InitializeSettings()
{
hInst = NULL;
LPTSTR pPath = new TCHAR[MAX_PATH + 10];
GetSystemDirectory(pPath, MAX_PATH);
CString str(pPath);
str += "\\rapi.dll";
hInst = LoadLibrary(str);
if (hInst)
{
CeRapiInit = (FARPROC) GetProcAddress(hInst, "CeRapiInit");
CeRapiUninit = (FARPROC) GetProcAddress(hInst, "CeRapiUninit");
CeCreateFile = (pfnFunc0)GetProcAddress(hInst, "CeCreateFile");
CeWriteFile = (pfnFunc1)GetProcAddress(hInst, "CeWriteFile");
CeCloseHandle = (pfnFunc2)GetProcAddress(hInst, "CeCloseHandle");
CeFindFirstFile = (pfnFunc3)GetProcAddress(hInst, "CeFindFirstFile");
CeGetFileSize = (pfnFunc4)GetProcAddress(hInst, "CeGetFileSize");
CeReadFile = (pfnFunc5)GetProcAddress(hInst, "CeReadFile");
CeFindNextFile = (pfnFunc6)GetProcAddress(hInst, "CeFindNextFile");
CeCreateDirectory = (pfnFunc7)GetProcAddress(hInst, "CeCreateDirectory");
CeCreateProcess = (pfnFunc8)GetProcAddress(hInst, "CeCreateProcess");
CeGetSystemInfo = (pfnFunc9)GetProcAddress(hInst, "CeGetSystemInfo");
CeDeleteFile = (pfnFunc10)GetProcAddress(hInst, "CeDeleteFile");
CeRegOpenKeyEx = (pfnFunc11)GetProcAddress(hInst, "CeRegOpenKeyEx");
CeRegCloseKey = (pfnFunc12)GetProcAddress(hInst, "CeRegCloseKey");
}
delete []pPath;
}
#define BUFFER_SIZE 10240
void CRAPI::CopyFilePCtoWinCE(CString strFileNamePC, CString strFileNamePPC)
{
CFile oldFile;
oldFile.Open(strFileNamePC, CFile::modeRead |CFile::typeBinary);
int iLen = oldFile.GetLength();
iLen = iLen / BUFFER_SIZE;
BSTR bstr = strFileNamePPC.AllocSysString();
SysFreeString(bstr);
CeRapiInit();
HANDLE h = CeCreateFile(bstr, GENERIC_READ | GENERIC_WRITE, 0, NULL,
OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
char cTemp[BUFFER_SIZE];
DWORD nbytes;
int iTotBytes = 0;
int iReaded=0;
while((iReaded=oldFile.Read(&cTemp, BUFFER_SIZE)) >= 1)
CeWriteFile(h, &cTemp, (DWORD)iReaded, &nbytes, NULL);
CeCloseHandle(h);
oldFile.Close();
CeRapiUninit();
}
void CRAPI::CopyFileWinCEtoPC(CString strFileNamePPC, CString strFileNamePC)
{
BSTR bstr = strFileNamePPC.AllocSysString();
SysFreeString(bstr);
CeRapiInit();
HANDLE h;
h = CeCreateFile(bstr, GENERIC_READ, FILE_SHARE_READ, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
CFile oldFile;
oldFile.Open(strFileNamePC, CFile::modeCreate | CFile::modeWrite);
char cTemp[BUFFER_SIZE];
DWORD nbytes;
CString s;
while(CeReadFile(h, &cTemp, (DWORD)BUFFER_SIZE, &nbytes, NULL) == TRUE)
{
oldFile.Write(&cTemp, nbytes);
if(nbytes < BUFFER_SIZE)
break;
}
CeCloseHandle(h);
oldFile.Close();
CeRapiUninit();
}
BOOL CRAPI::DeleteFileFromCE(CString strFileNamePPC)
{
BSTR bstr = strFileNamePPC.AllocSysString();
SysFreeString(bstr);
CeRapiInit();
BOOL bRet = CeDeleteFile(bstr);
CeRapiUninit();
return bRet;
}
CString CRAPI::GetCStringFromFile(CString strFileName)
{
CString strOut;
LPSTR pText = NULL;
int iLen;
CFile f;
if (f.Open(strFileName, CFile::modeReadWrite))
{
iLen = f.GetLength();
pText = new char[iLen + 1];
f.Read(pText, iLen);
pText[iLen] = '\0';
CString str(pText);
strOut = str;
delete pText;
f.Close();
}
else
{
strOut = "Error";
}
return strOut;
}
LONG CRAPI::RegOpenKeyExFromCE(HKEY hKey, LPCWSTR lpsz, DWORD dw, REGSAM reg, PHKEY phKey)
{
CeRapiInit();
HRESULT hResult=CeRegOpenKeyEx(hKey,lpsz,dw,reg,phKey);
CeRapiUninit();
return hResult;
}
LONG CRAPI::RegCloseKeyFromCE(HKEY hKey)
{
CeRapiInit();
HRESULT hResult = CeRegCloseKey(hKey);
CeRapiUninit();
return hResult;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -