Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

606 lines
16 KiB

  1. #include "stdafx.h"
  2. #include "drmerr.h"
  3. #define E_NoActiveSync HRESULT_FROM_WIN32(ERROR_DLL_NOT_FOUND)
  4. #define WIN_ERR_NO_ACTIVE_SYNC ERROR_DLL_NOT_FOUND
  5. #define RAPILIBNAME L"rapi.dll"
  6. HRESULT CeRapiInitEx(RAPIINIT* pRapiInit)
  7. {
  8. HMODULE hMod = LoadLibrary (RAPILIBNAME);
  9. if (hMod != NULL)
  10. {
  11. typedef HRESULT (*PFN)(RAPIINIT *);
  12. PFN pfn = (PFN) GetProcAddress(hMod, "CeRapiInitEx");
  13. _Assert (pfn != NULL); //there is no good reason that this fn wd not be there, it probably means a bug in late binding
  14. if (pfn != NULL)
  15. {
  16. return (*pfn)(pRapiInit);
  17. }
  18. }
  19. return E_NoActiveSync;
  20. }
  21. HRESULT CeRapiInvoke( LPCWSTR pDllPath, LPCWSTR pFunctionName, DWORD cbInput, BYTE *pInput,
  22. DWORD *pcbOutput, BYTE **ppOutput, IRAPIStream **ppIRAPIStream, DWORD dwReserved )
  23. {
  24. HMODULE hMod = LoadLibrary (RAPILIBNAME);
  25. if (hMod != NULL)
  26. {
  27. typedef HRESULT (*PFN)(LPCWSTR, LPCWSTR, DWORD, BYTE*, DWORD*, BYTE**, IRAPIStream**, DWORD);
  28. PFN pfn = (PFN) GetProcAddress(hMod, "CeRapiInvoke");
  29. _Assert (pfn != NULL); //there is no good reason that this fn wd not be there, it probably means a bug in late binding
  30. if (pfn != NULL)
  31. {
  32. return (*pfn)(pDllPath, pFunctionName, cbInput, pInput, pcbOutput, ppOutput, ppIRAPIStream, dwReserved);
  33. }
  34. }
  35. return E_NoActiveSync;
  36. }
  37. HRESULT CeRapiInit(void)
  38. {
  39. HMODULE hMod = LoadLibrary (RAPILIBNAME);
  40. if (hMod != NULL)
  41. {
  42. typedef HRESULT (*PFN)(void);
  43. PFN pfn = (PFN) GetProcAddress(hMod, "CeRapiInit");
  44. _Assert (pfn != NULL); //there is no good reason that this fn wd not be there, it probably means a bug in late binding
  45. if (pfn != NULL)
  46. {
  47. return (*pfn)();
  48. }
  49. }
  50. return E_NoActiveSync;
  51. }
  52. LONG CeRegOpenKeyEx( HKEY hKey, LPCWSTR lpszSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult )
  53. {
  54. HMODULE hMod = LoadLibrary (RAPILIBNAME);
  55. if (hMod != NULL)
  56. {
  57. typedef LONG (*PFN)(HKEY , LPCWSTR , DWORD , REGSAM , PHKEY );
  58. PFN pfn = (PFN) GetProcAddress(hMod, "CeRegOpenKeyEx");
  59. _Assert (pfn != NULL); //there is no good reason that this fn wd not be there, it probably means a bug in late binding
  60. if (pfn != NULL)
  61. {
  62. return (*pfn)(hKey, lpszSubKey, ulOptions, samDesired, phkResult);
  63. }
  64. }
  65. return WIN_ERR_NO_ACTIVE_SYNC;
  66. }
  67. HRESULT CeRapiGetError(void)
  68. {
  69. HMODULE hMod = LoadLibrary (RAPILIBNAME);
  70. if (hMod != NULL)
  71. {
  72. typedef HRESULT (*PFN)();
  73. PFN pfn = (PFN) GetProcAddress(hMod, "CeRapiGetError");
  74. _Assert (pfn != NULL); //there is no good reason that this fn wd not be there, it probably means a bug in late binding
  75. if (pfn != NULL)
  76. {
  77. return (*pfn)();
  78. }
  79. }
  80. return E_NoActiveSync;
  81. }
  82. DWORD CeGetLastError( void )
  83. {
  84. HMODULE hMod = LoadLibrary (RAPILIBNAME);
  85. if (hMod != NULL)
  86. {
  87. typedef DWORD (*PFN)();
  88. PFN pfn = (PFN) GetProcAddress(hMod, "CeGetLastError");
  89. _Assert (pfn != NULL); //there is no good reason that this fn wd not be there, it probably means a bug in late binding
  90. if (pfn != NULL)
  91. {
  92. return (*pfn)();
  93. }
  94. }
  95. return WIN_ERR_NO_ACTIVE_SYNC;
  96. }
  97. BOOL CeGetSystemPowerStatusEx(PSYSTEM_POWER_STATUS_EX pstatus, BOOL fUpdate)
  98. {
  99. HMODULE hMod = LoadLibrary (RAPILIBNAME);
  100. if (hMod != NULL)
  101. {
  102. typedef BOOL (*PFN)(PSYSTEM_POWER_STATUS_EX, BOOL);
  103. PFN pfn = (PFN) GetProcAddress(hMod, "CeGetSystemPowerStatusEx");
  104. _Assert (pfn != NULL); //there is no good reason that this fn wd not be there, it probably means a bug in late binding
  105. if (pfn != NULL)
  106. {
  107. return (*pfn)(pstatus, fUpdate);
  108. }
  109. }
  110. return FALSE; //FALSE indicates error
  111. }
  112. HRESULT CeRapiFreeBuffer( LPVOID Buffer )
  113. {
  114. HMODULE hMod = LoadLibrary (RAPILIBNAME);
  115. if (hMod != NULL)
  116. {
  117. typedef HRESULT (*PFN)(LPVOID);
  118. PFN pfn = (PFN) GetProcAddress(hMod, "CeRapiFreeBuffer");
  119. _Assert (pfn != NULL); //there is no good reason that this fn wd not be there, it probably means a bug in late binding
  120. if (pfn != NULL)
  121. {
  122. return (*pfn)(Buffer);
  123. }
  124. }
  125. return E_NoActiveSync;
  126. }
  127. BOOL CeFindAllFiles(LPCWSTR szPath, DWORD dwFlags, LPDWORD lpdwFoundCount, LPLPCE_FIND_DATA ppFindDataArray)
  128. {
  129. HMODULE hMod = LoadLibrary (RAPILIBNAME);
  130. if (hMod != NULL)
  131. {
  132. typedef BOOL (*PFN)(LPCWSTR, DWORD, LPDWORD, LPLPCE_FIND_DATA);
  133. PFN pfn = (PFN) GetProcAddress(hMod, "CeFindAllFiles");
  134. _Assert (pfn != NULL); //there is no good reason that this fn wd not be there, it probably means a bug in late binding
  135. if (pfn != NULL)
  136. {
  137. return (*pfn)(szPath, dwFlags, lpdwFoundCount, ppFindDataArray);
  138. }
  139. }
  140. return FALSE; //FALSE indicates error
  141. }
  142. BOOL CeCreateDirectory(LPCWSTR lpPathName, LPSECURITY_ATTRIBUTES lpSecurityAttributes)
  143. {
  144. HMODULE hMod = LoadLibrary (RAPILIBNAME);
  145. if (hMod != NULL)
  146. {
  147. typedef BOOL (*PFN)(LPCWSTR, LPSECURITY_ATTRIBUTES);
  148. PFN pfn = (PFN) GetProcAddress(hMod, "CeCreateDirectory");
  149. _Assert (pfn != NULL); //there is no good reason that this fn wd not be there, it probably means a bug in late binding
  150. if (pfn != NULL)
  151. {
  152. return (*pfn)(lpPathName, lpSecurityAttributes);
  153. }
  154. }
  155. return FALSE; //FALSE indicates error
  156. }
  157. BOOL CeCloseHandle( HANDLE hObject )
  158. {
  159. HMODULE hMod = LoadLibrary (RAPILIBNAME);
  160. if (hMod != NULL)
  161. {
  162. typedef BOOL (*PFN)(HANDLE);
  163. PFN pfn = (PFN) GetProcAddress(hMod, "CeCloseHandle");
  164. _Assert (pfn != NULL); //there is no good reason that this fn wd not be there, it probably means a bug in late binding
  165. if (pfn != NULL)
  166. {
  167. return (*pfn)(hObject);
  168. }
  169. }
  170. return FALSE;
  171. }
  172. BOOL CeSetFileAttributes(LPCWSTR lpFileName, DWORD dwFileAttributes)
  173. {
  174. HMODULE hMod = LoadLibrary (RAPILIBNAME);
  175. if (hMod != NULL)
  176. {
  177. typedef BOOL (*PFN)(LPCWSTR, DWORD);
  178. PFN pfn = (PFN) GetProcAddress(hMod, "CeSetFileAttributes");
  179. _Assert (pfn != NULL); //there is no good reason that this fn wd not be there, it probably means a bug in late binding
  180. if (pfn != NULL)
  181. {
  182. return (*pfn)(lpFileName, dwFileAttributes);
  183. }
  184. }
  185. return FALSE;
  186. }
  187. LONG CeRegQueryValueEx( HKEY hKey, LPCWSTR lpValueName, LPDWORD lpReserved, LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData )
  188. {
  189. HMODULE hMod = LoadLibrary (RAPILIBNAME);
  190. if (hMod != NULL)
  191. {
  192. typedef LONG (*PFN)( HKEY, LPCWSTR, LPDWORD, LPDWORD, LPBYTE, LPDWORD );
  193. PFN pfn = (PFN) GetProcAddress(hMod, "CeRegQueryValueEx");
  194. _Assert (pfn != NULL); //there is no good reason that this fn wd not be there, it probably means a bug in late binding
  195. if (pfn != NULL)
  196. {
  197. return (*pfn)(hKey, lpValueName, lpReserved, lpType, lpData, lpcbData);
  198. }
  199. }
  200. return WIN_ERR_NO_ACTIVE_SYNC;
  201. }
  202. LONG CeRegCloseKey( HKEY hKey )
  203. {
  204. HMODULE hMod = LoadLibrary (RAPILIBNAME);
  205. if (hMod != NULL)
  206. {
  207. typedef LONG (*PFN)( HKEY );
  208. PFN pfn = (PFN) GetProcAddress(hMod, "CeRegCloseKey");
  209. _Assert (pfn != NULL); //there is no reason that this fn wd not be there, it probably means a bug in late binding
  210. if (pfn != NULL)
  211. {
  212. return (*pfn)(hKey);
  213. }
  214. }
  215. return WIN_ERR_NO_ACTIVE_SYNC;
  216. }
  217. HRESULT CeRapiUninit(void)
  218. {
  219. HMODULE hMod = LoadLibrary (RAPILIBNAME);
  220. if (hMod != NULL)
  221. {
  222. typedef HRESULT (*PFN)();
  223. PFN pfn = (PFN) GetProcAddress(hMod, "CeRapiUninit");
  224. _Assert (pfn != NULL); //there is no good reason that this fn wd not be there, it probably means a bug in late binding
  225. if (pfn != NULL)
  226. {
  227. return (*pfn)();
  228. }
  229. }
  230. return E_NoActiveSync;
  231. }
  232. BOOL CeRemoveDirectory(LPCWSTR lpPathName)
  233. {
  234. HMODULE hMod = LoadLibrary (RAPILIBNAME);
  235. if (hMod != NULL)
  236. {
  237. typedef BOOL (*PFN)(LPCWSTR);
  238. PFN pfn = (PFN) GetProcAddress(hMod, "CeRemoveDirectory");
  239. _Assert (pfn != NULL); //there is no good reason that this fn wd not be there, it probably means a bug in late binding
  240. if (pfn != NULL)
  241. {
  242. return (*pfn)(lpPathName);
  243. }
  244. }
  245. return FALSE;
  246. }
  247. BOOL CeMoveFile(LPCWSTR lpExistingFileName, LPCWSTR lpNewFileName)
  248. {
  249. HMODULE hMod = LoadLibrary (RAPILIBNAME);
  250. if (hMod != NULL)
  251. {
  252. typedef BOOL (*PFN)(LPCWSTR, LPCWSTR);
  253. PFN pfn = (PFN) GetProcAddress(hMod, "CeMoveFile");
  254. _Assert (pfn != NULL); //there is no good reason that this fn wd not be there, it probably means a bug in late binding
  255. if (pfn != NULL)
  256. {
  257. return (*pfn)(lpExistingFileName, lpNewFileName);
  258. }
  259. }
  260. return FALSE;
  261. }
  262. DWORD CeSetFilePointer( HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod )
  263. {
  264. HMODULE hMod = LoadLibrary (RAPILIBNAME);
  265. if (hMod != NULL)
  266. {
  267. typedef DWORD (*PFN)( HANDLE, LONG, PLONG , DWORD );
  268. PFN pfn = (PFN) GetProcAddress(hMod, "CeSetFilePointer");
  269. _Assert (pfn != NULL); //there is no good reason that this fn wd not be there, it probably means a bug in late binding
  270. if (pfn != NULL)
  271. {
  272. return (*pfn)(hFile, lDistanceToMove, lpDistanceToMoveHigh, dwMoveMethod);
  273. }
  274. }
  275. //dll not found, fail over
  276. if (NULL != lpDistanceToMoveHigh)
  277. {
  278. *lpDistanceToMoveHigh = NULL;
  279. }
  280. return -1;
  281. }
  282. BOOL CeDeleteFile(LPCWSTR lpFileName)
  283. {
  284. HMODULE hMod = LoadLibrary (RAPILIBNAME);
  285. if (hMod != NULL)
  286. {
  287. typedef BOOL (*PFN)( LPCWSTR );
  288. PFN pfn = (PFN) GetProcAddress(hMod, "CeDeleteFile");
  289. _Assert (pfn != NULL); //there is no good reason that this fn wd not be there, it probably means a bug in late binding
  290. if (pfn != NULL)
  291. {
  292. return (*pfn)(lpFileName);
  293. }
  294. }
  295. return FALSE;
  296. }
  297. BOOL CeWriteFile( HANDLE hFile, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite, LPDWORD lpNumberOfBytesWritten,
  298. LPOVERLAPPED lpOverlapped )
  299. {
  300. HMODULE hMod = LoadLibrary (RAPILIBNAME);
  301. if (hMod != NULL)
  302. {
  303. typedef BOOL (*PFN)( HANDLE , LPCVOID , DWORD , LPDWORD , LPOVERLAPPED );
  304. PFN pfn = (PFN) GetProcAddress(hMod, "CeWriteFile");
  305. _Assert (pfn != NULL); //there is no good reason that this fn wd not be there, it probably means a bug in late binding
  306. if (pfn != NULL)
  307. {
  308. return (*pfn)(hFile, lpBuffer, nNumberOfBytesToWrite, lpNumberOfBytesWritten, lpOverlapped);
  309. }
  310. }
  311. return FALSE;
  312. }
  313. BOOL CeReadFile( HANDLE hFile, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, LPDWORD lpNumberOfBytesRead,
  314. LPOVERLAPPED lpOverlapped )
  315. {
  316. HMODULE hMod = LoadLibrary (RAPILIBNAME);
  317. if (hMod != NULL)
  318. {
  319. typedef BOOL (*PFN)( HANDLE , LPVOID , DWORD , LPDWORD , LPOVERLAPPED );
  320. PFN pfn = (PFN) GetProcAddress(hMod, "CeReadFile");
  321. _Assert (pfn != NULL); //there is no good reason that this fn wd not be there, it probably means a bug in late binding
  322. if (pfn != NULL)
  323. {
  324. return (*pfn)(hFile, lpBuffer, nNumberOfBytesToRead, lpNumberOfBytesRead, lpOverlapped);
  325. }
  326. }
  327. return FALSE;
  328. }
  329. DWORD CeGetFileAttributes(LPCWSTR lpFileName)
  330. {
  331. HMODULE hMod = LoadLibrary (RAPILIBNAME);
  332. if (hMod != NULL)
  333. {
  334. typedef DWORD (*PFN)( LPCWSTR );
  335. PFN pfn = (PFN) GetProcAddress(hMod, "CeGetFileAttributes");
  336. _Assert (pfn != NULL); //there is no good reason that this fn wd not be there, it probably means a bug in late binding
  337. if (pfn != NULL)
  338. {
  339. return (*pfn)(lpFileName);
  340. }
  341. }
  342. return -1;
  343. }
  344. BOOL CeSHGetShortcutTarget(LPWSTR lpszShortcut, LPWSTR lpszTarget, int cbMax)
  345. {
  346. HMODULE hMod = LoadLibrary (RAPILIBNAME);
  347. if (hMod != NULL)
  348. {
  349. typedef BOOL (*PFN)( LPWSTR , LPWSTR , int );
  350. PFN pfn = (PFN) GetProcAddress(hMod, "CeSHGetShortcutTarget");
  351. _Assert (pfn != NULL); //there is no good reason that this fn wd not be there, it probably means a bug in late binding
  352. if (pfn != NULL)
  353. {
  354. return (*pfn)(lpszShortcut, lpszTarget, cbMax);
  355. }
  356. }
  357. return FALSE;
  358. }
  359. BOOL CeCreateProcess(LPCWSTR lpApplicationName, LPCWSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, LPSECURITY_ATTRIBUTES lpThreadAttributes,
  360. BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, LPWSTR lpCurrentDirectory, LPSTARTUPINFO lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation)
  361. {
  362. HMODULE hMod = LoadLibrary (RAPILIBNAME);
  363. if (hMod != NULL)
  364. {
  365. typedef BOOL (*PFN)(LPCWSTR , LPCWSTR , LPSECURITY_ATTRIBUTES , LPSECURITY_ATTRIBUTES ,
  366. BOOL , DWORD , LPVOID , LPWSTR , LPSTARTUPINFO , LPPROCESS_INFORMATION );
  367. PFN pfn = (PFN) GetProcAddress(hMod, "CeCreateProcess");
  368. _Assert (pfn != NULL); //there is no good reason that this fn wd not be there, it probably means a bug in late binding
  369. if (pfn != NULL)
  370. {
  371. return (*pfn)(lpApplicationName, lpCommandLine, lpProcessAttributes, lpThreadAttributes, bInheritHandles, dwCreationFlags, lpEnvironment,
  372. lpCurrentDirectory, lpStartupInfo, lpProcessInformation);
  373. }
  374. }
  375. return FALSE;
  376. }
  377. HANDLE CeCreateFile(LPCWSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile)
  378. {
  379. HMODULE hMod = LoadLibrary (RAPILIBNAME);
  380. if (hMod != NULL)
  381. {
  382. typedef HANDLE (*PFN)(LPCWSTR , DWORD , DWORD , LPSECURITY_ATTRIBUTES , DWORD , DWORD , HANDLE );
  383. PFN pfn = (PFN) GetProcAddress(hMod, "CeCreateFile");
  384. _Assert (pfn != NULL); //there is no good reason that this fn wd not be there, it probably means a bug in late binding
  385. if (pfn != NULL)
  386. {
  387. return (*pfn)(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
  388. }
  389. }
  390. return INVALID_HANDLE_VALUE;
  391. }
  392. HANDLE CeFindFirstFile(LPCWSTR lpFileName, LPCE_FIND_DATA lpFindFileData)
  393. {
  394. HMODULE hMod = LoadLibrary (RAPILIBNAME);
  395. if (hMod != NULL)
  396. {
  397. typedef HANDLE (*PFN)(LPCWSTR , LPCE_FIND_DATA );
  398. PFN pfn = (PFN) GetProcAddress(hMod, "CeFindFirstFile");
  399. _Assert (pfn != NULL); //there is no good reason that this fn wd not be there, it probably means a bug in late binding
  400. if (pfn != NULL)
  401. {
  402. return (*pfn)(lpFileName, lpFindFileData);
  403. }
  404. }
  405. return INVALID_HANDLE_VALUE;
  406. }
  407. BOOL CeGetVersionEx(LPCEOSVERSIONINFO lpVersionInformation)
  408. {
  409. HMODULE hMod = LoadLibrary (RAPILIBNAME);
  410. if (hMod != NULL)
  411. {
  412. typedef BOOL (*PFN)(LPCEOSVERSIONINFO);
  413. PFN pfn = (PFN) GetProcAddress(hMod, "CeGetVersionEx");
  414. _Assert (pfn != NULL); //there is no good reason that this fn wd not be there, it probably means a bug in late binding
  415. if (pfn != NULL)
  416. {
  417. return (*pfn)(lpVersionInformation);
  418. }
  419. }
  420. return FALSE;
  421. }
  422. BOOL CeFindClose( HANDLE hFindFile )
  423. {
  424. HMODULE hMod = LoadLibrary (RAPILIBNAME);
  425. if (hMod != NULL)
  426. {
  427. typedef BOOL (*PFN)(HANDLE);
  428. PFN pfn = (PFN) GetProcAddress(hMod, "CeFindClose");
  429. _Assert (pfn != NULL); //there is no good reason that this fn wd not be there, it probably means a bug in late binding
  430. if (pfn != NULL)
  431. {
  432. return (*pfn)(hFindFile);
  433. }
  434. }
  435. return FALSE;
  436. }