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.

678 lines
17 KiB

  1. /**MOD+**********************************************************************/
  2. /* Module: Clxapi.cpp */
  3. /* */
  4. /* Purpose: Clx API functions */
  5. /* */
  6. /* Copyright(C) Microsoft Corporation 1997-1999 */
  7. /* */
  8. /****************************************************************************/
  9. #include <adcg.h>
  10. extern "C" {
  11. #define TRC_GROUP TRC_GROUP_CORE
  12. #define TRC_FILE "clxapi"
  13. #include <atrcapi.h>
  14. #include <tchar.h>
  15. #include <windowsx.h>
  16. }
  17. #include "autil.h"
  18. #include "clx.h"
  19. #include "nl.h"
  20. #include "sl.h"
  21. CCLX::CCLX(CObjs* objs)
  22. {
  23. _pClientObjects = objs;
  24. _pClx = NULL;
  25. }
  26. CCLX::~CCLX()
  27. {
  28. }
  29. //*************************************************************
  30. //
  31. // CLX_Alloc()
  32. //
  33. // Purpose: Allocates memory
  34. //
  35. // Parameters: IN [dwSize] - Size to allocate
  36. //
  37. // Return: Ptr to memory block - if successful
  38. // NULL - if unsuccessful
  39. //
  40. // History: 09-30-97 BrianTa Created
  41. //
  42. //*************************************************************
  43. PVOID
  44. CCLX::CLX_Alloc(IN DWORD dwSize)
  45. {
  46. #ifndef OS_WINCE
  47. return (GlobalAllocPtr(GMEM_MOVEABLE, dwSize));
  48. #else // OS_WINCE
  49. return LocalAlloc(LMEM_FIXED, dwSize);
  50. #endif
  51. }
  52. //*************************************************************
  53. //
  54. // CLX_Free()
  55. //
  56. // Purpose: Frees previously alloc'ed memory
  57. //
  58. // Parameters: IN [lpMemory] - Ptr to memory to free
  59. //
  60. // Return: void
  61. //
  62. // History: 09-30-97 BrianTa Created
  63. //
  64. //*************************************************************
  65. VOID
  66. CCLX::CLX_Free(IN PVOID lpMemory)
  67. {
  68. #ifndef OS_WINCE
  69. GlobalFreePtr(lpMemory);
  70. #else
  71. LocalFree(lpMemory);
  72. #endif
  73. }
  74. //*************************************************************
  75. //
  76. // CLX_SkipWhite()
  77. //
  78. // Purpose: Skips whitespace characters
  79. //
  80. // Parameters: IN [lpszCmdParam] - Ptr to string
  81. //
  82. // Return: Ptr string past whitespace
  83. //
  84. // History: 09-30-97 BrianTa Created
  85. //
  86. //*************************************************************
  87. LPTSTR
  88. CCLX::CLX_SkipWhite(IN LPTSTR lpszCmdParam)
  89. {
  90. while (*lpszCmdParam)
  91. {
  92. if (*lpszCmdParam != ' ')
  93. break;
  94. lpszCmdParam++;
  95. }
  96. return (lpszCmdParam);
  97. }
  98. //*************************************************************
  99. //
  100. // CLX_GetClx()
  101. //
  102. // Purpose: Returns PER INSTANCE pClx pointer
  103. //
  104. // Parameters: void
  105. //
  106. // Return: Ptr to per instance pClx - If successfull
  107. // NULL - if not
  108. //
  109. // History: 09-30-97 BrianTa Created
  110. //
  111. //*************************************************************
  112. PCLEXTENSION
  113. CCLX::CLX_GetClx(VOID)
  114. {
  115. if (_pClx == NULL)
  116. {
  117. _pClx = (PCLEXTENSION) CLX_Alloc(sizeof(CLEXTENSION));
  118. if (_pClx)
  119. memset(_pClx, 0, sizeof(CLEXTENSION));
  120. }
  121. return (_pClx);
  122. }
  123. //*************************************************************
  124. //
  125. // CLX_LoadProcs()
  126. //
  127. // Purpose: Loads proc addresses from clxdll
  128. //
  129. // Parameters: void
  130. //
  131. // Return: TRUE - if successfull
  132. // FALSE - if not
  133. //
  134. // History: 09-30-97 BrianTa Created
  135. //
  136. //*************************************************************
  137. BOOL
  138. CCLX::CLX_LoadProcs(void)
  139. {
  140. DC_BEGIN_FN("CLX_LoadProcs");
  141. _pClx->pClxInitialize = (PCLX_INITIALIZE)
  142. GetProcAddress(_pClx->hInstance, CLX_INITIALIZE);
  143. if (!_pClx->pClxInitialize)
  144. {
  145. TRC_ERR((TB,_T("CLX_Init() Could not find pClxInitialize entry point\n")));
  146. }
  147. _pClx->pClxConnect = (PCLX_CONNECT)
  148. GetProcAddress(_pClx->hInstance, CLX_CONNECT);
  149. if (!_pClx->pClxConnect)
  150. {
  151. TRC_ERR((TB,_T("CLX_Init() Could not find pClxConnect entry point\n")));
  152. }
  153. _pClx->pClxEvent = (PCLX_EVENT)
  154. GetProcAddress(_pClx->hInstance, CLX_EVENT);
  155. if (!_pClx->pClxEvent)
  156. {
  157. TRC_ERR((TB,_T("CLX_Init() Could not find pClxEvent entry point\n")));
  158. }
  159. _pClx->pClxDisconnect = (PCLX_DISCONNECT)
  160. GetProcAddress(_pClx->hInstance, CLX_DISCONNECT);
  161. if (!_pClx->pClxDisconnect)
  162. {
  163. TRC_ERR((TB,_T("CLX_Init() Could not find pClxDisconnect entry point\n")));
  164. }
  165. _pClx->pClxTerminate = (PCLX_TERMINATE)
  166. GetProcAddress(_pClx->hInstance, CLX_TERMINATE);
  167. if (!_pClx->pClxTerminate)
  168. {
  169. TRC_ERR((TB,_T("CLX_Init() Could not find pClxTerminate entry point\n")));
  170. }
  171. _pClx->pClxTextOut = (PCLX_TEXTOUT)
  172. GetProcAddress(_pClx->hInstance, CLX_TEXTOUT);
  173. if (!_pClx->pClxTextOut)
  174. {
  175. TRC_ERR((TB,_T("CLX_Init() Could not find pClxTextOut entry point\n")));
  176. }
  177. _pClx->pClxTextPosOut = (PCLX_TEXTPOSOUT)
  178. GetProcAddress(_pClx->hInstance, CLX_TEXTPOSOUT);
  179. if (!_pClx->pClxTextPosOut)
  180. {
  181. TRC_ERR((TB,_T("CLX_Init() Could not find pClxTextPosOut entry point\n")));
  182. }
  183. _pClx->pClxOffscrOut = (PCLX_OFFSCROUT)
  184. GetProcAddress(_pClx->hInstance, CLX_OFFSCROUT);
  185. if (!_pClx->pClxOffscrOut)
  186. {
  187. TRC_ERR((TB,_T("CLX_Init() Could not find pClxOffscrOut entry point\n")));
  188. }
  189. _pClx->pClxGlyphOut = (PCLX_GLYPHOUT)
  190. GetProcAddress(_pClx->hInstance, CLX_GLYPHOUT);
  191. if (!_pClx->pClxGlyphOut)
  192. {
  193. TRC_ERR((TB,_T("CLX_Init() Could not find pClxGlyphOut entry point\n")));
  194. }
  195. _pClx->pClxBitmap = (PCLX_BITMAP)
  196. GetProcAddress(_pClx->hInstance, CLX_BITMAP);
  197. if (!_pClx->pClxGlyphOut)
  198. {
  199. TRC_ERR((TB,_T("CLX_Init() Could not find pClxBitmap entry point\n")));
  200. }
  201. _pClx->pClxDialog = (PCLX_DIALOG)
  202. GetProcAddress(_pClx->hInstance, CLX_DIALOG);
  203. if (!_pClx->pClxDialog)
  204. {
  205. TRC_ERR((TB,_T("CLX_Init() Could not find pClxDialog entry point\n")));
  206. }
  207. _pClx->pClxPktDrawn = (PCLX_PKTDRAWN)
  208. GetProcAddress(_pClx->hInstance, CLX_PKTDRAWN);
  209. if (!_pClx->pClxPktDrawn)
  210. {
  211. TRC_ERR((TB,_T("CLX_Init() Could not find pClxPktDrawn entry point\n")));
  212. }
  213. _pClx->pClxRedirectNotify = (PCLX_REDIRECTNOTIFY)
  214. GetProcAddress(_pClx->hInstance, CLX_REDIRECTNOTIFY);
  215. if (!_pClx->pClxRedirectNotify)
  216. {
  217. TRC_ERR((TB,_T("CLX_Init() Could not find pClxRedirectNotify entry point\n")));
  218. }
  219. _pClx->pClxConnectEx = (PCLX_CONNECT_EX)
  220. GetProcAddress(_pClx->hInstance, CLX_CONNECT_EX);
  221. if (!_pClx->pClxConnectEx)
  222. {
  223. TRC_ERR((TB,_T("CLX_Init() Could not find pClxConnectEx entry point\n")));
  224. }
  225. DC_END_FN();
  226. return (_pClx->pClxInitialize && _pClx->pClxTerminate);
  227. }
  228. //*************************************************************
  229. //
  230. // CLX_ClxLoaded()
  231. //
  232. // Purpose: Returns clx load status
  233. //
  234. // Parameters: void
  235. //
  236. // Return: TRUE - if loaded
  237. // FALSE - if not
  238. //
  239. // History: 09-30-97 BrianTa Created
  240. //
  241. //*************************************************************
  242. BOOL
  243. CCLX::CLX_Loaded(void)
  244. {
  245. return (_pClx ? TRUE : FALSE);
  246. }
  247. //*************************************************************
  248. //
  249. // CLX_Init()
  250. //
  251. // Purpose: Loads / initializes the clx dll
  252. //
  253. // Parameters: IN [hwndMain] - Main client window handle
  254. //
  255. // Return: TRUE - if successfull
  256. // FALSE - if not
  257. //
  258. // History: 09-30-97 BrianTa Created
  259. //
  260. //*************************************************************
  261. #define CLX_DLL_NAME _T("clxtshar.dll")
  262. BOOL
  263. CCLX::CLX_Init(HWND hwndMain, LPTSTR szCmdLine)
  264. {
  265. DC_BEGIN_FN("CLX_Init");
  266. BOOL fLoaded;
  267. CLINFO clinfo;
  268. HINSTANCE hInstance;
  269. LPTSTR pszClxDll;
  270. fLoaded = FALSE;
  271. hInstance = NULL;
  272. _pClientObjects->AddObjReference(CLX_OBJECT_FLAG);
  273. if(!szCmdLine || _T('\0') == szCmdLine[0])
  274. {
  275. TRC_ALT((TB,_T("CLX_Init() NO CLX CMD Line Specified. Not loading CLX - %s\n"),
  276. CLX_DLL_NAME));
  277. return FALSE;
  278. }
  279. _pClx = CLX_GetClx();
  280. if (_pClx)
  281. {
  282. TRC_NRM((TB,_T("CLX_Init() attempting to load (%s)\n"), CLX_DLL_NAME));
  283. hInstance = LoadLibrary(CLX_DLL_NAME);
  284. if (hInstance)
  285. {
  286. _pClx->hInstance = hInstance;
  287. if (CLX_LoadProcs())
  288. {
  289. clinfo.cbSize = sizeof(clinfo);
  290. clinfo.dwVersion = CLINFO_VERSION;
  291. #ifdef UNICODE
  292. if(_pClx->pszClxServer)
  293. {
  294. if (!WideCharToMultiByte(CP_ACP,
  295. 0,
  296. _pClx->pszClxServer,
  297. -1,
  298. _szAnsiClxServer,
  299. sizeof(_szAnsiClxServer),
  300. NULL,
  301. NULL))
  302. {
  303. //Conv failed
  304. TRC_ERR((TB, _T("Failed to convert pszClxServer to ANSI: 0x%x"),
  305. GetLastError()));
  306. return FALSE;
  307. }
  308. clinfo.pszServer = _szAnsiClxServer;
  309. }
  310. else
  311. {
  312. clinfo.pszServer = NULL;
  313. }
  314. if(szCmdLine)
  315. {
  316. if (!WideCharToMultiByte(CP_ACP,
  317. 0,
  318. szCmdLine,
  319. -1,
  320. _szAnsiClxCmdLine,
  321. sizeof(_szAnsiClxCmdLine),
  322. NULL,
  323. NULL))
  324. {
  325. //Conv failed
  326. TRC_ERR((TB, _T("Failed to convert CLX szCmdLine to ANSI: 0x%x"),
  327. GetLastError()));
  328. return FALSE;
  329. }
  330. clinfo.pszCmdLine = _szAnsiClxCmdLine;
  331. }
  332. else
  333. {
  334. clinfo.pszCmdLine = NULL;
  335. }
  336. #else
  337. //Data is already ANSI
  338. clinfo.pszServer = _pClx->pszClxServer;
  339. clinfo.pszCmdLine = szCmdLine;
  340. #endif
  341. clinfo.hwndMain = hwndMain;
  342. fLoaded = _pClx->pClxInitialize(&clinfo, &_pClx->pvClxContext);
  343. TRC_NRM((TB,_T("CLX_Init() pClxInitialize() returned - %d\n"), fLoaded));
  344. }
  345. }
  346. else
  347. {
  348. TRC_NRM((TB,_T("CLX_Init() Error %d loading (%s)\n"),
  349. GetLastError(), CLX_DLL_NAME));
  350. }
  351. // If we were able to load the ClxDll and successfull perform its
  352. // base initialization, then tell it to go ahead and connect to the
  353. // test server
  354. if (fLoaded)
  355. fLoaded = CLX_ClxConnect();
  356. if (!fLoaded)
  357. {
  358. if (hInstance)
  359. FreeLibrary(hInstance);
  360. if (_pClx->pszClxDll)
  361. CLX_Free(_pClx->pszClxDll);
  362. if (_pClx->pszClxServer)
  363. CLX_Free(_pClx->pszClxServer);
  364. CLX_Free(_pClx);
  365. _pClx = NULL;
  366. }
  367. }
  368. DC_END_FN();
  369. return (_pClx != NULL);
  370. }
  371. //*************************************************************
  372. //
  373. // CLX_Term()
  374. //
  375. // Purpose: Sub-manager termination processing
  376. //
  377. // Parameters: void
  378. //
  379. // Return: void
  380. //
  381. // History: 09-30-97 BrianTa Created
  382. //
  383. //*************************************************************
  384. VOID
  385. CCLX::CLX_Term(VOID)
  386. {
  387. if (_pClx)
  388. {
  389. CLX_ClxDisconnect();
  390. CLX_ClxTerminate();
  391. if (_pClx->hInstance)
  392. FreeLibrary(_pClx->hInstance);
  393. if (_pClx->pszClxDll)
  394. CLX_Free(_pClx->pszClxDll);
  395. if (_pClx->pszClxServer)
  396. CLX_Free(_pClx->pszClxServer);
  397. CLX_Free(_pClx);
  398. _pClx = NULL;
  399. }
  400. _pClientObjects->ReleaseObjReference(CLX_OBJECT_FLAG);
  401. }
  402. //*************************************************************
  403. //
  404. // CLX_OnConnected()
  405. //
  406. // Purpose: OnConnected processing for the clx dll
  407. //
  408. // Parameters: void
  409. //
  410. // Return: void
  411. //
  412. // History: 09-30-97 BrianTa Created
  413. //
  414. //*************************************************************
  415. VOID
  416. CCLX::CLX_OnConnected(VOID)
  417. {
  418. CLX_ClxEvent(CLX_EVENT_CONNECT, 0);
  419. }
  420. //*************************************************************
  421. //
  422. // CLX_OnDisconnected()
  423. //
  424. // Purpose: OnDisconnected processing for the clx dll
  425. //
  426. // Parameters: IN [uDisconnect] -- Disconnection code
  427. //
  428. // Return: void
  429. //
  430. // History: 09-30-97 BrianTa Created
  431. //
  432. //*************************************************************
  433. VOID
  434. CCLX::CLX_OnDisconnected(IN UINT uDisconnect)
  435. {
  436. UINT uResult;
  437. switch (NL_GET_MAIN_REASON_CODE(uDisconnect))
  438. {
  439. case NL_DISCONNECT_LOCAL:
  440. uResult = CLX_DISCONNECT_LOCAL;
  441. break;
  442. case NL_DISCONNECT_REMOTE_BY_USER:
  443. uResult = CLX_DISCONNECT_BY_USER;
  444. break;
  445. case NL_DISCONNECT_REMOTE_BY_SERVER:
  446. uResult = CLX_DISCONNECT_BY_SERVER;
  447. break;
  448. case NL_DISCONNECT_ERROR:
  449. uResult = CLX_DISCONNECT_NL_ERROR;
  450. break;
  451. case SL_DISCONNECT_ERROR:
  452. uResult = CLX_DISCONNECT_SL_ERROR;
  453. break;
  454. default:
  455. uResult = CLX_DISCONNECT_UNKNOWN;
  456. break;
  457. }
  458. CLX_ClxEvent(CLX_EVENT_DISCONNECT, uResult);
  459. }
  460. //*************************************************************
  461. //
  462. // CLX_ClxConnect()
  463. //
  464. // Purpose: Connect processing for the clx dll
  465. //
  466. // Parameters: void
  467. //
  468. // Return: void
  469. //
  470. // History: 09-30-97 BrianTa Created
  471. //
  472. //*************************************************************
  473. BOOL
  474. CCLX::CLX_ClxConnect(VOID)
  475. {
  476. BOOL fConnect;
  477. fConnect = TRUE;
  478. if (_pClx && _pClx->pClxConnect)
  479. fConnect = _pClx->pClxConnect(_pClx->pvClxContext, _pClx->pszClxServer);
  480. return (fConnect);
  481. }
  482. //*************************************************************
  483. //
  484. // CLX_ClxEvent()
  485. //
  486. // Purpose: Event processing for the clx dll
  487. //
  488. // Parameters: IN [ClxEvent] - Event type
  489. // IN [ulParam] - Event specific param
  490. //
  491. // Return: void
  492. //
  493. // History: 09-30-97 BrianTa Created
  494. //
  495. //*************************************************************
  496. VOID
  497. CCLX::CLX_ClxEvent(IN CLXEVENT ClxEvent,
  498. IN LPARAM ulParam)
  499. {
  500. if (_pClx && _pClx->pClxEvent)
  501. _pClx->pClxEvent(_pClx->pvClxContext, ClxEvent, ulParam);
  502. }
  503. //*************************************************************
  504. //
  505. // CLX_Disconnect()
  506. //
  507. // Purpose: Disconnect processing for the clx dll
  508. //
  509. // Parameters: void
  510. //
  511. // Return: void
  512. //
  513. // History: 09-30-97 BrianTa Created
  514. //
  515. //*************************************************************
  516. VOID
  517. CCLX::CLX_ClxDisconnect(VOID)
  518. {
  519. if (_pClx && _pClx->pClxDisconnect)
  520. _pClx->pClxDisconnect(_pClx->pvClxContext);
  521. }
  522. //*************************************************************
  523. //
  524. // CLX_ClxTerminate()
  525. //
  526. // Purpose: Termination processing for the clx dll
  527. //
  528. // Parameters: void
  529. //
  530. // Return: void
  531. //
  532. // History: 09-30-97 BrianTa Created
  533. //
  534. //*************************************************************
  535. VOID
  536. CCLX::CLX_ClxTerminate(VOID)
  537. {
  538. if (_pClx && _pClx->pClxTerminate)
  539. _pClx->pClxTerminate(_pClx->pvClxContext);
  540. }
  541. //*************************************************************
  542. //
  543. // CLX_ClxDialog()
  544. //
  545. // Purpose: Let the clx dll know of the launched dialog
  546. //
  547. // Parameters: IN [hwnd] - Dialog hwnd
  548. //
  549. // Return: void
  550. //
  551. // History: 09-30-97 BrianTa Created
  552. //
  553. //*************************************************************
  554. VOID
  555. CCLX::CLX_ClxDialog(HWND hwnd)
  556. {
  557. if (_pClx && _pClx->pClxDialog)
  558. _pClx->pClxDialog(_pClx->pvClxContext, hwnd);
  559. }