ddeclient.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* Simple client interface to DDE servers.
  2. Copyright (C) 1998, 2001-2012 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
  7. (at 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
  19. DdeCallback (UINT uType, UINT uFmt, HCONV hconv,
  20. HSZ hsz1, HSZ hsz2, HDDEDATA hdata,
  21. DWORD dwData1, DWORD dwData2)
  22. {
  23. return ((HDDEDATA) NULL);
  24. }
  25. #define DdeCommand(str) \
  26. DdeClientTransaction (str, strlen (str)+1, HConversation, (HSZ)NULL, \
  27. CF_TEXT, XTYP_EXECUTE, 30000, NULL)
  28. int
  29. main (int argc, char *argv[])
  30. {
  31. DWORD idDde = 0;
  32. HCONV HConversation;
  33. HSZ Server;
  34. HSZ Topic = 0;
  35. char command[1024];
  36. if (argc < 2)
  37. {
  38. fprintf (stderr, "usage: ddeclient server [topic]\n");
  39. exit (1);
  40. }
  41. DdeInitialize (&idDde, (PFNCALLBACK)DdeCallback, APPCMD_CLIENTONLY, 0);
  42. Server = DdeCreateStringHandle (idDde, argv[1], CP_WINANSI);
  43. if (argc > 2)
  44. Topic = DdeCreateStringHandle (idDde, argv[2], CP_WINANSI);
  45. HConversation = DdeConnect (idDde, Server, Topic, NULL);
  46. if (HConversation != 0)
  47. {
  48. while (fgets (command, sizeof(command), stdin) != NULL)
  49. DdeCommand (command);
  50. DdeDisconnect (HConversation);
  51. }
  52. DdeFreeStringHandle (idDde, Server);
  53. if (Topic)
  54. DdeFreeStringHandle (idDde, Topic);
  55. DdeUninitialize (idDde);
  56. return (0);
  57. }