📄 rapicopy.cpp
字号:
// jsta.cpp : Defines the entry point for the console application.
//
#include <windows.h>
#include <stdio.h>
#include <rapi.h>
#include "stdafx.h"
#include "rapitypes.h"
#pragma comment(lib, "rapi.lib")
#define BUFFSIZE 32*1024
extern "C"
{
STDAPI CeRapiInit();
STDAPI CeRapiUninit();
STDAPI_( HRESULT ) CeRapiInvoke(LPCWSTR, LPCWSTR,DWORD,BYTE *, DWORD *,BYTE **, IRAPIStream **,DWORD);
STDAPI_(HANDLE) CeFindFirstFile(LPCWSTR, LPCE_FIND_DATA);
STDAPI_(BOOL) CeGetVersionEx(LPCEOSVERSIONINFO);
}
HRESULT TryRapiConnect(DWORD dwTimeOut)
{
HRESULT hr = E_FAIL;
RAPIINIT riCopy;
BOOL fInitialized = FALSE;
ZeroMemory(&riCopy, sizeof(riCopy));
riCopy.cbSize = sizeof(riCopy);
hr = CeRapiInitEx(&riCopy);
if (SUCCEEDED(hr))
{
DWORD dwRapiInit = 0;
fInitialized = TRUE;
dwRapiInit = WaitForSingleObject(
riCopy.heRapiInit,
dwTimeOut);
if (WAIT_OBJECT_0 == dwRapiInit)
{
// heRapiInit signaled:
// set return error code to return value of RAPI Init function
hr = riCopy.hrRapiInit;
}
else if (WAIT_TIMEOUT == dwRapiInit)
{
// timed out: device is probably not connected
// or not responding
hr = HRESULT_FROM_WIN32(ERROR_TIMEOUT);
}
else
{
// WaitForSingleObject failed
hr = HRESULT_FROM_WIN32(GetLastError());
}
}
if (fInitialized && FAILED(hr))
{
CeRapiUninit();
}
return hr;
}
void copyCabFile(TCHAR *a_pFileName)
{
HANDLE l_hPCFil = NULL;
HANDLE l_hDeviceFil = NULL;
PBYTE l_pBuffer = 0;
DWORD l_bytesRead = 0;
DWORD l_bytesWritten = 0;
BOOL l_bSuccess;
HRESULT hr = E_FAIL;
//Initialize Windows CE RAPI
if(ERROR_SUCCESS != TryRapiConnect(1000)){
printf("ERROR:the connection is not made!\r\n");
return;
}
// Allocate a buffer.
l_pBuffer = (PBYTE)LocalAlloc (LMEM_FIXED, BUFFSIZE);
l_hPCFil = CreateFile (a_pFileName,
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
//l_iFileSize = (int)GetFileSize (l_hPCFil, NULL);
//if (l_iFileSize < 0) return 0;
if (l_hPCFil == INVALID_HANDLE_VALUE) {
return;
}
l_hDeviceFil = CeCreateFile(a_pFileName,
GENERIC_WRITE,
FILE_SHARE_READ,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL);
if (l_hDeviceFil == INVALID_HANDLE_VALUE) {
return;
}
do {
// Read the file in PC.
l_bSuccess = ReadFile(l_hPCFil,
l_pBuffer,
BUFFSIZE,
&l_bytesRead,
NULL);
if (l_bSuccess){
l_bSuccess = CeWriteFile(l_hDeviceFil,
l_pBuffer,
l_bytesRead,
&l_bytesWritten,
NULL);
}
} while (l_bSuccess && (0 < l_bytesRead));
l_bSuccess = CloseHandle(l_hPCFil);
l_bSuccess = CeCloseHandle(l_hDeviceFil);
if(l_pBuffer){
LocalFree(l_pBuffer);
l_pBuffer = NULL;
}
hr = CeRapiUninit();
printf("success\r\n");
}
//////////////////////////////////////////////////////////////////////////
int _tmain(int argc, _TCHAR* argv[])
{
TCHAR l_filename[32] = _T("");
if(argc == 1) return 0;
wcscpy(l_filename,argv[1]);
copyCabFile(l_filename);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -