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.

154 lines
4.1 KiB

  1. // Copyright (c) 2000 Microsoft Corp.
  2. //
  3. // launches dhcp wizard from the dhcp snapin using mmc automation
  4. #include "headers.hxx"
  5. #include "resource.h"
  6. #include "smartptr.hpp"
  7. #include "misc.hpp"
  8. HINSTANCE hResourceModuleHandle = 0;
  9. HRESULT
  10. getContextMenu(const SmartInterface<View>& view, ContextMenu** dumbMenu)
  11. {
  12. HRESULT hr = S_OK;
  13. _variant_t missingParam2(DISP_E_PARAMNOTFOUND, VT_ERROR);
  14. hr = view->get_ScopeNodeContextMenu(missingParam2, dumbMenu);
  15. return hr;
  16. }
  17. HRESULT
  18. doIt()
  19. {
  20. HRESULT hr = S_OK;
  21. do
  22. {
  23. hr = ::CoInitialize(0);
  24. BREAK_ON_FAILED_HRESULT(hr, L"CoInitialize failed.");
  25. SmartInterface<_Application> app(0);
  26. hr =
  27. app.AcquireViaCreateInstance(
  28. CLSID_Application,
  29. 0,
  30. // we expect the object is out-of-proc, local server, but
  31. // we really don't care, so we'll take any implementation
  32. // available.
  33. CLSCTX_ALL);
  34. BREAK_ON_FAILED_HRESULT(hr, L"CoCreateInstance failed.");
  35. SmartInterface<Document> doc(0);
  36. Document* dumbDoc = 0;
  37. hr = app->get_Document(&dumbDoc);
  38. BREAK_ON_FAILED_HRESULT(hr, L"get_Document failed.");
  39. doc.Acquire(dumbDoc);
  40. SmartInterface<SnapIns> snapIns(0);
  41. SnapIns* dumbSnapIns = 0;
  42. hr = doc->get_SnapIns(&dumbSnapIns);
  43. BREAK_ON_FAILED_HRESULT(hr, L"get_SnapIns failed.");
  44. snapIns.Acquire(dumbSnapIns);
  45. static const wchar_t* DHCP_SNAPIN_CLSID =
  46. L"{90901AF6-7A31-11D0-97E0-00C04FC3357A}";
  47. SmartInterface<SnapIn> snapIn(0);
  48. SnapIn* dumbSnapIn = 0;
  49. _variant_t missingParam(DISP_E_PARAMNOTFOUND, VT_ERROR);
  50. _variant_t missingParam2(DISP_E_PARAMNOTFOUND, VT_ERROR);
  51. hr =
  52. snapIns->Add(AutoBstr(DHCP_SNAPIN_CLSID), missingParam, missingParam2, &dumbSnapIn);
  53. BREAK_ON_FAILED_HRESULT(hr, L"SnapIns::Add failed. Is DHCP installed?");
  54. snapIn.Acquire(dumbSnapIn);
  55. SmartInterface<Views> views(0);
  56. Views* dumbViews = 0;
  57. hr = doc->get_Views(&dumbViews);
  58. BREAK_ON_FAILED_HRESULT(hr, L"get_Views failed.");
  59. views.Acquire(dumbViews);
  60. SmartInterface<View> view(0);
  61. View* dumbView = 0;
  62. hr = views->Item(1, &dumbView);
  63. BREAK_ON_FAILED_HRESULT(hr, L"Views::Item failed.");
  64. view.Acquire(dumbView);
  65. SmartInterface<ScopeNamespace> sn(0);
  66. ScopeNamespace* dumbSn = 0;
  67. hr = doc->get_ScopeNamespace(&dumbSn);
  68. BREAK_ON_FAILED_HRESULT(hr, L"get_ScopeNamespace failed.");
  69. sn.Acquire(dumbSn);
  70. SmartInterface<Node> rootnode(0);
  71. Node* dumbNode = 0;
  72. hr = sn->GetRoot(&dumbNode);
  73. BREAK_ON_FAILED_HRESULT(hr, L"GetRoot failed.");
  74. rootnode.Acquire(dumbNode);
  75. SmartInterface<Node> child1(0);
  76. hr = sn->GetChild(rootnode, &dumbNode);
  77. BREAK_ON_FAILED_HRESULT(hr, L"GetChild failed.");
  78. child1.Acquire(dumbNode);
  79. hr = view->put_ActiveScopeNode(child1);
  80. BREAK_ON_FAILED_HRESULT(hr, L"put_ActiveScopeNode failed.");
  81. // have to read back the child node we just put...
  82. hr = view->get_ActiveScopeNode(&dumbNode);
  83. BREAK_ON_FAILED_HRESULT(hr, L"GetActiveScopeNode failed.");
  84. child1 = dumbNode;
  85. dumbNode->Release();
  86. dumbNode = 0;
  87. SmartInterface<Node> child2(0);
  88. hr = sn->GetChild(child1, &dumbNode);
  89. BREAK_ON_FAILED_HRESULT(hr, L"GetChild failed.");
  90. child2.Acquire(dumbNode);
  91. hr = view->put_ActiveScopeNode(child2);
  92. BREAK_ON_FAILED_HRESULT(hr, L"put_ActiveScopeNode failed.");
  93. // excute new scope wizard menu item
  94. _variant_t missingParam3(DISP_E_PARAMNOTFOUND, VT_ERROR);
  95. hr = view->ExecuteScopeNodeMenuItem((BSTR)AutoBstr(L"_CREATE_NEW_SCOPE"), missingParam3);
  96. BREAK_ON_FAILED_HRESULT(hr, L"ExecuteScopeNodeMenuItem _CREATE_NEW_SCOPE failed");
  97. hr = doc->Close(FALSE);
  98. BREAK_ON_FAILED_HRESULT(hr, L"Close failed.");
  99. }
  100. while (0);
  101. return hr;
  102. }
  103. int WINAPI
  104. WinMain(
  105. HINSTANCE hInstance,
  106. HINSTANCE /* hPrevInstance */ ,
  107. LPSTR /* lpszCmdLine */ ,
  108. int /* nCmdShow */ )
  109. {
  110. hResourceModuleHandle = hInstance;
  111. int exitCode = static_cast<int>(doIt());
  112. return exitCode;
  113. }