Windows NT 4.0 source code leak
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.

124 lines
4.6 KiB

4 years ago
  1. /***************************************************************************/
  2. /** Microsoft Windows **/
  3. /** Copyright(c) Microsoft Corp., 1991-1993 **/
  4. /***************************************************************************/
  5. /****************************************************************************
  6. pdde.h
  7. Aug 93, JimH non-MFC version
  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. Some built-in methods return a BOOL to determine success. Others (like
  18. the constructor) cannot, so use GetResult() for current status. If it
  19. is FALSE, GetLastError() can be useful.
  20. Class DDEServer : DDE
  21. This is a very simple extension. The contructor registers the server
  22. name and the destructor unregisters it. Most of the work for DDEML
  23. servers is done in the server callback function, not here.
  24. Class DDEClient : DDE
  25. This is used to instantiate a client-only DDE object. New methods
  26. request new data (RequestData) set up hot links (StartAdviseLoop)
  27. and send unsolicited data (Poke.)
  28. ****************************************************************************/
  29. #ifndef DDE_INC
  30. #define DDE_INC
  31. #define STRICT
  32. #include <windows.h>
  33. #include <ddeml.h>
  34. typedef HDDEDATA (CALLBACK *DDECALLBACK) (WORD, WORD, HCONV, HSZ, HSZ, HDDEDATA, DWORD, DWORD);
  35. HDDEDATA CALLBACK DdeServerCallBack(WORD, WORD, HCONV, HSZ, HSZ, HDDEDATA, DWORD, DWORD);
  36. HDDEDATA CALLBACK DdeClientCallBack(WORD, WORD, HCONV, HSZ, HSZ, HDDEDATA, DWORD, DWORD);
  37. class DDE
  38. {
  39. public:
  40. DDE(HINSTANCE hInst, const char *server, const char *topic,
  41. DDECALLBACK CallBack, DWORD filters = APPCLASS_STANDARD);
  42. virtual ~DDE();
  43. HDDEDATA CreateDataHandle(void FAR *lpbdata, DWORD size, HSZ hItem);
  44. HSZ CreateStrHandle(LPCSTR str, int codepage = CP_WINANSI);
  45. void DestroyStrHandle(HSZ hsz);
  46. PBYTE GetData(HDDEDATA hData, PBYTE pdata, DWORD len = 0);
  47. WORD GetInitError() { return _initerr; }
  48. UINT GetLastError() { return ::DdeGetLastError(_idInst); }
  49. BOOL GetResult() { return _bResult; }
  50. BOOL KeepStringHandle(HSZ hsz)
  51. { return ::DdeKeepStringHandle(_idInst, hsz); }
  52. void SetFilters(DWORD filters) { _filters = filters; }
  53. HSZ Topic() { return _hTopic; }
  54. private:
  55. BOOL Initialize(void);
  56. BOOL SetCallBack(HINSTANCE hInst, DDECALLBACK CallBack);
  57. DDECALLBACK _CallBack;
  58. DWORD _filters; // filters passed to ::DdeInitialize()
  59. WORD _initerr; // return error from ::DdeInitialize()
  60. protected:
  61. DWORD _idInst; // instance id from ::DdeInitialize()
  62. BOOL _bResult; // current state of object
  63. HSZ _hServer;
  64. HSZ _hTopic;
  65. };
  66. class DDEServer : public DDE
  67. {
  68. public:
  69. DDEServer(HINSTANCE hInst, const char *server, const char *topic,
  70. DDECALLBACK ServerCallBack,
  71. DWORD filters = APPCLASS_STANDARD);
  72. ~DDEServer(void);
  73. BOOL PostAdvise(HSZ hItem);
  74. };
  75. class DDEClient : public DDE
  76. {
  77. public:
  78. DDEClient(HINSTANCE hInst, const char *server, const char *topic,
  79. DDECALLBACK ClientCallBack,
  80. DWORD filters = APPCMD_CLIENTONLY | CBF_FAIL_SELFCONNECTIONS);
  81. ~DDEClient(void);
  82. BOOL Poke(HSZ hItem, const char *string, DWORD uTimeout = NULL);
  83. BOOL Poke(HSZ hItem, void FAR *pdata, DWORD len,
  84. DWORD uTimeout = NULL);
  85. BOOL ReConnect();
  86. void SetTimeOut(DWORD timeout) { _timeout = timeout; }
  87. HDDEDATA RequestData(HSZ hItem, DWORD uTimeout = NULL);
  88. BOOL StartAdviseLoop(HSZ hItem);
  89. private:
  90. HDDEDATA ClientTransaction(void FAR *lpbData, DWORD cbData, HSZ hItem,
  91. UINT uType, UINT uFmt = CF_TEXT);
  92. HCONV _hConv; // conversation handle from ::DdeConnect()
  93. DWORD _timeout; // timeout used in ::DdeClientTransaction()
  94. DWORD _deftimeout; // default timeout
  95. };
  96. #endif