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.

59 lines
1.3 KiB

  1. //***************************************************************************
  2. //
  3. // UTILS.CPP
  4. //
  5. // Module: WMI Instance provider sample code
  6. //
  7. // Purpose: General purpose utilities.
  8. //
  9. // Copyright (c) 1997-1999 Microsoft Corporation
  10. //
  11. //***************************************************************************
  12. #include "stdpch.h"
  13. #pragma hdrstop
  14. //***************************************************************************
  15. //
  16. // CreateInst
  17. //
  18. // Purpose: Creates a new instance and sets
  19. // the inital values of the properties.
  20. //
  21. // Return: S_OK if all is well, otherwise an error code is returned
  22. //
  23. //***************************************************************************
  24. SCODE
  25. CreateInst(
  26. IWbemServices * pNamespace,
  27. IWbemClassObject ** pNewInst,
  28. WCHAR * pwcClassName,
  29. IWbemContext *pCtx)
  30. {
  31. SCODE sc;
  32. IWbemClassObject * pClass = NULL;
  33. sc = pNamespace->GetObject(pwcClassName, 0, pCtx, &pClass, NULL);
  34. if(sc != S_OK)
  35. return WBEM_E_FAILED;
  36. sc = pClass->SpawnInstance(0, pNewInst);
  37. pClass->Release();
  38. if(FAILED(sc))
  39. return sc;
  40. VARIANT v;
  41. // Set the key property value.
  42. v.vt = VT_I4;
  43. v.lVal = 0;
  44. sc = (*pNewInst)->Put(L"Id", 0, &v, 0);
  45. VariantClear(&v);
  46. return sc;
  47. }