Source code of Windows XP (NT5)
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.

114 lines
2.6 KiB

  1. #include "stdinc.h"
  2. #include "SxApwHandle.h"
  3. #include "SxApwCreate.h"
  4. #include <string>
  5. #include <vector>
  6. #include <fstream>
  7. #include <iostream>
  8. #include "idsource.h"
  9. #include "chost.h"
  10. static ATL::CComModule Module;
  11. BEGIN_OBJECT_MAP(ObjectMap)
  12. //OBJECT_ENTRY(__uuidof(CSxApwHost), CSxApwHost)
  13. END_OBJECT_MAP()
  14. ATL::CComModule* GetModule() { return &Module; }
  15. ATL::_ATL_OBJMAP_ENTRY* GetObjectMap() { return ObjectMap; }
  16. const CLSID* GetTypeLibraryId() { return NULL; }
  17. std::wstring MultiByteToWideChar( const std::string& source )
  18. {
  19. std::vector<WCHAR> wch;
  20. wch.resize( MultiByteToWideChar( CP_ACP, 0, source.data(), source.size(), NULL, 0 ) );
  21. MultiByteToWideChar( CP_ACP, 0, source.data(), source.size(), &wch.front(), wch.size() );
  22. return std::wstring( wch.begin(), wch.end() );
  23. }
  24. STDMETHODIMP
  25. CSxApwHost::EstimateRowCount(
  26. int
  27. )
  28. {
  29. /* just ignore it */
  30. return S_OK;
  31. }
  32. STDMETHODIMP
  33. CSxApwHost::OnNextRow(
  34. int nColumns,
  35. const PCWSTR columns[]
  36. )
  37. {
  38. /*
  39. just multiplex/broadcast the data across all the views..
  40. */
  41. for (Views_t::const_iterator i = m_views.begin(); i != m_views.end() ; ++i)
  42. {
  43. (*i)->OnNextRow(nColumns, columns);
  44. }
  45. return S_OK;
  46. }
  47. HRESULT CSxApwHost::Main()
  48. {
  49. HRESULT hr;
  50. ATL::CComPtr<ISxApwDataSource> dirSource;
  51. ATL::CComPtr<ISxApwDataSource> dbSource;
  52. std::ifstream inStream;
  53. if (FAILED(hr = SetDataSource(CLSID_CSxApwDirDataSource_brace_stringW)))
  54. goto Exit;
  55. dirSource = m_dataSource;
  56. m_dataSource.Release();
  57. if (FAILED(hr = SetDataSource(CLSID_CSxApwDbDataSource_brace_stringW)))
  58. goto Exit;
  59. dbSource = m_dataSource;
  60. m_dataSource.Release();
  61. if (FAILED(hr = CreateView(CLSID_CSxApwStdoutView_brace_stringW, NULL)))
  62. goto Exit;
  63. if (FAILED(hr = dirSource->SetSite(this)))
  64. goto Exit;
  65. if (FAILED(hr = dirSource->RunQuery(L"C:\\*")))
  66. goto Exit;
  67. inStream.open("dbqueries.txt");
  68. if (!inStream.is_open())
  69. {
  70. hr = E_FAIL;
  71. goto Exit;
  72. }
  73. while (!inStream.eof())
  74. {
  75. std::string line;
  76. std::getline(inStream, line);
  77. if (line.empty())
  78. {
  79. break;
  80. }
  81. std::wstring wLine = MultiByteToWideChar(line);
  82. if (FAILED(hr = dbSource->SetSite(this)))
  83. goto Exit;
  84. if (FAILED(hr = dbSource->RunQuery(wLine.c_str())))
  85. goto Exit;
  86. }
  87. Exit:
  88. return hr;
  89. }
  90. int __cdecl main()
  91. {
  92. CoInitialize(NULL);
  93. _Module.Init(ObjectMap, GetModuleHandleW(NULL));
  94. ATL::CComObject<CSxApwHost> host;
  95. host.Main();
  96. return 0;
  97. }