Guest User

Untitled

a guest
Mar 10th, 2011
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.42 KB | None | 0 0
  1. #include <windows.h>
  2. #include <iostream>
  3. #include <fstream>
  4.  
  5.  
  6. #define TACCESS_API  __declspec(dllimport)
  7. typedef bool (WINAPI *tcallback)(BYTE* pData);
  8. typedef BYTE* (WINAPI *typeSendCommand)(BYTE* pData);
  9. typedef bool (WINAPI  *typeFreeMemory)(BYTE* pData);
  10. typedef bool (WINAPI *typeSetCallback)(tcallback pCallback);
  11.  
  12.  
  13. std::ofstream xmlfile;
  14. typeFreeMemory FreeMemory;
  15.  
  16.  
  17. bool CALLBACK acceptor(BYTE *pData)
  18. {
  19.     xmlfile<<pData<<std::endl;
  20.     FreeMemory(pData);
  21.     return true;
  22. }
  23.  
  24. int main(int argc, char* argv[]) {
  25.  
  26.     setlocale(LC_CTYPE, "");
  27.  
  28.     std::cout<<"Statring!"<<std::endl;
  29.     xmlfile.open("test.xml");
  30.     xmlfile<<"<?xml version='1.0' encoding='UTF-8'?>";
  31.     xmlfile<<"<root>";
  32.  
  33.     HMODULE hm = LoadLibrary("Debug\\txmlconnector.dll");
  34.     if (hm) {
  35.         typeSetCallback SetCallback =
  36.             reinterpret_cast<typeSetCallback>(GetProcAddress(hm, "SetCallback"));
  37.  
  38.         FreeMemory =
  39.             reinterpret_cast<typeFreeMemory>(GetProcAddress(hm, "FreeMemory"));
  40.  
  41.         SetCallback(acceptor);
  42.    
  43.  
  44.         typeSendCommand SendCommand =
  45.             reinterpret_cast<typeSendCommand>(GetProcAddress(hm,"SendCommand"));
  46.         if (!SendCommand)   {
  47.             printf("\"SendCommand\" not found (0x%X)\n", GetLastError());
  48.             return -1;
  49.         }
  50.         else {
  51.             BYTE* ss = SendCommand(reinterpret_cast<BYTE*>(
  52.                 "<command id='connect'>"
  53.                 "<login>KOKS</login><password>koks</password>"
  54.                 "<host>192.168.15.15</host><port>3901</port>"
  55.                 "<logsdir>.\\LOGS\\</logsdir><loglevel>0</loglevel></command>"));
  56.             std::cout<<reinterpret_cast<const char*>(ss);
  57.             FreeMemory(ss);
  58.  
  59.             Sleep(10000);
  60.  
  61.             ss = SendCommand(reinterpret_cast<BYTE*>("<command id='subscribe'>"
  62.                 "<alltrades><secid>304</secid></alltrades>"  //èäåíòèôèêàòîðû âçÿë ïðîñòî äëÿ ïðèìåðà
  63.                 "<quotations><secid>304</secid></quotations>" //â ðåàëüíî êîäà íàäî îðèåíòèðîâàòü íà òî,
  64.                 "<quotes><secid>304</secid></quotes>" //÷òî ïðèñûëâàåò ñåðâåð
  65.                 "</command>"));
  66.             std::cout<<reinterpret_cast<const char*>(ss);
  67.             FreeMemory(ss);
  68.  
  69.             Sleep(1000);
  70.  
  71.             ss = SendCommand(reinterpret_cast<BYTE*>(
  72.                     "<command id='disconnect'/>"));
  73.                 std::cout<<reinterpret_cast<char*>(ss);
  74.             FreeMemory(ss);
  75.         }
  76.    
  77.         try {
  78.             FreeLibrary(hm);
  79.         }
  80.         catch (...) {
  81.             std::cout<<"Fail in FreeLibrary";
  82.         }
  83.     }
  84.     int err = GetLastError();
  85.     xmlfile<<"</root>";
  86.  
  87.     std::cout<<"\nEnded...\n";
  88.     char c;
  89.     std::cin>>c;
  90.     return 0;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment