1
0

dde.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include <windows.h>
  2. #include "dde.h"
  3. #include <strsafe.h>
  4. HDDEDATA CALLBACK DdeGenericCallback(UINT uType, UINT uFmt,HCONV hconv, HSZ hsz1,
  5. HSZ hsz2, HDDEDATA hdata, DWORD dwData1,
  6. DWORD dwData2)
  7. {
  8. return ((HDDEDATA)0);
  9. }
  10. void DdeCom::sendCommand(wchar_t *application, wchar_t *command, DWORD minInterval)
  11. {
  12. static DWORD lastCmd=0, now;
  13. HSZ string1,string2,string3;
  14. wchar_t line[512];
  15. HCONV ddeConv;
  16. DWORD result;
  17. now = GetTickCount();
  18. if (now < lastCmd + minInterval)
  19. return;
  20. StringCchCopy(line, 512, command);
  21. DWORD DDE=0;
  22. if (DdeInitialize(&DDE, DdeGenericCallback, CBF_SKIP_ALLNOTIFICATIONS+ST_CLIENT,0) != DMLERR_NO_ERROR)
  23. {
  24. MessageBox(NULL,L"DDE INITIALIZE", L"Error", MB_OK);
  25. return;
  26. }
  27. string1 = DdeCreateStringHandle(DDE, application, CP_WINANSI);
  28. string2 = DdeCreateStringHandle(DDE, L"COMMAND", CP_WINANSI);
  29. if ((ddeConv = DdeConnect(DDE, string1, string2, 0)) != 0)
  30. {
  31. string3 = DdeCreateStringHandle(DDE, L"None", CP_WINANSI);
  32. DdeClientTransaction((LPBYTE)line, (wcslen(line)+1)*sizeof(line[0]), ddeConv, string3, CF_UNICODETEXT, XTYP_POKE, 1000, &result);
  33. DdeFreeStringHandle(DDE, string3);
  34. DdeDisconnect(ddeConv);
  35. lastCmd = now;
  36. }
  37. DdeFreeStringHandle(DDE, string1);
  38. DdeFreeStringHandle(DDE, string2);
  39. DdeUninitialize(DDE);
  40. }