shady
shady

Reputation: 1

IDISPATCH::Invoke to call a method fails with error 0x80020005 type mismatch

I am trying to call a mthod that takes 2 strings here you are the code

VARIANT vArgs[2];
                                            VariantInit(&vArgs[0]);
                                            VariantInit(&vArgs[1]);
                                            //VariantInit(&vArgs[2]);

                                    //vArgs[2].pdispVal = pDisptEntries;
                                    vArgs[1].bstrVal = bstrSrc;
                                    vArgs[0].bstrVal = bstrtrgt;

                                    vArgs[0].vt = VT_BSTR;
                                    vArgs[1].vt = VT_BSTR;
                                    //vArgs[2].vt = VT_DISPATCH;

                                    dpEntry.rgvarg = vArgs;
                                    dpEntry.cArgs = 2;
                                    dpEntry.cNamedArgs = 0;
                                    //dpEntry.rgdispidNamedArgs = new DISPID[2];
                                    //dpEntry.rgdispidNamedArgs[0] = 0;
                                    //dpEntry.rgdispidNamedArgs[1] = 1;

                                    UINT index = -1;
                                    EXCEPINFO   ex;

                                    hr = pDisptEntries->Invoke(dispid_Add, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, 
                                        &dpEntry, NULL, &ex, &index);

Upvotes: 0

Views: 2656

Answers (1)

Hans Passant
Hans Passant

Reputation: 941605

The error code unequivocally tells you that the function does not in fact take two arguments of type string. Getting the dispid wrong is possible too, it will call the wrong function. Watch out for the return value, not sure what happens when you pass NULL but the function returns a value.

Upvotes: 1

Related Questions