RAPI的CeFindAllFiles的錯誤? |
缺席
|
StephenSytwu
一般會員 發表:4 回覆:6 積分:2 註冊:2004-06-24 發送簡訊給我 |
我使用動態聯結RAPI.DLL方式想要取得PDA上指定目錄的檔案
先測試CeFindAllFiles 但是回復的值是False 請問我哪裡弄錯了? 原碼如下: HINSTANCE Hdl; Hdl = ::LoadLibrary("RAPI.dll"); //載入DLL WideString szSearchPath; szSearchPath = ("\\"); DWORD dwFoundCount; CE_FIND_DATA findDataArray; /* const int FAD_NAME =0x4; typedef struct _CE_FIND_DATA { DWORD dwFileAttributes; FILETIME ftCreationTime; FILETIME ftLastAccessTime; FILETIME ftLastWriteTime; DWORD nFileSizeHigh; DWORD nFileSizeLow; DWORD dwOID; WCHAR cFileName[MAX_PATH]; } CE_FIND_DATA, *LPCE_FIND_DATA; */ int __stdcall (*CeFindAllFiles)(LPCWSTR,DWORD,DWORD,CE_FIND_DATA); //設定定義函式原型 if(Hdl != NULL) { CeFindAllFiles = (BOOL __stdcall (*)(LPCWSTR,DWORD,DWORD,CE_FIND_DATA))::GetProcAddress(Hdl,"CeFindAllFiles"); //獲取函數入口地址 if(CeFindAllFiles != NULL) { if (CeFindAllFiles((LPCWSTR)(szSearchPath),FAF_NAME,dwFoundCount,findDataArray)) { ShowMessage("能取得RAPI資訊!"); } else { ShowMessage("不能取得RAPI資訊!"); } } else { ShowMessage("不能找到函數入口!"); } ::FreeLibrary(Hdl); //一定不要忘記用完后釋放DLL } else { ShowMessage("不能載入DLL!"); } |
StephenSytwu
一般會員 發表:4 回覆:6 積分:2 註冊:2004-06-24 發送簡訊給我 |
//改用 CeFindFirstFile and CeFindNextFile
/* typedef struct _CE_FIND_DATA { DWORD dwFileAttributes; FILETIME ftCreationTime; FILETIME ftLastAccessTime; FILETIME ftLastWriteTime; DWORD nFileSizeHigh; DWORD nFileSizeLow; DWORD dwOID; WCHAR cFileName[MAX_PATH]; } CE_FIND_DATA, *LPCE_FIND_DATA;//CE_FIND_DATA, *LPCE_FIND_DATA; */ int GetRemotePDAFileList(WideString RemotePathName, TStrings* LocalStrings)//-1 false 0 unknow false 1 success { HINSTANCE Hdl; Hdl = ::LoadLibrary("RAPI.dll"); //載入DLL if (Hdl == NULL) { return -1;//ShowMessage("不能載入DLL!"); } else { try { HRESULT __stdcall (*CeRapiInit)();//設定定義函式原型 CeRapiInit = (HRESULT __stdcall (*)())::GetProcAddress(Hdl,"CeRapiInit"); //獲取函數入口地址 void __stdcall (*CeRapiUnInit)();//設定定義函式原型 CeRapiUnInit = (void __stdcall (*)())::GetProcAddress(Hdl,"CeRapiUnInit"); //獲取函數入口地址 // BOOL __stdcall (*CeFindAllFiles)(LPCWSTR,DWORD,DWORD,LPCE_FIND_DATA); //設定定義函式原型 // CeFindAllFiles = (BOOL __stdcall (*)(LPCWSTR,DWORD,DWORD,LPCE_FIND_DATA))::GetProcAddress(Hdl,"CeFindAllFiles"); HANDLE __stdcall (*CeFindFirstFile)(LPCWSTR,LPCE_FIND_DATA); //設定定義函式原型 CeFindFirstFile = (HANDLE __stdcall (*)(LPCWSTR,LPCE_FIND_DATA))::GetProcAddress(Hdl,"CeFindFirstFile"); BOOL __stdcall (*CeFindNextFile)(HANDLE,LPCE_FIND_DATA); //設定定義函式原型 CeFindNextFile = (BOOL __stdcall (*)(HANDLE,LPCE_FIND_DATA))::GetProcAddress(Hdl,"CeFindNextFile"); BOOL __stdcall (*CeFindClose)(HANDLE); //設定定義函式原型 CeFindClose = (BOOL __stdcall (*)(HANDLE))::GetProcAddress(Hdl,"CeFindClose"); CeRapiInit(); DWORD dwFoundCount=0; LPCE_FIND_DATA findDataArray1 = new CE_FIND_DATA[1024]; WCHAR wszFileName[MAX_PATH]; RemotePathName = RemotePathName "\\*.*"; HANDLE MyH1 = new HANDLE; MyH1 = CeFindFirstFile(RemotePathName,findDataArray1); if (MyH1 != INVALID_HANDLE_VALUE) { LocalStrings->Clear(); LocalStrings->Add(findDataArray1->cFileName); while (CeFindNextFile(MyH1,findDataArray1)) { LocalStrings->Add(findDataArray1->cFileName); } CeFindClose(MyH1); return 1; } else { return 0; } } catch(...) { return -1; } ::FreeLibrary(Hdl); //一定不要忘記用完后釋放DLL } } 然後呼叫 GetRemotePDAFileList("\\My Documents",ListBox1->Items); 就會顯示於ListBox1中
編輯記錄
|
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |