title: .net UIAutomation simple example in C++
body: <p>I am going through <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ee671406%28v=vs.85%29.aspx" rel="nofollow noreferrer">UIAuomation Clients API</a> in .Net and have to use C++ instead of C#. This is because the <a href="http://msdn.microsoft.com/en-us/library/ms646310%28VS.85%29.aspx" rel="nofollow noreferrer">SendInput</a> function is only available in C++ and seems to be the most reliable method of sending mouse clicks to any application (same problem as this question: <a href="https://stackoverflow.com/questions/14230985/how-to-manipulate-a-control-without-any-pattern-implemented">How to manipulate a control without any pattern implemented?</a>).</p>
  
  <p>Right now I am struggling with the C++ version of UIAutomation API because of the lack of documentation on msdn. Can someone tell how to create a PropertyCondition using <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ee671529%28v=vs.85%29.aspx" rel="nofollow noreferrer">CreatePropertyCondition</a>, UIA_NamePropertyId and "Windows Media Player".</p>
  
  <pre><code>char *name = new char[30];
  strcpy(name, "Windows Media Player");
  VARIANT vt;
  vt.vt = VT_CARRAY; // This is probably wrong
  vt.pcVal = name;
  hr = g_pAutomation-&gt;CreatePropertyCondition(UIA_NamePropertyId, vt, &amp;condition);
  if(!SUCCEEDED(hr)){
      printf("Cannot createpropertycondition in getWMP\n");
      return hr;
  }
  </code></pre>
  
  <p>I am always going inside the <code>if</code> condition. the <code>g_pAutomation</code> variable is working fine, I am able to get the RootElement fine.</p>
  
  <p>Also a link to a simple tutorial/sample (in C++) will be really useful.</p>
  
  <p>Thanks</p>