|
定义函数
typedef HRESULT (WINAPI *pRapiInitEx)(RAPIINIT* pRapiInit);
typedef BOOL (WINAPI *pCeMoveFile)(LPCWSTR lpExistingFileName,
LPCWSTR lpNewFileName);
typedef BOOL (WINAPI *pCeCopyFile)( LPCWSTR lpExistingFileName, LPCWSTR lpNewFileName,
BOOL bFailIfExists
);
static pRapiInitEx RapiInitEx;
static pCeMoveFile movefile;
static pCeCopyFile copyfile;
执行移动的代码:
m_hInstance=::LoadLibrary("rapi.dll");
if (m_hInstance==NULL)
{
MessageBox("初始化库失败!!!");
return ;
}
RapiInitEx=(pRapiInitEx)GetProcAddressm_hInstance,"CeRapiInitEx");
if (!RapiInitEx)
{
return;
}
RAPIINIT ra;
ra.cbSize=sizeof(RAPIINIT);
RapiInitEx(&ra);
DWORD dWait; dWait=MsgWaitForMultipleObjects1,&ra.heRapiInit,TRUE,200,QS_ALLEVENTS);
if (dWait==WAIT_TIMEOUT)
{
MessageBox("wait time out !!");
FreeRAPILibrary();
return;
}
else if (ra.hrRapiInit==E_FAIL )
{
MessageBox("连结失败");
FreeRAPILibrary();
return;
}
else if (ra.hrRapiInit==E_INVALIDARG)
{
MessageBox("faile");
FreeRAPILibrary();
return;
}
//////////////////////////////////////////////////////////////////////////
//初始化函数库
copyfile=(pCeCopyFile )GetProcAddress(m_hInstance,"CeCopyFile");
if (!copyfile)
{
MessageBox("get file address faile");
FreeRAPILibrary();
return;
}
//移动文件
LPCWSTR ExistingFileName=L"\\Storage Card\\History\\2\2007-08-15\\12 2003-9-1-17-11.dat";
LPCWSTR NewFileName=L"E:\\CeFile\\2.dat";
BOOL bSuccess=copyfile(ExistingFileName,NewFileName,FALSE);
FreeRAPILibrary();
if (bSuccess)
{
MessageBox("ok");
}
else
{
MessageBox("error");
}
用CeCopyFile 和CeMoveFile时将不能移动文件,而当用CeFirstFile与CeFindNextFile(),CeReadFile,CeCreateFile等时,能完成文件移动!!
|
|