Leaked source code of windows server 2003
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.

861 lines
22 KiB

  1. /*++
  2. Copyright (C) 1996-2001 Microsoft Corporation
  3. Module Name:
  4. METHOD.CPP
  5. Abstract:
  6. History:
  7. --*/
  8. #include "precomp.h"
  9. #include <stdio.h>
  10. //#include <wbemutil.h>
  11. //#include "wstring.h"
  12. #include "method.h"
  13. #include "wbemtest.h"
  14. #include "bstring.h"
  15. #include "wbemqual.h"
  16. #include "textconv.h"
  17. #include "genlex.h"
  18. #include "objpath.h"
  19. #include <cominit.h> // for SetInterfaceSecurityEx()
  20. #include <autoptr.h>
  21. extern DWORD gdwAuthLevel;
  22. extern DWORD gdwImpLevel;
  23. extern BSTR gpPrincipal;
  24. extern COAUTHIDENTITY* gpAuthIdentity;
  25. INT_PTR GetObjectPath(HWND hDlg, LPWSTR pStr, int nMax);
  26. #include "objedit.h"
  27. CMethodDlg::CMethodDlg(HWND hParent, LONG lGenFlags, LONG lSync, LONG lTimeout)
  28. : CWbemDialog(IDD_METHOD, hParent), m_pOutParams(NULL), m_pInParams(NULL),
  29. m_lGenFlags(lGenFlags), m_lSync(lSync), m_lTimeout(lTimeout)
  30. {
  31. m_Path[0] = 0;
  32. m_Class[0] = 0;
  33. m_pClass = NULL;
  34. m_bAtLeastOne = FALSE;
  35. m_bHasOutParam = FALSE;
  36. }
  37. CMethodDlg::~CMethodDlg()
  38. {
  39. if(m_pInParams) m_pInParams->Release();
  40. if(m_pClass)
  41. m_pClass->Release();
  42. if(m_pOutParams)
  43. m_pOutParams->Release();
  44. }
  45. BOOL CMethodDlg::OnInitDialog()
  46. {
  47. m_hMethodList = GetDlgItem(IDC_METHLIST);
  48. BOOL bRet = GetPath();
  49. if(!bRet)
  50. EndDialog(IDCANCEL);
  51. ResetButtons();
  52. return bRet;
  53. }
  54. void CMethodDlg::RunDetached(CRefCountable* pOwner)
  55. {
  56. SetOwner(pOwner);
  57. SetDeleteOnClose();
  58. Create(FALSE);
  59. }
  60. BOOL CMethodDlg::GetPath()
  61. {
  62. WCHAR wTemp[2048];
  63. wcscpy(wTemp, m_Path);
  64. INT_PTR dwRet = GetObjectPath(m_hDlg, wTemp, 2048);
  65. if(dwRet == IDOK)
  66. {
  67. if(wcslen(wTemp) < 1)
  68. {
  69. MessageBox(m_hDlg, IDS_CANT_GET_CLASS, IDS_ERROR, MB_OK | MB_ICONSTOP);
  70. return FALSE;
  71. }
  72. wcscpy(m_Path, wTemp);
  73. CObjectPathParser par;
  74. ParsedObjectPath *pOutput;
  75. int nRes = par.Parse(m_Path, &pOutput);
  76. if(nRes || pOutput == NULL || pOutput->m_pClass == NULL)
  77. {
  78. MessageBox(IDS_CANT_GET_CLASS, IDS_WARNING, MB_OK | MB_ICONSTOP);
  79. return FALSE;
  80. }
  81. wcscpy(m_Class, pOutput->m_pClass);
  82. if(m_pClass)
  83. {
  84. m_pClass->Release();
  85. m_pClass = NULL;
  86. }
  87. CBString bsPath = m_Class;
  88. SCODE sc = g_pNamespace->GetObject(bsPath.GetString(), m_lGenFlags, g_Context,
  89. &m_pClass, NULL);
  90. if(sc != S_OK)
  91. {
  92. FormatError(sc, m_hDlg, NULL);
  93. return FALSE;
  94. }
  95. // populate the combo box with methods.
  96. SendMessage(m_hMethodList, CB_RESETCONTENT, 0, 0);
  97. SendMessage(m_hMethodList, CB_SETCURSEL, -1, 0);
  98. m_bAtLeastOne = FALSE;
  99. if(sc == S_OK && m_pClass)
  100. {
  101. BSTR Name = NULL;
  102. m_pClass->BeginMethodEnumeration(0);
  103. while (m_pClass->NextMethod(0, &Name, NULL, NULL) == WBEM_S_NO_ERROR)
  104. {
  105. char buf[TEMP_BUF];
  106. wcstombs(buf, Name, TEMP_BUF);
  107. buf[TEMP_BUF-1] = '\0';
  108. SendMessage(m_hMethodList, CB_ADDSTRING, 0, LPARAM(buf));
  109. m_bAtLeastOne = TRUE;
  110. }
  111. if(m_bAtLeastOne)
  112. {
  113. SendMessage(m_hMethodList, CB_SETCURSEL, 0, 0);
  114. OnSelChange(0);
  115. }
  116. else
  117. {
  118. MessageBox(m_hDlg, IDS_CLASS_HAS_NO_METHODS, IDS_ERROR, MB_OK | MB_ICONSTOP);
  119. ResetButtons();
  120. return FALSE;
  121. }
  122. m_pClass->EndMethodEnumeration();
  123. }
  124. return TRUE;
  125. }
  126. else
  127. return FALSE;
  128. }
  129. BOOL CMethodDlg::OnCommand(WORD wNotifyCode, WORD nId)
  130. {
  131. switch(nId)
  132. {
  133. case IDC_EDITPATH:
  134. GetPath();
  135. break;
  136. case IDC_CLEAR:
  137. UpdateObjs();
  138. break;
  139. case IDC_EXECUTE:
  140. OnExecute();
  141. break;
  142. case IDC_EDITOUT:
  143. if(m_pOutParams != NULL)
  144. {
  145. IWbemClassObject* pNew;
  146. m_pOutParams->Clone(&pNew);
  147. CObjectEditor ed(m_hDlg, m_lGenFlags, CObjectEditor::readonly, m_lSync,
  148. pNew, m_lTimeout);
  149. ed.Run();
  150. pNew->Release();
  151. }
  152. break;
  153. case IDC_EDITIN:
  154. if(m_pInParams != NULL)
  155. {
  156. IWbemClassObject* pNew;
  157. m_pInParams->Clone(&pNew);
  158. CObjectEditor ed(m_hDlg, m_lGenFlags, CObjectEditor::readwrite, m_lSync,
  159. pNew, m_lTimeout);
  160. if(ed.Run() == IDOK)
  161. {
  162. m_pInParams->Release();
  163. m_pInParams = pNew;
  164. }
  165. }
  166. else
  167. {
  168. m_pInParams = _CreateInstance(m_hDlg, m_lGenFlags, m_lSync, m_lTimeout);
  169. }
  170. break;
  171. }
  172. ResetButtons();
  173. return TRUE;
  174. }
  175. void CMethodDlg::ResetButtons()
  176. {
  177. EnableWindow(GetDlgItem(IDC_CLEAR), (m_pInParams != NULL));
  178. EnableWindow(GetDlgItem(IDC_EXECUTE), (wcslen(m_Path)));
  179. EnableWindow(GetDlgItem(IDC_EDITIN), (m_pInParams != NULL));
  180. EnableWindow(GetDlgItem(IDC_EDITOUT), (m_pOutParams != NULL));
  181. char cTemp[2048];
  182. wcstombs(cTemp, m_Path, 2048);
  183. SetWindowText(GetDlgItem(IDC_OBJPATH), cTemp);
  184. }
  185. BOOL CMethodDlg::OnExecute()
  186. {
  187. // Get all the parameters
  188. // ======================
  189. if(wcslen(m_Path) == 0)
  190. {
  191. MessageBox(IDS_MUST_SPECIFY_PATH, IDS_ERROR, MB_OK | MB_ICONHAND);
  192. return FALSE;
  193. }
  194. if(wcslen(m_wsName) == 0)
  195. {
  196. MessageBox(IDS_MUST_SPECIFY_NAME, IDS_ERROR, MB_OK | MB_ICONHAND);
  197. return FALSE;
  198. }
  199. // Execute the method
  200. // ==================
  201. CBString bsPath(m_Path);
  202. CBString bsMethod(m_wsName);
  203. if(m_pOutParams)
  204. m_pOutParams->Release();
  205. m_pOutParams = NULL;
  206. HRESULT res;
  207. IWbemClassObject* pErrorObj = NULL;
  208. // Asynchronous
  209. if (m_lSync & ASYNC)
  210. {
  211. CHourGlass hg;
  212. CTestNotify* pNtfy = new CTestNotify(1);
  213. res = g_pNamespace->ExecMethodAsync(bsPath.GetString(), bsMethod.GetString(),
  214. WBEM_FLAG_SEND_STATUS,
  215. g_Context, m_pInParams, CUnsecWrap(pNtfy));
  216. if(SUCCEEDED(res))
  217. {
  218. pNtfy->WaitForSignal(INFINITE);
  219. res = pNtfy->GetStatusCode(&pErrorObj);
  220. if(SUCCEEDED(res))
  221. {
  222. CFlexArray* pArray = pNtfy->GetObjectArray();
  223. if(m_bHasOutParam && pArray && pArray->Size() > 0)
  224. {
  225. m_pOutParams = (IWbemClassObject*)pArray->GetAt(0);
  226. if (m_pOutParams)
  227. m_pOutParams->AddRef();
  228. }
  229. }
  230. }
  231. pNtfy->Release();
  232. }
  233. // Semisynchronous
  234. else if (m_lSync & SEMISYNC)
  235. {
  236. IWbemCallResult* pCallRes = NULL;
  237. CHourGlass hg;
  238. res = g_pNamespace->ExecMethod(bsPath.GetString(), bsMethod.GetString(),
  239. WBEM_FLAG_RETURN_IMMEDIATELY,
  240. g_Context, m_pInParams, (m_bHasOutParam) ? &m_pOutParams : NULL,
  241. &pCallRes);
  242. if (SUCCEEDED(res))
  243. {
  244. LONG lStatus;
  245. SetInterfaceSecurityEx(pCallRes, gpAuthIdentity, gpPrincipal, gdwAuthLevel, gdwImpLevel);
  246. while ((res = pCallRes->GetCallStatus(m_lTimeout, &lStatus)) == WBEM_S_TIMEDOUT)
  247. {
  248. // wait
  249. }
  250. if (res == WBEM_S_NO_ERROR)
  251. {
  252. res = (HRESULT)lStatus; // lStatus is the final result of the above IWbemServices::ExecMethod call
  253. if (m_bHasOutParam && res == WBEM_S_NO_ERROR)
  254. {
  255. res = pCallRes->GetResultObject(0, &m_pOutParams); // don't use timeout since object should be available
  256. }
  257. }
  258. pCallRes->Release();
  259. }
  260. }
  261. // Synchronous
  262. else
  263. {
  264. CHourGlass hg;
  265. res = g_pNamespace->ExecMethod(bsPath.GetString(), bsMethod.GetString(),
  266. 0,
  267. g_Context, m_pInParams, (m_bHasOutParam) ? &m_pOutParams : NULL,
  268. NULL);
  269. }
  270. if (FAILED(res))
  271. FormatError(res, m_hDlg, pErrorObj);
  272. else
  273. MessageBox(m_hDlg, IDS_STRING_METHOD_OK, IDS_WBEMTEST, MB_OK);
  274. return TRUE;
  275. }
  276. BOOL CMethodDlg::UpdateObjs()
  277. {
  278. SCODE sc;
  279. if(m_pClass == NULL)
  280. return FALSE;
  281. if(m_pInParams)
  282. {
  283. m_pInParams->Release();
  284. m_pInParams = NULL;
  285. }
  286. if(m_pOutParams)
  287. {
  288. m_pOutParams->Release();
  289. m_pOutParams = NULL;
  290. }
  291. sc = m_pClass->GetMethod((LPWSTR)m_wsName, 0, &m_pInParams, &m_pOutParams);
  292. m_bHasOutParam = (m_pOutParams != NULL);
  293. if(m_pOutParams)
  294. {
  295. m_pOutParams->Release();
  296. m_pOutParams = NULL;
  297. }
  298. return sc == S_OK;
  299. }
  300. BOOL CMethodDlg::OnSelChange(int nID)
  301. {
  302. if(m_pClass == NULL)
  303. return FALSE;
  304. LRESULT nIndex = SendMessage(m_hMethodList, CB_GETCURSEL, 0, 0);
  305. if (nIndex == LB_ERR)
  306. return FALSE;
  307. char buf[TEMP_BUF];
  308. *buf = 0;
  309. SendMessage(m_hMethodList, CB_GETLBTEXT, nIndex, LPARAM(buf));
  310. if (*buf == 0)
  311. return FALSE;
  312. m_wsName = buf;
  313. // Get the property value from the object
  314. // ======================================
  315. UpdateObjs();
  316. ResetButtons();
  317. return TRUE;
  318. }
  319. void CMethodEditor::OnAddQualifier()
  320. {
  321. CTestQualifier att;
  322. att.m_lType =
  323. WBEM_FLAVOR_FLAG_PROPAGATE_TO_INSTANCE |
  324. WBEM_FLAVOR_FLAG_PROPAGATE_TO_DERIVED_CLASS;
  325. CTestQualifierEditor ed(m_hDlg, &att, FALSE);
  326. INT_PTR nRes = ed.Edit();
  327. if ((nRes == IDCANCEL) || (nRes == 0))
  328. return;
  329. // If here, the Qualifier is being added.
  330. // ======================================
  331. IWbemQualifierSet* pQualifierSet = m_pTarget->m_pQualifiers;
  332. VARIANT *p = att.m_pValue->GetNewVariant();
  333. HRESULT hres = pQualifierSet->Put(att.m_pName, p, att.m_lType);
  334. if(FAILED(hres))
  335. {
  336. FormatError(hres, m_hDlg);
  337. }
  338. VariantClear(p);
  339. Refresh();
  340. }
  341. void CMethodEditor::SetSystemCheck(int nID)
  342. {
  343. SetCheck(IDC_NOT_NULL, BST_UNCHECKED);
  344. SetCheck(IDC_NORMAL, BST_UNCHECKED);
  345. SetCheck(nID, BST_CHECKED);
  346. }
  347. int CMethodEditor::RemoveSysQuals()
  348. {
  349. IWbemQualifierSet* pSet = m_pTarget->m_pQualifiers;
  350. HRESULT hres;
  351. hres = pSet->Delete(L"not_null");
  352. if(FAILED(hres) && hres != WBEM_E_NOT_FOUND)
  353. {
  354. SetSystemCheck(IDC_NOT_NULL);
  355. return IDC_NOT_NULL;
  356. }
  357. return 0;
  358. }
  359. void CMethodEditor::OnNotNull()
  360. {
  361. IWbemQualifierSet* pQualifierSet = m_pTarget->m_pQualifiers;
  362. int nRes = RemoveSysQuals();
  363. if(nRes != 0)
  364. {
  365. MessageBox(IDS_CANNOT_CHANGE_SYSTEM_QUALS, IDS_ERROR, MB_OK);
  366. return;
  367. }
  368. VARIANT v;
  369. V_VT(&v) = VT_BOOL;
  370. V_BOOL(&v) = VARIANT_TRUE;
  371. HRESULT hres = pQualifierSet->Put(L"not_null",
  372. &v,
  373. WBEM_FLAVOR_FLAG_PROPAGATE_TO_INSTANCE |
  374. WBEM_FLAVOR_FLAG_PROPAGATE_TO_DERIVED_CLASS);
  375. if(FAILED(hres))
  376. {
  377. MessageBox(IDS_MAY_NOT_SPECIFY_NOT_NULL, IDS_ERROR,
  378. MB_OK | MB_ICONSTOP);
  379. SetSystemCheck(IDC_NORMAL);
  380. }
  381. }
  382. void CMethodEditor::OnEditQualifier()
  383. {
  384. // See if anything is selected.
  385. // ============================
  386. LRESULT nSel = SendMessage(m_hQualifierList, LB_GETCURSEL, 0, 0);
  387. if (nSel == LB_ERR)
  388. return;
  389. int sizeRequired = SendMessage(m_hQualifierList, LB_GETTEXTLEN, nSel, 0);
  390. wmilib::auto_buffer<char> buf(new char[sizeRequired+1]);
  391. if (buf.get() == 0)
  392. return;
  393. SendMessage(m_hQualifierList, LB_GETTEXT, nSel, LPARAM(buf.get()));
  394. if (*buf.get() == 0)
  395. return;
  396. // At this point, the text of the selected Qualifier is in <buf>.
  397. // ==============================================================
  398. char name[TEMP_BUF];
  399. *name = 0;
  400. if (sscanf(buf.get(), "%[^\t\0]", name) == EOF)
  401. return;
  402. if (*name == 0)
  403. return;
  404. WString WName = name;
  405. // Find the Qualifier in question.
  406. // ===============================
  407. VARIANT v;
  408. VariantInit(&v);
  409. LONG lType = 0;
  410. IWbemQualifierSet* pQualifierSet = m_pTarget->m_pQualifiers;
  411. CBString bsWName(WName);
  412. SCODE res = pQualifierSet->Get(bsWName.GetString(), 0, &v, &lType);
  413. if (res != 0)
  414. {
  415. MessageBox(IDS_QUALIFIER_NOT_FOUND, IDS_CRITICAL_ERROR, MB_OK);
  416. return;
  417. }
  418. // If here, convert temporarily to a CTestQualifier object for the duration of
  419. // the edit.
  420. // ====================================================================
  421. CVar *pNewVal = new CVar;
  422. pNewVal->SetVariant(&v);
  423. VariantClear(&v);
  424. CTestQualifier att;
  425. att.m_pValue = pNewVal;
  426. att.m_pName = new wchar_t[wcslen(WName) + 1];
  427. wcscpy(att.m_pName, WName);
  428. att.m_lType = lType;
  429. CTestQualifierEditor ed(m_hDlg, &att, TRUE);
  430. INT_PTR nRes = ed.Edit();
  431. if ((nRes == IDCANCEL) || (nRes == 0))
  432. {
  433. return;
  434. }
  435. // If here, the Qualifier is being added.
  436. // ======================================
  437. VARIANT *p = att.m_pValue->GetNewVariant();
  438. CBString bsName(att.m_pName);
  439. res = pQualifierSet->Put(bsName.GetString(), p, att.m_lType);
  440. if(FAILED(res))
  441. {
  442. FormatError(res, m_hDlg);
  443. }
  444. VariantClear(p);
  445. Refresh();
  446. }
  447. //ok
  448. void CMethodEditor::OnDelQualifier()
  449. {
  450. // See if anything is selected.
  451. // ============================
  452. LRESULT nSel = SendMessage(m_hQualifierList, LB_GETCURSEL, 0, 0);
  453. if (nSel == LB_ERR)
  454. return;
  455. int sizeRequired = SendMessage(m_hQualifierList, LB_GETTEXTLEN, nSel, 0);
  456. wmilib::auto_buffer<char> buf(new char[sizeRequired+1]);
  457. if (buf.get() == 0)
  458. return;
  459. SendMessage(m_hQualifierList, LB_GETTEXT, nSel, LPARAM(buf.get()));
  460. if (*buf.get() == 0)
  461. return;
  462. // At this point, the text of the selected Qualifier is in <buf>.
  463. // ==============================================================
  464. char name[TEMP_BUF];
  465. *name = 0;
  466. if (sscanf(buf.get(), "%[^\t\0]", name) == EOF)
  467. return;
  468. if (*name == 0)
  469. return;
  470. WString WName = name;
  471. // Remove the Qualifier.
  472. // =====================
  473. IWbemQualifierSet *pQualifierSet = m_pTarget->m_pQualifiers;
  474. CBString bsName(WName);
  475. HRESULT hres = pQualifierSet->Delete(bsName.GetString());
  476. if(FAILED(hres) || hres != 0)
  477. {
  478. FormatError(hres, m_hDlg);
  479. }
  480. Refresh();
  481. }
  482. void CMethodEditor::Refresh()
  483. {
  484. // Zap the current contents.
  485. // =========================
  486. SendMessage(m_hQualifierList, LB_RESETCONTENT, 0, 0);
  487. SetCheck(IDC_NOT_NULL, BST_UNCHECKED);
  488. SetCheck(IDC_NORMAL, BST_CHECKED);
  489. EnableWindow(GetDlgItem(IDC_INPUT_ARGS), GetCheck(IDC_CHECKINPUT) == BST_CHECKED);
  490. EnableWindow(GetDlgItem(IDC_OUTPUT_ARGS), GetCheck(IDC_CHECKOUTPUT) == BST_CHECKED);
  491. // Fill in the Qualifier list.
  492. // ===========================
  493. IWbemQualifierSet *pQualifiers = m_pTarget->m_pQualifiers;
  494. if(pQualifiers == NULL)
  495. {
  496. EnableWindow(m_hQualifierList, FALSE);
  497. EnableWindow(GetDlgItem(IDC_NOT_NULL), FALSE);
  498. EnableWindow(GetDlgItem(IDC_NORMAL), FALSE);
  499. EnableWindow(GetDlgItem(IDC_ADD_ATTRIB), FALSE);
  500. EnableWindow(GetDlgItem(IDC_EDIT_ATTRIB), FALSE);
  501. EnableWindow(GetDlgItem(IDC_DELETE_ATTRIB), FALSE);
  502. EnableWindow(GetDlgItem(IDC_STATIC_QUAL), FALSE);
  503. }
  504. if (pQualifiers)
  505. {
  506. pQualifiers->BeginEnumeration(0);
  507. BSTR strName = NULL;
  508. long lFlavor;
  509. VARIANT vVal;
  510. VariantInit(&vVal);
  511. while(pQualifiers->Next(0, &strName, &vVal, &lFlavor) == S_OK)
  512. {
  513. if(!wbem_wcsicmp(strName, L"not_null"))
  514. {
  515. if(GetCheck(IDC_KEY) == BST_UNCHECKED &&
  516. GetCheck(IDC_INDEXED) == BST_UNCHECKED)
  517. {
  518. SetSystemCheck(IDC_NOT_NULL);
  519. }
  520. SysFreeString(strName);
  521. strName = NULL;
  522. continue;
  523. }
  524. CTestQualifier A;
  525. A.m_pName = new wchar_t[wcslen(strName)+1];
  526. wcscpy(A.m_pName, strName);
  527. A.m_pValue = new CVar(&vVal);
  528. A.m_lType = lFlavor;
  529. // Build list box string.
  530. // ======================
  531. LPSTR stringValue = CTestQualifierToString(&A);
  532. SendMessage(m_hQualifierList, LB_ADDSTRING, 0,LPARAM(stringValue));
  533. delete[] stringValue;
  534. VariantClear(&vVal);
  535. SysFreeString(strName);
  536. strName = NULL;
  537. }
  538. pQualifiers->EndEnumeration();
  539. VariantClear(&vVal);
  540. }
  541. }
  542. BOOL CMethodEditor::OnDoubleClick(int nID)
  543. {
  544. if(nID == IDC_ATTRIB_LIST)
  545. {
  546. OnEditQualifier();
  547. return TRUE;
  548. }
  549. return FALSE;
  550. }
  551. BOOL CMethodEditor::OnSelChange(int nID)
  552. {
  553. if(nID == IDC_TYPE_LIST)
  554. {
  555. char* pszType = GetCBCurSelString(IDC_TYPE_LIST);
  556. BOOL bArray = (GetCheck(IDC_ARRAY) == BST_CHECKED);
  557. m_pTarget->m_lType = StringToType(pszType);
  558. if(bArray)
  559. m_pTarget->m_lType |= VT_ARRAY;
  560. if((m_pTarget->m_lType & ~VT_ARRAY) == VT_EMBEDDED_OBJECT)
  561. {
  562. ShowWindow(GetDlgItem(IDC_EMBEDDING), SW_SHOW);
  563. }
  564. else
  565. {
  566. ShowWindow(GetDlgItem(IDC_EMBEDDING), SW_HIDE);
  567. }
  568. delete [] pszType;
  569. }
  570. return TRUE;
  571. }
  572. BOOL CMethodEditor::OnCommand(WORD wCode, WORD wID)
  573. {
  574. switch(wID)
  575. {
  576. case IDC_EDIT_ATTRIB: OnEditQualifier(); return TRUE;
  577. case IDC_ADD_ATTRIB: OnAddQualifier(); return TRUE;
  578. case IDC_DELETE_ATTRIB: OnDelQualifier(); return TRUE;
  579. case IDC_NOT_NULL:
  580. if(wCode == BN_CLICKED)
  581. OnNotNull();
  582. return TRUE;
  583. case IDC_NORMAL:
  584. if(wCode == BN_CLICKED)
  585. RemoveSysQuals();
  586. return TRUE;
  587. case IDC_INPUT_ARGS:
  588. ViewEmbedding(TRUE);
  589. return TRUE;
  590. case IDC_OUTPUT_ARGS:
  591. ViewEmbedding(FALSE);
  592. return TRUE;
  593. case IDC_CHECKINPUT:
  594. m_pTarget->m_bEnableInputArgs = (GetCheck(IDC_CHECKINPUT) == BST_CHECKED);
  595. Refresh();
  596. return TRUE;
  597. case IDC_CHECKOUTPUT:
  598. m_pTarget->m_bEnableOutputArgs = (GetCheck(IDC_CHECKOUTPUT) == BST_CHECKED);
  599. Refresh();
  600. return TRUE;
  601. }
  602. return TRUE;
  603. }
  604. BOOL CMethodEditor::OnInitDialog()
  605. {
  606. ShowWindow(GetDlgItem(IDC_EMBEDDING), SW_HIDE);
  607. CenterOnParent();
  608. m_hPropName = GetDlgItem(IDC_PROPNAME);
  609. m_hQualifierList = GetDlgItem(IDC_ATTRIB_LIST);
  610. SetCheck(IDC_CHECKINPUT, (m_pTarget->m_bEnableInputArgs) ? BST_CHECKED : BST_UNCHECKED);
  611. SetCheck(IDC_CHECKOUTPUT, (m_pTarget->m_bEnableOutputArgs) ? BST_CHECKED : BST_UNCHECKED);
  612. LONG Tabs[] = { 80, 120, 170 };
  613. int TabCount = 3;
  614. SendMessage(m_hQualifierList, LB_SETTABSTOPS,
  615. (WPARAM) TabCount, (LPARAM) Tabs);
  616. // Now initialize the controls with the contents of the
  617. // current object, if any.
  618. // ====================================================
  619. if (m_pTarget->m_pName)
  620. {
  621. SetWindowText(m_hPropName, LPWSTRToLPSTR(m_pTarget->m_pName));
  622. }
  623. if(m_pTarget->m_pClass)
  624. {
  625. SetDlgItemText(IDC_ORIGIN, LPWSTRToLPSTR(m_pTarget->m_pClass));
  626. }
  627. // Refresh the Qualifiers.
  628. // =======================
  629. Refresh();
  630. // If editing, don't allow type/name change.
  631. // =========================================
  632. if (m_bEditOnly)
  633. {
  634. EnableWindow(m_hPropName, FALSE);
  635. }
  636. if(m_bInstance)
  637. {
  638. EnableWindow(GetDlgItem(IDC_NOT_NULL), FALSE);
  639. EnableWindow(GetDlgItem(IDC_NORMAL), FALSE);
  640. }
  641. return TRUE;
  642. }
  643. void CMethodEditor::ViewEmbedding(BOOL bInput)
  644. {
  645. IWbemClassObject* pCurrentEmbed;
  646. if(bInput)
  647. pCurrentEmbed = m_pTarget->m_pInArgs;
  648. else
  649. pCurrentEmbed = m_pTarget->m_pOutArgs;
  650. IWbemClassObject* pEmbed;
  651. pCurrentEmbed->Clone(&pEmbed);
  652. // pCurrentEmbed->Release();
  653. CObjectEditor ed(m_hDlg, 0, CObjectEditor::readwrite | CObjectEditor::nomethods,
  654. SYNC, pEmbed);
  655. if(ed.Edit() == IDOK)
  656. {
  657. if(bInput)
  658. m_pTarget->m_pInArgs = pEmbed;
  659. else
  660. m_pTarget->m_pOutArgs = pEmbed;
  661. }
  662. else
  663. pEmbed->Release();
  664. }
  665. BOOL CMethodEditor::Verify()
  666. {
  667. char buf[TEMP_BUF];
  668. // Verify that name is present.
  669. // ============================
  670. if (GetWindowText(m_hPropName, buf, TEMP_BUF) == 0)
  671. {
  672. MessageBox(IDS_NO_METHOD_NAME, IDS_ERROR, MB_OK);
  673. return FALSE;
  674. }
  675. StripTrailingWs(buf);
  676. WString Name = buf;
  677. if (m_pTarget->m_pName)
  678. delete m_pTarget->m_pName;
  679. m_pTarget->m_pName = new wchar_t[wcslen(Name) + 1];
  680. wcscpy(m_pTarget->m_pName, Name);
  681. return TRUE;
  682. }
  683. CMethodEditor::CMethodEditor(
  684. HWND hParent,
  685. CTestMethod *pMethod,
  686. BOOL bEditOnly,
  687. BOOL bInstance
  688. ) : CWbemDialog(IDD_METHOD_EDITOR, hParent)
  689. {
  690. m_pTarget = pMethod;
  691. m_bEditOnly = bEditOnly;
  692. m_bInstance = bInstance;
  693. }
  694. INT_PTR CMethodEditor::Edit()
  695. {
  696. return Run();
  697. }