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

0

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);
c++
com
asked on Stack Overflow Mar 28, 2011 by shady • edited Mar 28, 2011 by Felice Pollano

1 Answer

1

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.

answered on Stack Overflow Mar 28, 2011 by Hans Passant

User contributions licensed under CC BY-SA 3.0