VS 2010: IDispatch::Invoke fails with DISP_E_BADCALLEE when called on Addin Instance object passed to OnConnection. RRS feed

  • Question

  • Hi!

    I'm trying to implement a simple C++ abstraction for a generic IDTExtensibility2-based addin with an option of supporting VisualStudio' family IDTCommandTarget interface.

    In order to support both addins: for MS Office and VisualStudio, I prefer to use late binding and get the value of AddInInst.ProgID property via IDispatch.

    This technique works perfectly in VS 7.1, VS 9.0 (I suppose, in VS 8.0 too), but fails with VS 10.0.

    In the following snippet:


    if (S_OK == instance->Invoke(3 /*get_ProgID*/, IID_NULL, 0, DISPATCH_PROPERTYGET, &dispparams, &vregid, NULL, &arg_error))
    	_regid = _bstr_t(vregid);

    Invoke returns DISP_E_BADCALLEE. Calling the same method using metadata object (ITypeInfo, got from the same 'instance') and passing 'instance' variable as 'pvInstance' according to http://msdn.microsoft.com/en-us/library/aa911675.aspx did help. Stepping into the assembly of IDispatch::Invoke method revealed that ATL thunks are used in the implementation, so that ITypeInfo::Invoke is being called with pvInstance decreased by 0x14, which, obviously, leads to a failed (misrouted) call.

    The implementation of IDispatch::Invoke resides inside '%Program Files%\Microsoft Visual Studio 10.0\Common7\IDE\msenv.dll' library.

    This behavior looks pretty much as a defect to me, so my question:

    Is this is a known defect and/or is it scheduled for a fix?


    Thank you,

    Artem Gevorkyan


    Monday, November 21, 2011 10:11 PM

All replies

  • Hello ,

    Thank you for your question.

    I am trying to involve someone familiar with this topic to further look at this issue. There might be some time delay. Appreciate your patience.

    Thank you for your understanding and support.


    Yi Feng Li [MSFT]
    MSDN Community Support | Feedback to us
    Wednesday, November 23, 2011 6:30 AM
  • Hi Artern,

    Can you provide the addin code? Without code, it is difficult to analyze the issue.



    Jacky Wu

    Friday, November 25, 2011 1:53 AM
  • Sure! Here goes the STR:

    1. Create New Project. Choose 'Extensibility'/'Visual Studio Add-in' project type;

    2. Project Wizard page #1: Use 'Create an Add-in using Visual C++ / ATL' option;

    3. Project Wizard page #2: Omit support of VS 2010 Macros;

    4. You may left preferences intact in the remained pages.

    5. In the resulted skeleton code inject the following snippet into the body of OnConnection method (file: Connect.cpp):


    DISPPARAMS params = { 0 };
    CComVariant result;
    UINT error_argument = 0;
    HRESULT hr = pAddInInst->Invoke(3 /*get_ProgID*/, IID_NULL, 0, DISPATCH_PROPERTYGET, &params, &result, NULL, &error_argument);
    ATLASSERT(S_OK == hr && VT_BSTR == result.vt && CComBSTR(result.bstrVal) != L"");
    return S_OK;


    When the addin is loaded into VS 2010 You will have an assertion. 'hr' will have value of DISP_E_BADCALLEE.

    You will not have an assertion when the addin loaded into VS 2008, provided that you have added an appropriate script lines to AddIn.rgs. Here they go (you have to insert them at the same level as for version 10.0):


    NoRemove '9.0'
    	NoRemove 'AddIns'
    		ForceRemove 'MyAddin1.Connect'
    			val LoadBehavior = d 0
    			val CommandLineSafe = d 0
    			val CommandPreload = d 0
    			val FriendlyName = s 'MyAddin1 - No Name provided.'
    			val Description = s 'MyAddin1 - No Description provided.'




    P.S. Use 'Tools/Add-in Manager...' in the main menu to load the addin. Place a checkbox in front of the addin you created and registered.

    • Edited by Arty_G Friday, November 25, 2011 10:13 AM
    Friday, November 25, 2011 10:10 AM
  • Hi Artern,

    I can reproduce this issue with your project create steps, and seems that there are really difference between vs2008 and vs2010 implementation. However, need more time to figure out cause.



    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. Regards, Jacky Wu Microsoft Online Community Support
    Tuesday, November 29, 2011 2:02 AM
  • It is likely the same bug talked about here, there is no work around I am aware of (certainly not one that would make code that would be usable in Office and VS) and the fix was not included in the SP.


    Tuesday, November 29, 2011 7:00 AM
  • Hi,

    Is there a fix for this issue yet by MS? or is there a work around for this?.

    Please let me know as i am stuck with this . we r trying to reuse existing C++ (3.5) code in our 4.0 .net app & it doesnt work.

    Wednesday, May 15, 2013 9:42 AM