Source code of Windows XP (NT5)
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.

334 lines
9.6 KiB

  1. /*++
  2. * File name:
  3. * clxtshar.h
  4. * Contents:
  5. * Header file for clxtshar.dll
  6. *
  7. * Copyright (C) 1998-1999 Microsoft Corp.
  8. --*/
  9. #ifndef _CLXTSHAR_H
  10. #define _CLXTSHAR_H
  11. #ifdef OS_WIN16
  12. #include <ctype.h>
  13. #include <tchar.h>
  14. #define UINT_PTR UINT
  15. #define LONG_PTR LONG
  16. #define TEXT(_s_) _s_
  17. #define LPCTSTR LPCSTR
  18. #define TCHAR char
  19. #define CHAR char
  20. #define INT int
  21. #define LOADDS __loadds
  22. //#define EXPORT __export LOADDS __far
  23. //#define CLXAPI
  24. #define HUGEMOD __huge
  25. #define HUGEMEMCPY hmemcpy
  26. #define MAKEWORD(_hi, _lo) ((((WORD)((_hi) & 0xFF)) << 8)|((_lo) & 0xFF))
  27. #define BST_UNCHECKED 0x0000
  28. #define BST_CHECKED 0x0001
  29. #define BST_INDETERMINATE 0x0002
  30. #define BST_PUSHED 0x0004
  31. #define BST_FOCUS 0x0008
  32. #endif // OS_WIN16
  33. #ifdef OS_WIN32
  34. //#define EXPORT
  35. #define LOADDS
  36. //#define CLXAPI __declspec(dllexport)
  37. #define HUGEMOD
  38. #define HUGEMEMCPY memcpy
  39. #endif // OS_WIN32
  40. #ifdef UNICODE
  41. #define _CLX_strstr(s1, s2) wcsstr(s1, s2)
  42. #define _CLX_strchr(s, c) wcschr(s, c)
  43. #define _CLX_strlen(s) wcslen(s)
  44. #define _CLX_strcpy(s1, s2) wcscpy(s1, s2)
  45. #define _CLX_strncpy(s1, s2, n) wcsncpy(s1, s2, n)
  46. #define _CLX_atol(s) _wtol(s)
  47. #define _CLX_vsnprintf(s, n, f, a) _vsnwprintf(s, n, f, a)
  48. #define _CLX_strcmp(s1, s2) wcscmp(s1, s2)
  49. BOOL _CLX_SetDlgItemTextA(HWND hDlg, INT nDlgItem, LPCSTR lpString);
  50. #else // !UNICODE
  51. #define _CLX_strstr(s1, s2) strstr(s1, s2)
  52. #define _CLX_strchr(s, c) strchr(s, c)
  53. #define _CLX_strlen(s) strlen(s)
  54. #define _CLX_strcpy(s1, s2) strcpy(s1, s2)
  55. #define _CLX_strncpy(s1, s2, n) strncpy(s1, s2, n)
  56. #define _CLX_atol(s) atol(s)
  57. #define _CLX_vsnprintf(s, n, f, a) _vsnprintf(s, n, f, a)
  58. #define _CLX_strcmp(s1, s2) strcmp(s1, s2)
  59. #endif
  60. #ifndef OS_WINCE
  61. #define _CLXALLOC(_size_) GlobalAllocPtr(GMEM_FIXED, _size_)
  62. #define _CLXFREE(_ptr_) GlobalFreePtr(_ptr_)
  63. #define _CLXREALLOC(_ptr_, _size_) GlobalReAllocPtr(_ptr_, _size_, 0)
  64. typedef HINSTANCE _CLXWINDOWOWNER;
  65. // Windows are identified by
  66. // hInstance
  67. #else // OS_WINCE
  68. #define _CLXALLOC(_size_) LocalAlloc(LMEM_FIXED, _size_)
  69. #define _CLXFREE(_ptr_) LocalFree(_ptr_)
  70. #define _CLXREALLOC(_ptr_, _size_) LocalReAlloc(_ptr_, _size_, 0)
  71. typedef DWORD _CLXWINDOWOWNER;
  72. // Identified by process Id
  73. #define WSAGETSELECTERROR(lParam) HIWORD(lParam)
  74. #define WSAGETSELECTEVENT(lParam) LOWORD(lParam)
  75. BOOL _StartAsyncThread(VOID);
  76. VOID _CloseAsyncThread(VOID);
  77. INT WSAAsyncSelect(SOCKET s, HWND hWnd, UINT uiMsg, LONG lEvent);
  78. INT AsyncRecv(SOCKET s, PVOID pBuffer, INT nBytesToRead, INT *pnErrorCode);
  79. BOOL
  80. CheckDlgButton(
  81. HWND hDlg,
  82. INT nIDButton,
  83. UINT uCheck);
  84. #define isalpha(c) ((c >= 'A' && c <= 'Z') ||\
  85. (c >= 'a' && c <= 'z'))
  86. #endif // OS_WINCE
  87. #include <clxapi.h>
  88. #include <wuiids.h>
  89. #include "..\lib\feedback.h"
  90. #include "..\lib\clntdata.h"
  91. #include "clxexport.h"
  92. // Context structure
  93. typedef struct _CLXINFO {
  94. HWND hwndMain; // Clients main window
  95. HDC hdcShadowBitmap; // Client's shadow bitmap
  96. HBITMAP hShadowBitmap; // -- " --
  97. // members used in local mode
  98. HWND hwndSMC; // SmClient window handle
  99. #ifdef OS_WIN32
  100. #ifndef OS_WINCE
  101. HANDLE hMapF; // Map file for passing data to smclient
  102. UINT nMapSize; // Currently allocated map file
  103. DWORD dwProcessId; // Our process ID
  104. #endif // !OS_WINCE
  105. #endif // OS_WIN32
  106. // Used in RCLX mode WIN16/WIN32
  107. HWND hwndInput; // client input window
  108. BOOL alive; // TRUE if client is connected to Hydra server
  109. SOCKET hSocket; // Used only in RCLX mode
  110. struct sockaddr_in sinTestSrv;
  111. // cached address of TestServer
  112. HWND hwndDialog; // RDP client's dialog
  113. RCLXCONNECTINFO RClxInfo; // Connection info
  114. UINT_PTR uiReconnectTimer; // Timer for reconnect retrys
  115. // Receiving messages
  116. BOOL bPrologReceived;
  117. UINT32 nBytesReceived;
  118. RCLXREQPROLOG RClxReqProlog;
  119. BYTE *pRequest;
  120. UINT32 nReqAllocSize;
  121. BOOL bClientInfoSent;
  122. BOOL bCloseTrys;
  123. LONG bClipboardReenter;
  124. #ifndef OS_WINCE
  125. #ifdef OS_WIN32
  126. BOOL bSendMsgThreadExit; // Used by _ClxSendMessage
  127. HANDLE semSendReady;
  128. HANDLE semSendCompleted;
  129. HANDLE semSendDone;
  130. HANDLE hSendMsgThread;
  131. MSG msg;
  132. #endif // OS_WIN32
  133. #endif // !OS_WINCE
  134. } CLXINFO, *PCLXINFO;
  135. /*
  136. * Clipboard help functions (clputil.c)
  137. */
  138. VOID
  139. Clp_GetClipboardData(
  140. UINT format,
  141. HGLOBAL hClipData,
  142. UINT32 *pnClipDataSize,
  143. HGLOBAL *phNewData);
  144. BOOL
  145. Clp_SetClipboardData(
  146. UINT formatID,
  147. HGLOBAL hClipData,
  148. UINT32 nClipDataSize,
  149. BOOL *pbFreeHandle);
  150. /*
  151. * Internal functions definitions
  152. */
  153. BOOL RClx_Connect(PCLXINFO pClx);
  154. VOID RClx_Disconnect(PCLXINFO pClx);
  155. BOOL RClx_SendBuffer(SOCKET hSocket, PVOID pBuffer, DWORD nSize);
  156. BOOL RClx_SendEvent(PCLXINFO pClx, CLXEVENT Event, DWORD dwParam);
  157. BOOL
  158. RClx_SendClipboard(
  159. PCLXINFO pClx,
  160. UINT uiFormat,
  161. UINT32 nSize,
  162. VOID HUGEMOD *pClipboard);
  163. BOOL
  164. RClx_SendTextOut(
  165. PCLXINFO pClx,
  166. PVOID pText,
  167. INT textLength);
  168. BOOL RClx_SendBitmap(
  169. PCLXINFO pClx,
  170. UINT cxSize,
  171. UINT cySize,
  172. PVOID pBuffer,
  173. UINT nBmiSize,
  174. PVOID pBmi);
  175. VOID RClx_CreateWindow(HINSTANCE hInstance);
  176. VOID RClx_DestroyWindow(VOID);
  177. BOOL RClx_ReadRequest(PCLXINFO pClx);
  178. VOID RClx_ProcessRequest(PCLXINFO pClx);
  179. VOID _StripGlyph(LPBYTE pData, UINT *pxSize, UINT ySize);
  180. HWND _ParseCmdLine(LPCTSTR szCmdLine);
  181. VOID
  182. CLXAPI
  183. ClxEvent(PCLXINFO pClx, CLXEVENT Event, ULONG uResult);
  184. HWND _FindTopWindow(LPCTSTR, LPCTSTR, _CLXWINDOWOWNER);
  185. #ifndef OS_WINCE
  186. HWND _FindSMCWindow(PCLXINFO);
  187. HWND _CheckWindow();
  188. #endif // !OS_WINCE
  189. #ifdef OS_WIN32
  190. #ifndef OS_WINCE
  191. #define CLX_ONE_PAGE 4096 // Map-file alignment
  192. BOOL _OpenMapFile(PCLXINFO pClx, UINT nSize);
  193. BOOL _ReOpenMapFile(PCLXINFO pClx, UINT newSize);
  194. BOOL _SaveInMapFile(HANDLE hMapF,
  195. LPVOID *str,
  196. INT strsize,
  197. DWORD dwProcessId);
  198. BOOL _CheckRegistrySettings(VOID);
  199. #endif // !OS_WINCE
  200. #endif // OS_WIN32
  201. #ifdef OS_WIN16
  202. BOOL _CheckIniSettings(VOID);
  203. __inline INT GetLastError(VOID) { return -1; }
  204. #endif // OS_WIN16
  205. VOID _GetIniSettings(VOID);
  206. VOID __cdecl LocalPrintMessage(INT errlevel, LPCTSTR format, ...);
  207. VOID _ClxAssert( LPCTSTR filename, INT line);
  208. HWND _FindWindow(HWND hwndParent, LPCTSTR srchclass);
  209. VOID _SetClipboard(UINT uiFormat, PVOID pClipboard, UINT32 nSize);
  210. VOID _OnBackground(PCLXINFO);
  211. BOOL _GarbageCollecting(PCLXINFO, BOOL bNotifiyForErrorBox);
  212. BOOL
  213. WS_Init(VOID);
  214. VOID
  215. _AttemptToCloseTheClient(VOID);
  216. VOID
  217. _GetDIBFromBitmap(
  218. HDC hdcMemSrc,
  219. HBITMAP hBitmap,
  220. HANDLE *phDIB,
  221. INT left,
  222. INT top,
  223. INT right,
  224. INT bottom);
  225. DWORD
  226. _ClxSendMsgThread(VOID *param);
  227. LRESULT
  228. _ClxSendMessage(
  229. HWND hWnd,
  230. UINT Msg,
  231. WPARAM wParam,
  232. LPARAM lParam
  233. );
  234. VOID
  235. _ClxDestroySendMsgThread(PCLXINFO pClx);
  236. DWORD
  237. _CLXSendDataVC(
  238. LPCSTR szChannelName,
  239. LPVOID pData,
  240. DWORD dwSize
  241. );
  242. // This structure is used by _FindTopWindow
  243. typedef struct _SEARCHWND {
  244. LPCTSTR szClassName; // The class name of searched window,
  245. // NULL - ignore
  246. LPCTSTR szCaption; // Window caption, NULL - ignore
  247. _CLXWINDOWOWNER hInstance;
  248. // instance of the owner, NULL - ignore
  249. HWND hWnd; // Found window handle
  250. } SEARCHWND, *PSEARCHWND;
  251. enum {ERROR_MESSAGE = 0, WARNING_MESSAGE, INFO_MESSAGE, ALIVE_MESSAGE};
  252. typedef struct _CLXVCHANNEL {
  253. CHAR szName[MAX_VCNAME_LEN];
  254. PCLXVC_SENDDATA pSendDataFn;
  255. struct _CLXVCHANNEL *pNext;
  256. } CLXVCHANNEL, *PCLXVCHANNEL;
  257. #ifndef SD_RECEIVE
  258. #define SD_RECEIVE 0x00
  259. #define SD_SEND 0x01
  260. #define SD_BOTH 0x02
  261. #endif // SD_RECEIVE
  262. #define _CLXWINDOW_CLASS "CLXTSHARClass"
  263. #define RCLX_RECONNECT_TIMERID 11000
  264. #define RCLX_BACKGNDTIMERID 11001
  265. #define RCLX_TIMERELAPSETIME 15000 // 15 seconds between retrys
  266. #define RCLX_RECONNECTELAPSETIME 5000
  267. PCLXINFO g_pClx = NULL;
  268. PCLXVCHANNEL g_pVChannels = NULL;
  269. // Used in RCLX mode
  270. CHAR g_szTestServer[_MAX_PATH] = "";
  271. u_short g_nPort = RCLX_DEFAULT_PORT;
  272. // Read this from cmdline
  273. HWND g_hWindow = NULL; // Window for receving winsock messages
  274. HINSTANCE g_hInstance = NULL; // Dll instance
  275. UINT32 g_nMyReconId = 0; // RCLX recon mode, contains ID to reconnect
  276. _CLXWINDOWOWNER g_hRDPInst; // instance of RDP client
  277. UINT_PTR g_uiBackgroundTimer = 0;// Background processing timer
  278. INT g_VerboseLevel = 1; // default verbose level: only errors
  279. INT g_GlyphEnable = 0;
  280. // UI texts, captions and so
  281. TCHAR g_strClientCaption[_MAX_PATH];
  282. TCHAR g_strDisconnectDialogBox[_MAX_PATH];
  283. TCHAR g_strYesNoShutdown[_MAX_PATH];
  284. // BitMask is used by _StripGlyph
  285. const BYTE BitMask[] = {0x0, 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xFE, 0xFF};
  286. #define IS_RCLX (g_szTestServer[0])
  287. #define TRACE(_x_) LocalPrintMessage _x_
  288. #ifndef OS_WINCE
  289. #define ASSERT(_x_) if (!(_x_)) _ClxAssert( __FILE__, __LINE__)
  290. #endif
  291. #endif // !_CLXTSHAR_H