title: error: 80070057 The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
body: <p>I have a requirement where I need to get a result out of a C++ Unmanaged dll's method from C#. I am trying to create an instance to the class type and then try to invoke the method using</p>
  
  <pre><code>Activator.CreateInstance(type)
  </code></pre>
  
  <p>The unmanaged dll is a COM DLL, I can't modify that, I have to just use it. Also I don't have an interop to that COM DLL, I am not sure whether I need to have one or ask someone to create it. Following is the sample declaration present there</p>
  
  <p>Following is the IDL:</p>
  
  <pre><code>[
      object,
      uuid(XXXX-XXXX-XXXX-XX-XXXXXXXX),
      dual,
      helpstring("IMyClass Interface"),
      pointer_default(unique)
  ]
  interface IMyClass : IDispatch
  {
      ....
      id(100), helpstring("My Help String")]
      HRESULT MethodToInvoke([out, retval] unsigned short *pVal);
      ....
  }
  
  library MyLib
  {
  importlib("stdole32.tlb");
  importlib("stdole2.tlb");
  [
      uuid(XXXXX-XXXXX-XXXX-XXXX-XXXXX),
      helpstring("MyClass")
  ]
  coclass MyClass
  {
      [default] interface IMyClass;
  };
  </code></pre>
  
  <p></p>
  
  <p>Following is the class declaration:</p>
  
  <pre><code>class ATL_NO_VTABLE CMyClass : 
  public CComObjectRootEx&lt;CComMultiThreadModel&gt;,
  public CComCoClass&lt;CMyClass, &amp;CLSID_MyClass&gt;,
  public IDispatchImpl&lt;IMyClass, &amp;IID_IMyClass, &amp;LIBID_MyLib&gt;
  {
      STDMETHOD(MethodToInvoke)(WORD *pVal);
  }
  </code></pre>
  
  <p>In order to invoke the above <code>MethodToInvode</code> I am trying the following code from a C# application:</p>
  
  <pre><code> Type mytype = Type.GetTypeFromProgID("MyProgID.MyClass");
   object instance = Activator.CreateInstance(mytype);
   result = Convert.ToString(mytype .GetType().InvokeMember("MethodToInvoke", BindingFlags.InvokeMethod, null, instance, null));
  </code></pre>
  
  <p>I am getting following Exception on the line <code>object instance = Activator.CreateInstance(mytype);</code></p>
  
  <p>Exception:
  <code>
  Creating an instance of the COM component with CLSID {XXXXX-XXX-XXX-XXXX-XXXXXX} from the IClassFactory failed due to the following error: 80070057 The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG)).
  </code></p>
  
  <p>Please let me know whether what I am trying is achievable, if it is achievable, what all I should verify to make sure mine works. Thanks in advance</p>