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.

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