ddeclient.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* Simple client interface to DDE servers.
  2. Copyright (C) 1998, 2001-2017 Free Software Foundation, Inc.
  3. This file is part of GNU Emacs.
  4. GNU Emacs is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or (at
  7. your option) any later version.
  8. GNU Emacs is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
  14. #include <windows.h>
  15. #include <ddeml.h>
  16. #include <stdlib.h>
  17. #include <stdio.h>
  18. HDDEDATA CALLBACK DdeCallback (UINT, UINT, HCONV, HSZ, HSZ, HDDEDATA, DWORD,
  19. DWORD);
  20. HDDEDATA CALLBACK
  21. DdeCallback (UINT uType, UINT uFmt, HCONV hconv,
  22. HSZ hsz1, HSZ hsz2, HDDEDATA hdata,
  23. DWORD dwData1, DWORD dwData2)
  24. {
  25. return ((HDDEDATA) NULL);
  26. }
  27. #define DdeCommand(str) \
  28. DdeClientTransaction (str, strlen (str)+1, HConversation, (HSZ)NULL, \
  29. CF_TEXT, XTYP_EXECUTE, 30000, NULL)
  30. int
  31. main (int argc, char *argv[])
  32. {
  33. DWORD idDde = 0;
  34. HCONV HConversation;
  35. HSZ Server;
  36. HSZ Topic = 0;
  37. char command[1024];
  38. if (argc < 2)
  39. {
  40. fprintf (stderr, "usage: ddeclient server [topic]\n");
  41. exit (1);
  42. }
  43. DdeInitialize (&idDde, (PFNCALLBACK)DdeCallback, APPCMD_CLIENTONLY, 0);
  44. Server = DdeCreateStringHandle (idDde, argv[1], CP_WINANSI);
  45. if (argc > 2)
  46. Topic = DdeCreateStringHandle (idDde, argv[2], CP_WINANSI);
  47. HConversation = DdeConnect (idDde, Server, Topic, NULL);
  48. if (HConversation != 0)
  49. {
  50. while (fgets (command, sizeof(command), stdin) != NULL)
  51. DdeCommand (command);
  52. DdeDisconnect (HConversation);
  53. }
  54. DdeFreeStringHandle (idDde, Server);
  55. if (Topic)
  56. DdeFreeStringHandle (idDde, Topic);
  57. DdeUninitialize (idDde);
  58. return (0);
  59. }