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.

444 lines
16 KiB

  1. /****************************** Module Header ******************************\
  2. * Module Name: ddemlcli.h
  3. *
  4. * Copyright (c) 1985 - 1999, Microsoft Corporation
  5. *
  6. * This header file contains stuff used by client side ddeml code.
  7. *
  8. * History:
  9. * 10-28-91 Sanfords Created
  10. \***************************************************************************/
  11. #if DBG
  12. #define DDEMLAlloc(cb) RtlAllocateHeap(gpDDEMLHeap, HEAP_ZERO_MEMORY, (cb))
  13. #define DDEMLReAlloc(p, cb) RtlReAllocateHeap(gpDDEMLHeap, HEAP_ZERO_MEMORY, (p), (cb))
  14. #define DDEMLFree(p) RtlFreeHeap(gpDDEMLHeap, 0, (p))
  15. #else
  16. #define DDEMLAlloc(cb) LocalAlloc(LPTR, cb)
  17. #define DDEMLReAlloc(p, cb) LocalReAlloc(p, cb, LHND)
  18. #define DDEMLFree(p) LocalFree(p);
  19. #endif
  20. // general typedefs
  21. typedef ATOM LATOM;
  22. typedef ATOM GATOM;
  23. // monitor stuff ------------------------------------------
  24. #define MONHSZ(pcii, hsz, type) if ((pcii->MonitorFlags & MF_HSZ_INFO) && hsz) \
  25. MonitorStringHandle(pcii, hsz, type)
  26. #define MONLINK(pcii, fEst, fNoD, aS, aT, aI, wFmt, fSvr, hConvS, hConvC) \
  27. if (pcii->MonitorFlags & MF_LINKS) \
  28. MonitorLink(pcii, fEst, fNoD, aS, aT, aI, \
  29. wFmt, fSvr, hConvS, hConvC)
  30. #define MONCONV(pcoi, fConn) \
  31. if (((pcoi)->pcii->MonitorFlags & MF_CONV) && \
  32. ((((pcoi)->state & ST_ISLOCAL) && (pcoi)->state & ST_CLIENT) || \
  33. !((pcoi)->state & ST_ISLOCAL))) \
  34. MonitorConv(pcoi, fConn);
  35. // critical section stuff ---------------------------------
  36. extern RTL_CRITICAL_SECTION gcsDDEML;
  37. #if DBG
  38. extern PVOID gpDDEMLHeap;
  39. #endif
  40. #define EnterDDECrit RtlEnterCriticalSection(&gcsDDEML);
  41. #define LeaveDDECrit RtlLeaveCriticalSection(&gcsDDEML);
  42. #if DBG
  43. #define CheckDDECritIn if (GetCurrentThreadId() != HandleToUlong(gcsDDEML.OwningThread)) { \
  44. RIPMSG0(RIP_ERROR, "CheckDDECritIn failed"); \
  45. }
  46. #define CheckDDECritOut if (GetCurrentThreadId() == HandleToUlong(gcsDDEML.OwningThread)) { \
  47. RIPMSG0(RIP_ERROR, "CheckDDECritoUT failed"); \
  48. }
  49. #else
  50. #define CheckDDECritIn ;
  51. #define CheckDDECritOut ;
  52. #endif
  53. // String handle stuff -------------------------------------
  54. // return values for ValidateHSZ macro
  55. #define HSZT_INVALID 0
  56. #define HSZT_NORMAL 1
  57. #define HSZT_INST_SPECIFIC 2
  58. #define LATOM_FROM_HSZ(hsz) (LATOM)(ULONG_PTR)(hsz)
  59. #define NORMAL_HSZ_FROM_LATOM(a) (HSZ)(ULONG_PTR)(a)
  60. #define INST_SPECIFIC_HSZ_FROM_LATOM(a) (HSZ)LongToHandle( MAKELONG(a, 1) )
  61. // Handle manager stuff ------------------------------------------
  62. typedef struct tagCHANDLEENTRY {
  63. HANDLE handle;
  64. ULONG_PTR dwData;
  65. } CHANDLEENTRY, *PCHANDLEENTRY;
  66. typedef BOOL (*PFNHANDLEAPPLY)(HANDLE);
  67. #define MASK_ID 0xFF000000 // 256 uniqueness
  68. #define SHIFT_ID 24
  69. #define MASK_INDEX 0x00FFFC00 // 16K handles per process max
  70. #define SHIFT_INDEX 10
  71. #define MASK_TYPE 0x00000380 // 8 types max
  72. #define SHIFT_TYPE 7
  73. #define MASK_INST 0x0000007F // 128 instances per process max
  74. #define SHIFT_INST 0
  75. #define MAX_INST MASK_INST
  76. #define IdFromHandle(h) (DWORD)(((ULONG_PTR)(h) & MASK_ID) >> SHIFT_ID)
  77. #define IndexFromHandle(h) (DWORD)(((ULONG_PTR)(h) & MASK_INDEX) >> SHIFT_INDEX)
  78. #define TypeFromHandle(h) (DWORD)(((ULONG_PTR)(h) & MASK_TYPE) >> SHIFT_TYPE)
  79. #define InstFromHandle(h) (DWORD)(((ULONG_PTR)(h) & MASK_INST) >> SHIFT_INST)
  80. #define HandleFromId(h) (((DWORD)(h)) << SHIFT_ID)
  81. #define HandleFromIndex(h) (((DWORD)(h)) << SHIFT_INDEX)
  82. #define HandleFromType(h) (((DWORD)(h)) << SHIFT_TYPE)
  83. #define HandleFromInst(h) (((DWORD)(h)) << SHIFT_INST)
  84. #define HTYPE_EMPTY 0
  85. #define HTYPE_INSTANCE 1
  86. #define HTYPE_SERVER_CONVERSATION 2
  87. #define HTYPE_CLIENT_CONVERSATION 3
  88. #define HTYPE_CONVERSATION_LIST 4
  89. #define HTYPE_TRANSACTION 5
  90. #define HTYPE_DATA_HANDLE 6
  91. #define HTYPE_ZOMBIE_CONVERSATION 7
  92. #define HTYPE_ANY (DWORD)(-1)
  93. #define HINST_ANY (DWORD)(-1)
  94. // transaction stuff -------------------------------------------
  95. typedef struct tagXACT_INFO *PXACT_INFO;
  96. typedef BOOL (* FNRESPONSE)(PXACT_INFO, UINT, LPARAM);
  97. typedef struct tagXACT_INFO {
  98. struct tagXACT_INFO *next;
  99. struct tagCONV_INFO *pcoi;
  100. DWORD_PTR hUser;
  101. HANDLE hXact;
  102. FNRESPONSE pfnResponse;
  103. GATOM gaItem;
  104. WORD wFmt;
  105. WORD wType; // for DdeQueryConvInfo only
  106. WORD wStatus; // see DDE_F flags
  107. WORD flags; // see XIF_ flags
  108. WORD state; // see XST_ state values (ddeml.h)
  109. HANDLE hDDESent; // in case NACK is returned.
  110. HANDLE hDDEResult;
  111. } XACT_INFO;
  112. #define XIF_SYNCHRONOUS 0x1
  113. #define XIF_COMPLETE 0x2
  114. #define XIF_ABANDONED 0x4
  115. #define TID_TIMEOUT 1
  116. // Advise link tracking stuff -----------------------------------
  117. typedef struct tagLINK_COUNT *PLINK_COUNT;
  118. typedef struct tagADVISE_LINK {
  119. struct tagLINK_COUNT *pLinkCount;
  120. LATOM laItem;
  121. WORD wFmt;
  122. WORD wType; // XTYP_ and XTYPF_ constants
  123. WORD state; // ADVST_ constant
  124. } ADVISE_LINK, *PADVISE_LINK;
  125. #define ADVST_WAITING 0x0080
  126. #define ADVST_CHANGED 0x0040
  127. // DDE message handling stuff -----------------------------------
  128. typedef struct tagDDE_MESSAGE_QUEUE {
  129. struct tagDDE_MESSAGE_QUEUE *next;
  130. struct tagCONV_INFO *pcoi;
  131. UINT msg;
  132. LPARAM lParam;
  133. } DDE_MESSAGE_QUEUE, *PDDE_MESSAGE_QUEUE;
  134. // instance info stuff -------------------------------------------
  135. typedef struct tagSERVER_LOOKUP {
  136. LATOM laService;
  137. LATOM laTopic;
  138. HWND hwndServer;
  139. } SERVER_LOOKUP, *PSERVER_LOOKUP;
  140. typedef struct tagLINK_COUNT {
  141. struct tagLINK_COUNT *next;
  142. LATOM laTopic;
  143. GATOM gaItem;
  144. LATOM laItem;
  145. WORD wFmt;
  146. short Total;
  147. short Count;
  148. } LINK_COUNT;
  149. typedef struct tagCL_INSTANCE_INFO {
  150. struct tagCL_INSTANCE_INFO *next;
  151. HANDLE hInstServer;
  152. HANDLE hInstClient;
  153. DWORD MonitorFlags;
  154. HWND hwndMother;
  155. HWND hwndEvent;
  156. HWND hwndTimeout;
  157. DWORD afCmd;
  158. PFNCALLBACK pfnCallback;
  159. DWORD LastError;
  160. DWORD tid;
  161. LATOM *plaNameService;
  162. WORD cNameServiceAlloc;
  163. PSERVER_LOOKUP aServerLookup;
  164. short cServerLookupAlloc;
  165. WORD ConvStartupState;
  166. WORD flags; // IIF_ flags
  167. short cInDDEMLCallback;
  168. PLINK_COUNT pLinkCount;
  169. } CL_INSTANCE_INFO, *PCL_INSTANCE_INFO;
  170. #define IIF_IN_SYNC_XACT 0x0001
  171. #define IIF_UNICODE 0x8000
  172. // conversation stuff ---------------------------------------------
  173. typedef struct tagCONV_INFO {
  174. struct tagCONV_INFO *next;
  175. PCL_INSTANCE_INFO pcii;
  176. DWORD_PTR hUser;
  177. HCONV hConv;
  178. LATOM laService;
  179. LATOM laTopic;
  180. HWND hwndPartner;
  181. HWND hwndConv;
  182. WORD state; // ST_ flags
  183. LATOM laServiceRequested;
  184. PXACT_INFO pxiIn;
  185. PXACT_INFO pxiOut;
  186. PDDE_MESSAGE_QUEUE dmqIn;
  187. PDDE_MESSAGE_QUEUE dmqOut;
  188. PADVISE_LINK aLinks;
  189. int cLinks;
  190. int cLocks;
  191. } CONV_INFO, *PCONV_INFO;
  192. typedef struct tagCL_CONV_INFO {
  193. CONV_INFO ci;
  194. HWND hwndReconnect;
  195. HCONVLIST hConvList;
  196. } CL_CONV_INFO, *PCL_CONV_INFO;
  197. typedef struct tagSVR_CONV_INFO {
  198. CONV_INFO ci;
  199. } SVR_CONV_INFO, *PSVR_CONV_INFO;
  200. typedef struct tagCONVLIST {
  201. int chwnd; // number of client windows in this list
  202. HWND ahwnd[1]; // windows in list.
  203. } CONVLIST, *PCONVLIST;
  204. extern CONVCONTEXT DefConvContext; // global from connect.c
  205. typedef struct tagENABLE_ENUM_STRUCT{
  206. BOOL *pfRet;
  207. WORD wCmd;
  208. WORD wCmd2;
  209. } ENABLE_ENUM_STRUCT, *PENABLE_ENUM_STRUCT;
  210. // memory management stuff -------------------------------------
  211. typedef struct tagDDEMLDATA {
  212. HANDLE hDDE; // Global data handle or data token
  213. DWORD flags; // See HDATA_ constants
  214. } DDEMLDATA, *PDDEMLDATA;
  215. // DDEML client side Globals -----------------------------------
  216. extern PHANDLE aInstance;
  217. extern DWORD gWM_REGISTERCALLBACK;
  218. // prototypes --------------------------------------------------
  219. // handles.c
  220. HANDLE CreateHandle(ULONG_PTR dwData, DWORD type, DWORD inst);
  221. ULONG_PTR DestroyHandle(HANDLE h);
  222. ULONG_PTR GetHandleData(HANDLE h);
  223. VOID SetHandleData(HANDLE h, ULONG_PTR dwData);
  224. ULONG_PTR ValidateCHandle(HANDLE h, DWORD ExpectedType, DWORD ExpectedInstance);
  225. PCL_INSTANCE_INFO PciiFromHandle(HANDLE h);
  226. HANDLE FindIstanceHandleFromHandle(HANDLE h);
  227. VOID ApplyFunctionToObjects(DWORD ExpectedType, DWORD ExpectedInstance,
  228. PFNHANDLEAPPLY pfn);
  229. VOID BestSetLastDDEMLError(DWORD error);
  230. // ddemlcli.c
  231. UINT InternalDdeInitialize(LPDWORD pidInst, PFNCALLBACK pfnCallback, DWORD afCmd,
  232. BOOL fUnicode);
  233. // DDEML API DdeInitializeA
  234. // DDEML API DdeInitializeW
  235. // DDEML API DdeUninitialize
  236. // DDEML API DdeNameService
  237. // DDEML API DdeGetLastError
  238. // instance.c
  239. HANDLE AddInstance(HANDLE hInst);
  240. HANDLE DestroyInstance(HANDLE hInst);
  241. PCL_INSTANCE_INFO ValidateInstance(HANDLE hInst);
  242. BOOL CsClearSecurityForAck(HANDLE hInst, HWND hwndServer, HWND hwndClient);
  243. VOID SetLastDDEMLError(PCL_INSTANCE_INFO pcii, DWORD error);
  244. // hsz.c
  245. HSZ InternalDdeCreateStringHandle(DWORD idInst, PVOID psz, int iCodePage);
  246. // DDEML API DdeCreateStringHandleA
  247. // DDEML API DdeCreateStringHandleW
  248. DWORD InternalDdeQueryString(DWORD idInst, HSZ hsz, PVOID psz, DWORD cchMax,
  249. INT iCodePage);
  250. // DDEML API DdeQueryStringA
  251. // DDEML API DdeQueryStringW
  252. // DDEML API DdeFreeStringHandle
  253. // DDEML API DdeKeepStringHandle
  254. // DDEML API DdeCmpStringHandles
  255. DWORD ValidateHSZ(HSZ hsz);
  256. LATOM MakeInstSpecificAtom(LATOM la, HWND hwnd);
  257. HWND ParseInstSpecificAtom(LATOM la, LATOM *plaNormal);
  258. GATOM LocalToGlobalAtom(LATOM la);
  259. LATOM GlobalToLocalAtom(GATOM ga);
  260. GATOM IncGlobalAtomCount(GATOM la);
  261. LATOM IncLocalAtomCount(LATOM la);
  262. // connect.c
  263. // DDEML API DdeConnect
  264. // DDEML API DdeConnectList
  265. // DDEML API DdeReconnect
  266. BOOL ValidateConnectParameters(HANDLE hInst, PCL_INSTANCE_INFO *ppcii,
  267. HSZ *phszService, HSZ hszTopic, LATOM *plaNormalSvcName,
  268. PCONVCONTEXT *ppCC, HWND *phwndTarget, HCONVLIST hConvList);
  269. PCL_CONV_INFO ConnectConv(PCL_INSTANCE_INFO pcii, LATOM laService,
  270. LATOM laTopic, HWND hwndTarget, HWND hwndSkip,
  271. PCONVCONTEXT pCC, HCONVLIST hConvList, DWORD clst);
  272. VOID SetCommonStateFlags(HWND hwndUs, HWND hwndThem, PWORD pwFlags);
  273. // DDEML API DdeQueryNextServer
  274. // DDEML API DdeDisconnect
  275. // DDEML API DdeDisconnectList
  276. VOID ShutdownConversation(PCONV_INFO pcoi, BOOL fMakeCallback);
  277. VOID FreeConversationResources(PCONV_INFO pcoi);
  278. BOOL WaitForZombieTerminate(HANDLE hData);
  279. // xact.c
  280. VOID GetConvContext(HWND hwnd, LONG *pl);
  281. VOID SetConvContext(HWND hwnd, LONG *pl);
  282. // DDEML API DdeClientTransaction
  283. // DDEML API DdeQueryConvInfo
  284. // DDEML API DdeSetUserHandle
  285. // DDEML API DdeAbandonTransaction
  286. BOOL
  287. UpdateLinkIfChanged(
  288. PADVISE_LINK paLink,
  289. PXACT_INFO pxi,
  290. PCONV_INFO pcoi,
  291. PADVISE_LINK paLinkLast,
  292. PBOOL pfSwapped,
  293. DWORD cLinksToGo);
  294. // DDEML API DdePostAdvise
  295. VOID LinkTransaction(PXACT_INFO pxi);
  296. VOID UnlinkTransaction(PXACT_INFO pxi);
  297. BOOL ValidateTransaction(HCONV hConv, HANDLE hXact, PCONV_INFO *ppcoi,
  298. PXACT_INFO *ppxi);
  299. // hdata.c
  300. // DDEML API DdeCreateDataHandle
  301. HDDEDATA InternalCreateDataHandle(PCL_INSTANCE_INFO pcii, LPBYTE pSrc, DWORD cb,
  302. DWORD cbOff, DWORD flags, WORD wStatus, WORD wFmt);
  303. // DDEML API DdeAddData
  304. // DDEML API DdeGetData
  305. // DDEML API DdeAccessData
  306. // DDEML API DdeUnaccessData
  307. // DDEML API DdeFreeDataHandle
  308. BOOL ApplyFreeDataHandle(HANDLE hData);
  309. BOOL InternalFreeDataHandle(HDDEDATA hData, BOOL fIgnorefRelease);
  310. VOID FreeDDEData(HANDLE hDDE, BOOL fIgnorefRelease, BOOL fFreeTruelyGlobalObjects);
  311. HANDLE CopyDDEData(HANDLE hDDE, BOOL fExec);
  312. // callback.c
  313. HDDEDATA DoCallback(PCL_INSTANCE_INFO pcii, WORD wType, WORD wFmt, HCONV hConv,
  314. HSZ hsz1, HSZ hsz2, HDDEDATA hData, ULONG_PTR dw1, ULONG_PTR dw2);
  315. DWORD _ClientEventCallback(PCL_INSTANCE_INFO pcii, PEVENT_PACKET pep);
  316. // DDEML API DdeEnableCallback
  317. BOOL SetEnableState(PCONV_INFO pcoi, UINT wCmd);
  318. DWORD _ClientGetDDEHookData(UINT message, LPARAM lParam,
  319. PDDEML_MSG_HOOK_DATA pdmhd);
  320. DWORD _ClientGetDDEFlags(HANDLE hClient, DWORD flags);
  321. BOOL EnableEnumProc(HWND hwnd, PENABLE_ENUM_STRUCT pees);
  322. // ddemlwp.c
  323. LRESULT DDEMLMotherWndProc(HWND, UINT, WPARAM, LPARAM);
  324. LRESULT DDEMLClientWndProc(HWND, UINT, WPARAM, LPARAM);
  325. LRESULT DDEMLServerWndProc(HWND, UINT, WPARAM, LPARAM);
  326. PCONV_INFO ProcessTerminateMsg(PCONV_INFO pcoi, HWND hwndFrom);
  327. VOID ProcessAsyncDDEMsg(PCONV_INFO pcoi, UINT msg, HWND hwndFrom, LPARAM lParam);
  328. BOOL CheckForQueuedMessages(PCONV_INFO pcoi);
  329. VOID DumpDDEMessage(BOOL fFreeData, UINT msg, LPARAM lParam);
  330. BOOL ProcessSyncDDEMessage(PCONV_INFO pcoi, UINT msg, LPARAM lParam);
  331. // stdptcl.c
  332. BOOL ClStartAdvise(PXACT_INFO pxi);
  333. BOOL SvSpontAdvise(PSVR_CONV_INFO psi, LPARAM lParam);
  334. BOOL ClRespAdviseAck(PXACT_INFO pxi, UINT msg, LPARAM lParam);
  335. BOOL SvStartAdviseUpdate(PXACT_INFO pxi, DWORD cLinksToGo);
  336. BOOL ClSpontAdviseData(PCL_CONV_INFO pci, LPARAM lParam);
  337. BOOL SvRespAdviseDataAck(PXACT_INFO pxi, UINT msg, LPARAM lParam);
  338. BOOL ClStartUnadvise(PXACT_INFO pxi);
  339. BOOL SvSpontUnadvise(PSVR_CONV_INFO psi, LPARAM lParam);
  340. BOOL ClRespUnadviseAck(PXACT_INFO pxi, UINT msg, LPARAM lParam);
  341. BOOL ClStartExecute(PXACT_INFO pxi);
  342. BOOL ClRespExecuteAck(PXACT_INFO pxi, UINT msg, LPARAM lParam);
  343. BOOL ClStartPoke(PXACT_INFO pxi);
  344. BOOL SvSpontPoke(PSVR_CONV_INFO psi, LPARAM lParam);
  345. BOOL ClRespPokeAck(PXACT_INFO pxi, UINT msg, LPARAM lParam);
  346. BOOL ClStartRequest(PXACT_INFO pxi);
  347. BOOL SvSpontRequest(PSVR_CONV_INFO psi, LPARAM lParam);
  348. BOOL ClRespRequestData(PXACT_INFO pxi, UINT msg, LPARAM lParam);
  349. BOOL SpontaneousClientMessage(PCL_CONV_INFO pci, UINT msg, LPARAM lParam);
  350. BOOL SpontaneousServerMessage(PSVR_CONV_INFO psi, UINT msg, LPARAM lParam);
  351. HANDLE AllocAndSetDDEData(LPBYTE pSrc, DWORD cb, WORD wStatus, WORD wFmt);
  352. DWORD PackAndPostMessage(HWND hwndTo, UINT msgIn, UINT msgOut, HWND hwndFrom,
  353. LPARAM lParam, UINT_PTR uiLo, UINT_PTR uiHi);
  354. BOOL ExtractDDEDataInfo(HANDLE hDDE, LPWORD pwStatus, LPWORD pwFmt);
  355. BOOL TransactionComplete(PXACT_INFO pxi, HDDEDATA hData);
  356. HANDLE UnpackAndFreeDDEMLDataHandle(HDDEDATA hData, BOOL fExec);
  357. // util.c
  358. BOOL AddLink(PCONV_INFO pcoi, GATOM gaItem, WORD wFmt, WORD wType);
  359. VOID DeleteLinkCount(PCL_INSTANCE_INFO pcii, PLINK_COUNT pLinkCountDelete);
  360. // monitor.c
  361. VOID MonitorStringHandle(PCL_INSTANCE_INFO pcii, HSZ hsz, DWORD fsAction);
  362. VOID MonitorLink(PCL_INSTANCE_INFO pcii, BOOL fEstablished, BOOL fNoData,
  363. LATOM laSvc, LATOM laTopic, GATOM gaItem, WORD wFmt, BOOL fServer,
  364. HCONV hConvServer, HCONV hConvClient);
  365. VOID MonitorConv(PCONV_INFO pcoi, BOOL fConnect);
  366. // register.c
  367. VOID RegisterService(BOOL fRegister, GATOM gaApp, HWND hwndListen);
  368. LRESULT ProcessRegistrationMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);