title: Implement IDispatch Interface for MFC automation
body: <p>I have a COM project which does not support MFC and needs to communicate with another App through a MFC interface.
  I cannot use directly in MFC interface with my COM project as it is not an MFC project.</p>
  <p>A solution was to create an automation interface for the Of the MFC interface which I would be able to use as a layer through which my COM project can communicate to the MFC project.</p>
  <p>As I understood, the automation app will run in a different thread. My COM project will invoke methods from the automation interface to call the MFC interface.</p>
  <p>The Automation project and its IDL file were provided to me and provides me with a Pure Dispinterface.</p>
  <p>Before integrating the implementation of the IDispatch interface to my COM project I decided to create a new C++ console project in order to focus on simply using the automation interface.
  Using the documentation provided by microsoft (<a href="https://docs.microsoft.com/en-us/previous-versions/windows/desktop/automat/implementing-the-idispatch-interface" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/previous-versions/windows/desktop/automat/implementing-the-idispatch-interface</a>) I implemented the IDispatch interface as follows:</p>
  <pre><code>#include &quot;TTAutomate.h&quot;
  
  HRESULT hresult;
  DISPID dispid;
  DISPPARAMS dispparamsNoArgs = { NULL, NULL, 0, 0 };
  EXCEPINFO excepinfo;
  UINT nArgErr;
  ClassFromIDL* m_ClassFromIDL;
  _DTTAutomateEvents* m_DTTAutomateEvents;
  _DTTAutomate* m_DTTAutomate;
  
  
  hresult = OleInitialize(NULL);
  
  // OLE function CoCreateInstance starts application using GUID.
  hresult = CoCreateInstance(CLSID_TTfromIDL, NULL, CLSCTX_INPROC_SERVER, DIID__DTTAutomateEvents, (LPVOID*)m_Automate);
  
  
  // Call QueryInterface to see if object supports IDispatch.
  hresult = m_ClassFromIDL-&gt;QueryInterface(DIID__DTTfromIDL, (LPVOID*)pdisp);
  
  // Retrieve the dispatch identifier for the SayHello method.
  // Use defaults where possible.
  OLECHAR* szMember = &quot;SayHello&quot;;
  DISPID dispid_Item;
  hresult = pdisp-&gt;GetIDsOfNames(
      IID_NULL,
      &amp;szFunction,
      1,
      LOCALE_USER_DEFAULT,
      &amp;dispid_Item);
  </code></pre>
  <p>First of all the implementation is a bit different as the one in the documentation because with the line :</p>
  <pre><code>hresult = CoCreateInstance(CLSID_Hello, NULL, CLSCTX_SERVER, IID_IUnknown, (void **)&amp;amp;punk);
  </code></pre>
  <p>I would get an error &quot;amp undefined&quot;.</p>
  <p>With the code above I currently get an error stating a <code>const char *</code> cannot initialize a <code>OLECHAR *</code>.</p>
  <p>On my COM project I have a line:</p>
  <pre><code>LPOLESTR szFunction = OLESTR(&quot;SayHello&quot;);
  </code></pre>
  <p>which compiles but the same line on my test project does not work.</p>
  <p>Did I miss some includes to add?
  Did I not create the right kind of test project?</p>