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.

293 lines
7.1 KiB

  1. /*****************************************************************************
  2. D D E C A L L B A C K
  3. Name: callback.c
  4. Date: 21-Jan-1994
  5. Creator: Unknown
  6. Description:
  7. History:
  8. Date Description
  9. ----------- -------------------------------------------------------
  10. 10-Apr-1996 johnfu, added retry count for RQ_PREVBITMAP
  11. 03-Nov-1997 drewm, added code to fix bug 3168
  12. *****************************************************************************/
  13. #include <windows.h>
  14. #include "common.h"
  15. #include "clipbook.h"
  16. #include "clipbrd.h"
  17. #include "callback.h"
  18. #include "debugout.h"
  19. #include "cvutil.h"
  20. // internal forwards
  21. static HWND GetConvHwnd ( HCONV hConv );
  22. /*
  23. * DdeCallback
  24. *
  25. * ddeml callback routine
  26. */
  27. HDDEDATA EXPENTRY DdeCallback(
  28. WORD wType,
  29. WORD wFmt,
  30. HCONV hConv,
  31. HSZ hszTopic,
  32. HSZ hszItem,
  33. HDDEDATA hData,
  34. DWORD lData1,
  35. DWORD lData2)
  36. {
  37. HWND hwndTmp;
  38. CONVINFO ConvInfo;
  39. PDATAREQ pDataReq;
  40. switch (wType)
  41. {
  42. case XTYP_ADVDATA:
  43. if ( hwndTmp = GetConvHwnd ( hConv ) )
  44. {
  45. InitListBox ( hwndTmp, hData );
  46. }
  47. return FALSE;
  48. break;
  49. case XTYP_DISCONNECT:
  50. ConvInfo.cb = sizeof(CONVINFO);
  51. if (DdeQueryConvInfo ( hConv, (DWORD)QID_SYNC, &ConvInfo ) == 0)
  52. {
  53. PERROR(TEXT("DdeQueryConvInfo for %p failed: %x\n\r"),
  54. (DWORD_PTR)hConv, DdeGetLastError(idInst));
  55. break;
  56. }
  57. if (pDataReq = (PDATAREQ)ConvInfo.hUser)
  58. {
  59. PINFO(TEXT("Freeing data req on %lx at disconnect time\n\r"), hConv);
  60. MessageBoxID (hInst, hwndApp, IDS_PRIVILEGEERROR, IDS_APPNAME,
  61. MB_OK | MB_ICONSTOP);
  62. ProcessDataReq (0, pDataReq);
  63. DeleteDataReq (pDataReq);
  64. DdeSetUserHandle (hConv, (DWORD)QID_SYNC, 0L);
  65. }
  66. else
  67. {
  68. PINFO(TEXT("Disconnect received on %lx - no datareq\n\r"), hConv );
  69. }
  70. break;
  71. case XTYP_XACT_COMPLETE:
  72. ConvInfo.cb = sizeof(CONVINFO);
  73. if ( DdeQueryConvInfo ( hConv, (DWORD)QID_SYNC, &ConvInfo ) == 0 )
  74. {
  75. PERROR(TEXT("DdeQueryConvInfo for %p failed: %x\n\r"),
  76. (DWORD_PTR)hConv, DdeGetLastError(idInst));
  77. break;
  78. }
  79. PINFO(TEXT("dde callback: got %lx data from conv handle %p\n\r"),
  80. ConvInfo.hUser, (DWORD_PTR)hConv );
  81. pDataReq = (PDATAREQ)ConvInfo.hUser;
  82. if (hData)
  83. ProcessDataReq (hData, pDataReq);
  84. else
  85. {
  86. if (RQ_PREVBITMAP == pDataReq->rqType &&
  87. pDataReq->wRetryCnt)
  88. {
  89. LPLISTENTRY lpLE;
  90. HWND hwnd;
  91. INT iItem;
  92. WORD wRetryCnt;
  93. wRetryCnt = pDataReq->wRetryCnt;
  94. hwnd = pDataReq->hwndMDI;
  95. iItem = pDataReq->iListbox;
  96. SendMessage (GETMDIINFO(hwnd)->hWndListbox,
  97. LB_GETTEXT,
  98. iItem,
  99. (LPARAM)&lpLE);
  100. GetPreviewBitmap (hwnd, lpLE->name, iItem);
  101. pDataReq->wRetryCnt = wRetryCnt -1;
  102. break;
  103. }
  104. RequestXactError (hConv);
  105. XactMessageBox (hInst, hwndApp, IDS_APPNAME, MB_OK | MB_ICONSTOP);
  106. }
  107. DdeSetUserHandle (hConv, (DWORD)QID_SYNC, 0L);
  108. if (pDataReq->fDisconnect)
  109. {
  110. DdeDisconnect (hConv);
  111. }
  112. DeleteDataReq (pDataReq);
  113. break;
  114. case XTYP_REGISTER:
  115. case XTYP_UNREGISTER:
  116. case XTYP_ADVREQ:
  117. case XTYP_REQUEST:
  118. case XTYP_ADVSTART:
  119. case XTYP_CONNECT_CONFIRM:
  120. case XTYP_CONNECT:
  121. default:
  122. break;
  123. }
  124. return 0;
  125. }
  126. /*
  127. * GetConvHwnd
  128. *
  129. * this function retrieves the window handle associated with
  130. * a conversation handle - the hande is put there by
  131. * using DdeSetUserHandle at DdeConnect time
  132. */
  133. static HWND GetConvHwnd ( HCONV hConv )
  134. {
  135. CONVINFO ConvInfo;
  136. PDATAREQ pDataReq;
  137. ConvInfo.cb = sizeof(CONVINFO);
  138. if ( DdeQueryConvInfo ( hConv, (DWORD)QID_SYNC, &ConvInfo ) == 0 )
  139. {
  140. PERROR(TEXT("DdeQueryConvInfo for %p failed: %x\n\r"),
  141. (DWORD_PTR)hConv, DdeGetLastError(idInst));
  142. }
  143. pDataReq = (PDATAREQ)ConvInfo.hUser;
  144. PINFO(TEXT("GetConvHwnd: got %p as conv handle\r\n"), pDataReq);
  145. if ( !IsWindow ( pDataReq->hwndMDI ) )
  146. {
  147. PERROR(TEXT("Invalid window %p in conv Uhandle: %p!\n\r"),
  148. (DWORD_PTR)pDataReq->hwndMDI, (DWORD_PTR)hConv );
  149. return NULL;
  150. }
  151. return pDataReq->hwndMDI;
  152. }
  153. /*
  154. * GetClipsrvVersion
  155. *
  156. * Purpose: Get the version of Clipsrv connected to the given MDI
  157. * child.
  158. *
  159. * Parameters:
  160. * hwndChild - The child window.
  161. *
  162. * Returns:
  163. * A version number with the Clipsrv OS version in the hiword, and
  164. * the Clipsrv version in the loword.
  165. *
  166. * Hiword values:
  167. * 0 - Win 3.x
  168. * 1 - NT 1.x
  169. *
  170. * Loword values:
  171. * 0 - WFW 1.0 Clipsrv
  172. * 1 - NT 1.0 Clipsrv, adds [version] and [security] executes
  173. */
  174. DWORD GetClipsrvVersion(
  175. HWND hwndChild)
  176. {
  177. MDIINFO *pMDI;
  178. HDDEDATA hdde;
  179. DWORD dwRet;
  180. char *lpszDDE;
  181. dwRet = 0;
  182. if (!(pMDI = GETMDIINFO(hwndChild)))
  183. return 0;
  184. if (!(pMDI->flags & F_CLPBRD))
  185. {
  186. hdde = MySyncXact (SZCMD_VERSION,
  187. lstrlen(SZCMD_VERSION) + 1,
  188. pMDI->hExeConv,
  189. 0L,
  190. CF_TEXT,
  191. XTYP_EXECUTE,
  192. SHORT_SYNC_TIMEOUT, NULL);
  193. if (hdde)
  194. {
  195. lpszDDE = (char *)DdeAccessData(hdde, &dwRet);
  196. if (lpszDDE)
  197. {
  198. dwRet = MAKELONG(lpszDDE[0] - '0', lpszDDE[2] - '0');
  199. }
  200. else
  201. {
  202. dwRet = 0L;
  203. }
  204. DdeUnaccessData (hdde);
  205. DdeFreeDataHandle (hdde);
  206. }
  207. else
  208. {
  209. PINFO(TEXT("Clipsrv didn't like version execute\r\n"));
  210. }
  211. }
  212. else
  213. {
  214. PERROR(TEXT("No Clipsrv for clipboard!\r\n"));
  215. }
  216. return dwRet;
  217. }