📄 pctowcedlg.cpp
字号:
//return ;
//_tprintf( TEXT("File not updateded\n"));
// goto CloseConnection;
// }
}
}
hSrc = CreateFile(
tszSrcFile,
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
if (INVALID_HANDLE_VALUE == hSrc)
{
MessageBox("无法打开PC文件", "");
return ;
//_tprintf( TEXT("Unable to open source/host file"));
//return 1;
}
hDest = CeCreateFile(
wszDestFile,
GENERIC_WRITE,
FILE_SHARE_READ,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL);
if (INVALID_HANDLE_VALUE == hDest )
{
MessageBox("无法打开WinCE文件", "");
//_tprintf( TEXT("Unable to open WinCE file"));
//return 1;
return;
}
#ifdef UNICODE
wprintf( TEXT("Copying %s to WCE:%s\n"), tszSrcFile, wszDestFile);
#else
printf( TEXT("Copying %s to WCE:%S\n"), tszSrcFile, wszDestFile);
#endif
do
{
if (ReadFile(
hSrc,
&Buffer,
sizeof(Buffer),
&dwNumRead,
NULL))
{
if (!CeWriteFile(
hDest,
&Buffer,
dwNumRead,
&dwNumWritten,
NULL))
{
MessageBox("无法写入WinCE文件", "");
return ;
//_tprintf( TEXT("Error !!! Writing WinCE file"));
//goto FatalError;
}
}
else
{
MessageBox("无法读原文件", "");
return ;
//_tprintf( TEXT("Error !!! Reading source file"));
//goto FatalError;
}
//MessageBox("Error !!! Reading source file", "");
//_tprintf( TEXT("."));
} while (dwNumRead);
//_tprintf( TEXT("\n"));
FatalError:
CeCloseHandle( hDest);
CloseHandle (hSrc);
CloseConnection:
// _tprintf( TEXT("Closing connection ..."));
CeRapiUninit();
//_tprintf( TEXT("Done\n"));
MessageBox("完成!!!", "");
// return 0;
}
void CPCtoWCEDlg::OnButton2()
{
// TODO: Add your control notification handler code here
CString FilePathName;
CFileDialog file(TRUE,NULL,NULL);
file.m_ofn.lpstrInitialDir = "c:\\";
//file.DoModal();
if(file.DoModal()==IDOK)
FilePathName=file.GetPathName();
GetDlgItem(IDC_EDIT1)->SetWindowText(FilePathName);
}
///////////////////////////////////////////////////////////////////////
void CPCtoWCEDlg::wcetopc()
{
UpdateData();
//char *argv[ ];
TCHAR wszDestFile[MAX_PATH];
WCHAR wszSrcFile[MAX_PATH];
TCHAR tszDestFile[MAX_PATH];
WCHAR tszSrcFile[MAX_PATH];
BYTE Buffer[4096];
HANDLE hSrc, hDest, hFind;
//HANDLE hSrc, hDest;
//CString hFind;
CE_FIND_DATA wfd;
HRESULT hRapiResult;
DWORD dwAttr, dwNumRead, dwNumWritten;
if(wce_file1=="")
{
MessageBox("请输入WinCE的文件名","提示");
return ;
}
if(pc_file1=="")
{
MessageBox("请输入要保存的文件名","提示");
return;
}
CString wcefile1="\\my documents\\"+wce_file1;
CString pcfile1="c:\\"+pc_file1;
//CString aa="\\my documents\\wepkeys.txt";
//#ifdef UNICODE
MultiByteToWideChar(
CP_ACP,
MB_PRECOMPOSED,
wcefile1,
strlen(wcefile1)+1,
wszSrcFile,
sizeof(wszSrcFile));
// #else
// _tcscpy( wszSrcFile, wcefile1);
//#endif
#ifdef UNICODE
MultiByteToWideChar(
CP_ACP,
MB_PRECOMPOSED,
pcfile1,
strlen(pcfile1)+1,
tszDestFile,
sizeof(tszDestFile));
#else
_tcscpy( tszDestFile, pcfile1);
#endif
//_tprintf( TEXT("Connecting to Windows CE..."));
RAPIINIT rapiinit;
rapiinit.cbSize=sizeof(RAPIINIT);
if(CeRapiInitEx(&rapiinit)!=S_OK)
{
// ShowError(IDM_RAPIINIT_ERROR);
//CDialog::OnCancel();
}
if(::WaitForSingleObject(rapiinit.heRapiInit,0)!=WAIT_OBJECT_0)
{
//连接成功
//MessageBox("连接成功", "");
MessageBox("手持未连接", "");
return ;
}
hRapiResult = CeRapiInit();
if (FAILED(hRapiResult))
{
//_tprintf( TEXT("Failed\n"));
//return 1;
}
//_tprintf( TEXT("Success\n"));
hFind = CeFindFirstFile( wszSrcFile, &wfd);
if (INVALID_HANDLE_VALUE == hFind)
{
//_tprintf( TEXT("Windows CE file does not exist\n"));
//return 1;
}
CeFindClose( hFind);
if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
//_tprintf( TEXT("Windows CE file specifies a directory\n"));
//return 1;
}
dwAttr = GetFileAttributes( tszDestFile);
if (0xFFFFFFFF != dwAttr)
{
if (dwAttr & FILE_ATTRIBUTE_DIRECTORY)
{
//Just a directory was specified so we will have to get the filename from the src spec.
strcat( tszDestFile, "\\");
#ifdef UNICODE
wcscpy( tszDestFile+wcslen(tszDestFile), wfd.cFileName);
#else
WideCharToMultiByte(
CP_ACP,
0,
wfd.cFileName,
wcslen(wfd.cFileName)+1,
wszDestFile+strlen(wszDestFile),
sizeof(wszDestFile)-strlen(wszDestFile),
NULL,
FALSE);
#endif
}
else
{
//_tprintf( TEXT("File already exists. Do you want to overwrite ? (Y/N)"));
//if ( 'N' == toupper(getchar()))
//{
// _tprintf( TEXT("File not updateded\n"));
// goto CloseConnection;
//}
}
}
hSrc = CeCreateFile(
wszSrcFile,
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
if (INVALID_HANDLE_VALUE == hSrc)
{
//_tprintf( TEXT("Unable to open Windows CE file"));
//return 1;
}
hDest = CreateFile(
tszDestFile,
GENERIC_WRITE,
FILE_SHARE_READ,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL);
if (INVALID_HANDLE_VALUE == hDest)
{
//_tprintf( TEXT("Unable to open host/destination file"));
//return 1;
}
#ifdef UNICODE
wprintf( TEXT("Copying WCE:%s to %s\n"), wszSrcFile, tszDestFile);
#else
printf( TEXT("Copying WCE:%S to %s\n"), tszSrcFile, tszDestFile);
#endif
do
{
if (CeReadFile(
hSrc,
&Buffer,
sizeof(Buffer),
&dwNumRead,
NULL))
{
if (!WriteFile(
hDest,
&Buffer,
dwNumRead,
&dwNumWritten,
NULL))
{
//_tprintf( TEXT("Error !!! Writing hostfile"));
//goto FatalError;
}
}
else
{
//_tprintf( TEXT("Error !!! Reading Windows CE file"));
//goto FatalError;
}
//_tprintf( TEXT("."));
} while (dwNumRead);
// _tprintf( TEXT("\n"));
FatalError:
CeCloseHandle( hSrc);
CloseHandle (hDest);
CloseConnection:
//_tprintf( TEXT("Closing connection ..."));
CeRapiUninit();
//_tprintf( TEXT("Done\n"));
MessageBox("完成!!!","");
//return 0;
}
void CPCtoWCEDlg::ONCOLOSE()
{
// TODO: Add your control notification handler code here
ExitProcess(0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -