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.

346 lines
7.8 KiB

  1. /*----------------------------------------------------------------------------
  2. iedde.cpp
  3. Sends URL open command to IE using DDE
  4. Copyright (C) 1995-96 Microsoft Corporation
  5. All right reserved
  6. Authors:
  7. VetriV Vellore T. Vetrivelkumaran
  8. jmazner Jeremy Mazner
  9. History:
  10. 8/29/96 jmazner created, with minor changes for 32 bit world, from
  11. VetriV's ie16dde.cpp
  12. ----------------------------------------------------------------------------*/
  13. #include "isignup.h"
  14. #if defined(WIN16)
  15. #include <windows.h>
  16. #endif
  17. #include <ddeml.h>
  18. #include <stdio.h>
  19. #include <malloc.h>
  20. #include <stdlib.h>
  21. #include <stdarg.h>
  22. #include <string.h>
  23. static FARPROC lpfnDDEProc;
  24. static HCONV hConv = (HCONV) NULL;
  25. static HSZ hszMosaicService = (HSZ) NULL;
  26. static HSZ hszTopic = (HSZ) NULL;
  27. static HSZ hszItem = (HSZ) NULL;
  28. static DWORD g_dwInstance = 0;
  29. //+---------------------------------------------------------------------------
  30. //
  31. // Function: Dprintf
  32. //
  33. // Synopsis: Prints the values contained in the variable number of
  34. // arguments in the specified format
  35. //
  36. // Arguments: [pcsz - Format string]
  37. //
  38. // Returns: Nothing
  39. //
  40. // History: 8/9/96 VetriV Created
  41. //
  42. //----------------------------------------------------------------------------
  43. void Dprintf(LPCSTR pcsz, ...)
  44. {
  45. #ifdef DEBUG
  46. va_list argp;
  47. char szBuf[1024];
  48. va_start(argp, pcsz);
  49. wvsprintf(szBuf, pcsz, argp);
  50. OutputDebugString(szBuf);
  51. va_end(argp);
  52. #endif
  53. }
  54. //+---------------------------------------------------------------------------
  55. //
  56. // Function: DdeCallback
  57. //
  58. // Synopsis: Callback function used in DDEIntialize
  59. //
  60. // Arguments: [Please see DdeInitialize documentation]
  61. //
  62. // Returns: Nothing
  63. //
  64. // History: 8/9/96 VetriV Created
  65. // 8/29/96 jmazner minor change in signature for 32 bit world
  66. //
  67. //----------------------------------------------------------------------------
  68. #if defined(WIN16)
  69. extern "C"
  70. HDDEDATA CALLBACK _export DdeCallBack(UINT uType, // transaction type
  71. #else
  72. HDDEDATA CALLBACK DdeCallBack(UINT uType, // transaction type
  73. #endif
  74. UINT uFmt, // clipboard data format
  75. HCONV hconv, // handle of the conversation
  76. HSZ hsz1, // handle of a string
  77. HSZ hsz2, // handle of a string
  78. HDDEDATA hdata, // handle of a global memory object
  79. DWORD dwData1, // transaction-specific data
  80. DWORD dwData2) // transaction-specific data
  81. {
  82. return 0;
  83. }
  84. //+---------------------------------------------------------------------------
  85. //
  86. // Function: OpenURL
  87. //
  88. // Synopsis: Opens the given URL use DDE.
  89. // Warning: This function uses global static variables and hence
  90. // it is not re-entrant.
  91. //
  92. // Arguments: [lpsszURL - URL to be opened]
  93. //
  94. // Returns: Nothing
  95. //
  96. // History: 8/9/96 VetriV Created
  97. // 9/3/96 jmazner Minor tweaks; moved string handle code in from DdeInit
  98. //
  99. //----------------------------------------------------------------------------
  100. int OpenURL(LPCTSTR lpcszURL)
  101. {
  102. TCHAR szOpenURL[] = TEXT("WWW_OpenURL");
  103. TCHAR szRemainingParams[] = TEXT("\"\",-1,0,\"\",\"\",\"\"");
  104. TCHAR szArg[1024];
  105. HDDEDATA trans_ret;
  106. long long_result;
  107. if ((NULL == lpcszURL) || ('\0' == lpcszURL[0]))
  108. goto ErrorOpenURL;
  109. //
  110. // Create String handle for the Operation WWW_OpenURL
  111. //
  112. if (hszTopic)
  113. DdeFreeStringHandle(g_dwInstance, hszTopic);
  114. hszTopic = DdeCreateStringHandle(g_dwInstance, szOpenURL, CP_WINANSI);
  115. if (!hszTopic)
  116. {
  117. Dprintf("DdeCreateStringHandle for %s failed with %u\r\n",
  118. szOpenURL, DdeGetLastError(g_dwInstance));
  119. goto ErrorOpenURL;
  120. }
  121. //
  122. // Compose the argument string
  123. //
  124. if (lstrlen(lpcszURL) + lstrlen(szRemainingParams) > 1020)
  125. goto ErrorOpenURL;
  126. memset(szArg, 0, sizeof(szArg));
  127. wsprintf(szArg, TEXT("\"%s\",%s"), lpcszURL, szRemainingParams);
  128. //
  129. // Create String Handle for the Arguments
  130. //
  131. if (hszItem)
  132. DdeFreeStringHandle(g_dwInstance, hszItem);
  133. hszItem = DdeCreateStringHandle(g_dwInstance, szArg, CP_WINANSI);
  134. if (!hszItem)
  135. {
  136. Dprintf("DdeCreateStringHandle for %s failed with %u\r\n",
  137. szArg, DdeGetLastError(g_dwInstance));
  138. goto ErrorOpenURL;
  139. }
  140. //
  141. // Connect to DDE Server
  142. //
  143. hConv = DdeConnect(g_dwInstance, hszMosaicService, hszTopic, NULL);
  144. if (!hConv)
  145. {
  146. Dprintf("DdeConnect failed with %u\r\n",
  147. DdeGetLastError(g_dwInstance));
  148. goto ErrorOpenURL;
  149. }
  150. //
  151. // Request
  152. //
  153. trans_ret = DdeClientTransaction(NULL, 0, hConv, hszItem, CF_TEXT,
  154. XTYP_REQUEST, 60000, NULL);
  155. //
  156. // long integer return value
  157. //
  158. if (trans_ret != DDE_FNOTPROCESSED)
  159. {
  160. DdeGetData(trans_ret, (LPBYTE) &long_result, sizeof(long_result), 0);
  161. DdeFreeDataHandle(trans_ret);
  162. return 0; // Successfully started opening the URL
  163. }
  164. else
  165. {
  166. Dprintf("DdeClientTransaction failed with %u\r\n",
  167. DdeGetLastError(g_dwInstance));
  168. goto ErrorOpenURL;
  169. }
  170. ErrorOpenURL:
  171. if (hConv)
  172. {
  173. DdeDisconnect(hConv);
  174. hConv = (HCONV) NULL;
  175. }
  176. if (hszTopic)
  177. {
  178. DdeFreeStringHandle(g_dwInstance, hszTopic);
  179. hszTopic = NULL;
  180. }
  181. if (hszItem)
  182. {
  183. DdeFreeStringHandle(g_dwInstance, hszItem);
  184. hszItem = NULL;
  185. }
  186. return -1;
  187. }
  188. //+---------------------------------------------------------------------------
  189. //
  190. // Function: DDEClose
  191. //
  192. // Synopsis: Shutsdown DDE and releases string handles
  193. // Warning: This function uses global static variables and hence
  194. // it is not re-entrant.
  195. //
  196. // Arguments: None
  197. //
  198. // Returns: Nothing
  199. //
  200. // History: 8/9/96 VetriV Created
  201. //
  202. //----------------------------------------------------------------------------
  203. void DDEClose(void)
  204. {
  205. Dprintf("DDEClose called\r\n");
  206. if (0 != g_dwInstance)
  207. {
  208. if (hConv)
  209. {
  210. DdeDisconnect(hConv);
  211. hConv = (HCONV) NULL;
  212. }
  213. if (hszTopic)
  214. {
  215. DdeFreeStringHandle(g_dwInstance, hszTopic);
  216. hszTopic = NULL;
  217. }
  218. if (hszItem)
  219. {
  220. DdeFreeStringHandle(g_dwInstance, hszItem);
  221. hszItem = NULL;
  222. }
  223. if (hszMosaicService)
  224. {
  225. DdeFreeStringHandle(g_dwInstance, hszMosaicService);
  226. hszMosaicService = NULL;
  227. }
  228. DdeUninitialize(g_dwInstance);
  229. g_dwInstance = 0;
  230. }
  231. return;
  232. }
  233. //+---------------------------------------------------------------------------
  234. //
  235. // Function: DDEinit
  236. //
  237. // Synopsis: Intializes DDE, creates string handles for service
  238. // and registers the names.
  239. // Warning: This function uses global static variables and hence
  240. // it is not re-entrant.
  241. //
  242. // Arguments: [hInst - Instance handle]
  243. //
  244. // Returns: 0 if successful
  245. // Negative values, otherwise
  246. //
  247. // History: 8/9/96 VetriV Created
  248. // 8/29/96 jmazner Removed calls to make us a DDE server,
  249. // moved string handle code to openUrl
  250. //
  251. //----------------------------------------------------------------------------
  252. int DDEInit(HINSTANCE hInst)
  253. {
  254. UINT uiRetValue;
  255. Dprintf("DDEInit called with %u\r\n", hInst);
  256. if (g_dwInstance == 0)
  257. {
  258. lpfnDDEProc = MakeProcInstance((FARPROC) DdeCallBack, hInst);
  259. if (NULL == lpfnDDEProc)
  260. {
  261. Dprintf("MakeProcInstance failed");
  262. return -1;
  263. }
  264. uiRetValue = DdeInitialize(&g_dwInstance, (PFNCALLBACK) lpfnDDEProc,
  265. APPCLASS_STANDARD, 0);
  266. if (DMLERR_NO_ERROR != uiRetValue)
  267. {
  268. Dprintf("DdeInitialize failed with %u\r\n", uiRetValue);
  269. g_dwInstance = 0;
  270. return -2;
  271. }
  272. }
  273. hszMosaicService = DdeCreateStringHandle(g_dwInstance, TEXT("IEXPLORE"), CP_WINANSI);
  274. if (NULL == hszMosaicService)
  275. {
  276. Dprintf("DdeCreateStringHandle for IEXPLORE failed with %u\r\n",
  277. DdeGetLastError(g_dwInstance));
  278. }
  279. return( TRUE );
  280. }