error: 80070057 The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

1

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

Activator.CreateInstance(type)

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

Following is the IDL:

[
    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;
};

Following is the class declaration:

class ATL_NO_VTABLE CMyClass : 
public CComObjectRootEx<CComMultiThreadModel>,
public CComCoClass<CMyClass, &CLSID_MyClass>,
public IDispatchImpl<IMyClass, &IID_IMyClass, &LIBID_MyLib>
{
    STDMETHOD(MethodToInvoke)(WORD *pVal);
}

In order to invoke the above MethodToInvode I am trying the following code from a C# application:

 Type mytype = Type.GetTypeFromProgID("MyProgID.MyClass");
 object instance = Activator.CreateInstance(mytype);
 result = Convert.ToString(mytype .GetType().InvokeMember("MethodToInvoke", BindingFlags.InvokeMethod, null, instance, null));

I am getting following Exception on the line object instance = Activator.CreateInstance(mytype);

Exception: 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)).

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

c#
visual-c++
com
asked on Stack Overflow Dec 12, 2017 by Kalyani Manchu

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0