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.

128 lines
5.0 KiB

  1. /***************************************************************************/
  2. /** Microsoft Windows **/
  3. /** Copyright(c) Microsoft Corp., 1991, 1992 **/
  4. /***************************************************************************/
  5. /****************************************************************************
  6. dde.h
  7. Aug 92, JimH
  8. Header file for DDE objects (DDEClient, and DDEServer.) DDE is not meant to
  9. be instantiated directly.
  10. Class DDE
  11. This superclass requires both a server name and a topic name for which
  12. it creates and destroys string handles. Servers technically do not
  13. need the topic name to instantiate, but they generally need at least
  14. one to do useful things, so it is provided here. Clients require the
  15. topic name to connect. DDE also requires a dde callback function pointer.
  16. Type DDECALLBACK is defined for this purpose.
  17. DDE provides a convenient way to retrieve dde data from within
  18. callback functions, especially string data in CString objects via
  19. GetDataString(hData). Structures can also be retrieved, but in that
  20. case memory must be allocated prior to the GetData() call.
  21. Some built-in methods return a BOOL to determine success. Others (like
  22. the constructor) cannot, so use GetResult() for current status. If it
  23. is FALSE, GetLastError() can be useful.
  24. Class DDEServer : DDE
  25. This is a very simple extension. The contructor registers the server
  26. name and the destructor unregisters it. Most of the work for DDEML
  27. servers is done in the server callback function, not here.
  28. Class DDEClient : DDE
  29. This is used to instantiate a client-only DDE object. New methods
  30. request new data (RequestString) set up hot links (StartAdviseLoop)
  31. and send unsolicited data (Poke.)
  32. ****************************************************************************/
  33. #ifndef DDE_INC
  34. #define DDE_INC
  35. #include <ddeml.h>
  36. typedef HDDEDATA (EXPENTRY *DDECALLBACK) (WORD, WORD, HCONV, HSZ, HSZ, HDDEDATA, DWORD, DWORD);
  37. HDDEDATA EXPENTRY EXPORT DdeServerCallBack(WORD, WORD, HCONV, HSZ, HSZ, HDDEDATA, DWORD, DWORD);
  38. HDDEDATA EXPENTRY EXPORT DdeClientCallBack(WORD, WORD, HCONV, HSZ, HSZ, HDDEDATA, DWORD, DWORD);
  39. class DDE
  40. {
  41. public:
  42. DDE(const TCHAR *server, const TCHAR *topic, DDECALLBACK CallBack,
  43. DWORD filters = APPCLASS_STANDARD);
  44. virtual ~DDE();
  45. HDDEDATA CreateDataHandle(void FAR *pdata, DWORD size, HSZ hItem);
  46. HSZ CreateStrHandle(LPCTSTR str, int codepage = CP_WINANSI);
  47. void DestroyStrHandle(HSZ hsz);
  48. PBYTE GetData(HDDEDATA hData, PBYTE pdata, DWORD len = 0);
  49. CString GetDataString(HDDEDATA hData = NULL);
  50. WORD GetInitError() { return m_initerr; }
  51. UINT GetLastError() { return ::DdeGetLastError(m_idInst); }
  52. BOOL GetResult() { return m_bResult; }
  53. CString GetServer() { return m_server; }
  54. CString GetTopic() { return m_topic; }
  55. BOOL SetCallBack(DDECALLBACK CallBack);
  56. void SetFilters(DWORD filters) { m_filters = filters; }
  57. private:
  58. BOOL Initialize(void);
  59. DDECALLBACK m_CallBack;
  60. DWORD m_filters; // filters passed to ::DdeInitialize()
  61. WORD m_initerr; // return error from ::DdeInitialize()
  62. protected:
  63. DWORD m_idInst; // instance id from ::DdeInitialize()
  64. BOOL m_bResult; // current state of object
  65. CString m_data; // last string acquired from GetDataString()
  66. CString m_server, m_topic; // server and topic names
  67. HSZ m_hServer, m_hTopic;
  68. };
  69. class DDEServer : public DDE
  70. {
  71. public:
  72. DDEServer(const TCHAR *server, const TCHAR *topic,
  73. DDECALLBACK ServerCallBack,
  74. DWORD filters = APPCLASS_STANDARD);
  75. ~DDEServer(void);
  76. BOOL PostAdvise(HSZ hItem);
  77. };
  78. class DDEClient : public DDE
  79. {
  80. public:
  81. DDEClient(const TCHAR *server, const TCHAR *topic,
  82. DDECALLBACK ClientCallBack,
  83. DWORD filters = APPCMD_CLIENTONLY | CBF_FAIL_SELFCONNECTIONS);
  84. ~DDEClient(void);
  85. BOOL Poke(HSZ hItem, const TCHAR *string, DWORD uTimeout = NULL);
  86. BOOL Poke(HSZ hItem, void FAR *pdata, DWORD len,
  87. DWORD uTimeout = NULL);
  88. void SetTimeOut(DWORD timeout) { m_timeout = timeout; }
  89. HDDEDATA RequestData(HSZ hItem, DWORD uTimeout = NULL);
  90. BOOL RequestString(HSZ hItem, DWORD uTimeout = NULL);
  91. BOOL StartAdviseLoop(HSZ hItem);
  92. private:
  93. HDDEDATA ClientTransaction(void FAR *lpvData, DWORD cbData, HSZ hItem,
  94. UINT uType, UINT uFmt = CF_TEXT);
  95. HCONV m_hConv; // conversation handle from ::DdeConnect()
  96. DWORD m_timeout; // timeout used in ::DdeClientTransaction()
  97. DWORD m_deftimeout; // default timeout
  98. };
  99. extern DDEClient *ddeClient;
  100. extern DDEServer *ddeServer;
  101. #endif