title: Call a method of CIM_DataFile object
body: <p>I got a <code>CIM_DataFile</code> object, received from a <code>WMI</code> query.</p>
  
  <p>I want to call a method of that object, for example <code>Delete</code> - I'm searching for days now and couldn't find an answer to how I do that in c++ (it is literally 4 lines in Python)</p>
  
  <p>This is my code so far, I'm successfully receiving the file <code>CIM_DataFile</code></p>
  
  <pre><code>#include &lt;Windows.h&gt;  
  #include &lt;iostream&gt;  
  #include &lt;WbemCli.h&gt;  
  
  #pragma comment(lib, "wbemuuid.lib")  
  
  int main()
  {
      using std::cout;
      using std::cin;
      using std::endl;
  
      HRESULT hRes = CoInitializeEx(NULL, COINIT_MULTITHREADED);
      if (FAILED(hRes))
      {
          cout &lt;&lt; "Unable to launch COM: 0x" &lt;&lt; std::hex &lt;&lt; hRes &lt;&lt; endl;
          return 1;
      }
  
      if ((FAILED(hRes = CoInitializeSecurity(NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_CONNECT, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE, 0))))
      {
          cout &lt;&lt; "Unable to initialize security: 0x" &lt;&lt; std::hex &lt;&lt; hRes &lt;&lt; endl;
          return 1;
      }
  
      IWbemLocator* pLocator = NULL;
      if (FAILED(hRes = CoCreateInstance(CLSID_WbemLocator, NULL, CLSCTX_ALL, IID_PPV_ARGS(&amp;pLocator))))
      {
          cout &lt;&lt; "Unable to create a WbemLocator: " &lt;&lt; std::hex &lt;&lt; hRes &lt;&lt; endl;
          return 1;
      }
  
      IWbemServices* pService = NULL;
      if (FAILED(hRes = pLocator-&gt;ConnectServer(L"root\\CIMV2", NULL, NULL, NULL, WBEM_FLAG_CONNECT_USE_MAX_WAIT, NULL, NULL, &amp;pService)))
      {
          pLocator-&gt;Release();
          cout &lt;&lt; "Unable to connect to \"CIMV2\": " &lt;&lt; std::hex &lt;&lt; hRes &lt;&lt; endl;
          return 1;
      }
  
      IEnumWbemClassObject* pEnumerator = NULL;
      if (FAILED(hRes = pService-&gt;ExecQuery(L"WQL", L"SELECT * FROM CIM_DataFile WHERE Name = \"C:\\\\deleteme.txt\"", WBEM_FLAG_FORWARD_ONLY, NULL, &amp;pEnumerator)))
      {
          pLocator-&gt;Release();
          pService-&gt;Release();
          cout &lt;&lt; "Unable to retrive CIM_DataFile: " &lt;&lt; std::hex &lt;&lt; hRes &lt;&lt; endl;
          return 1;
      }
  
      IWbemClassObject* clsObj = NULL;
      int numElems;
      while ((hRes = pEnumerator-&gt;Next(WBEM_INFINITE, 1, &amp;clsObj, (ULONG*)&amp;numElems)) != WBEM_S_FALSE)
      {
          if (FAILED(hRes))
              break;
  
          // HERE I SHOULD GET THE CIM_DataFile.DELETE METHOD SOMEHOW
  
          clsObj-&gt;Release();
      }
  
      pEnumerator-&gt;Release();
      pService-&gt;Release();
      pLocator-&gt;Release();
      return 0;
  }
  </code></pre>