COM link error

  • 18 years ago

    Hello All, thanks for reading this and for any help you may provide. I am having a problem, I used the "Building Office 2K Addins" article as a guide and I am trying to automate MS Word but I keep getting a compiler error. The error is:


    StdAfx.obj : fatal error LNK1179: invalid or corrupt file: duplicate comdat "IIDCanvasShapes"


    I cannot figure out why I keep getting this link error. I am not sure what is causing this. Does any have any idea that may work, it works in the article but not for me. I have included a lot of the code, if anyone needs to see more, just let me know. I am in desperate need and am clueless!!!!


    Why would I be getting error. I cannot get around it! PLEASE HELP!!!!



    Instead of importing Outlook, I am trying to import Word in the stdafx.h:


    import "C:\Program Files\Common Files\Microsoft Shared\Office10\mso.dll" renamenamespace("Office") namedguids


    using namespace Office;


    import "C:\Program Files\Microsoft Office\Office10\MSWORD.olb" rename("ExitWindows", "WordExitWindows"), namedguids, rawinterfaces_only


    using namespace Word;



    My stdafx.cpp looks like this:


    include "stdafx.h"



    ifdef ATLSTATIC_REGISTRY


    include


    include


    endif



    include




    my addin.h looks like this:


    ifndef _ADDINH_


    define _ADDINH_



    include "resource.h" // main symbols


    import "C:\Program Files\Common Files\Designer\MSADDNDR.DLL" rawinterfacesonly, rawnativetypes, nonamespace, namedguids



    /////////////
    extern ATLFUNC_INFO OnClickButtonInfo;



    class ATLNOVTABLE CAddin :
    public CComObjectRootEx<CComSingleThreadModel>,
    public CComCoClass<CAddin, &CLSIDAddin>,
    public ISupportErrorInfo,
    public IDispatchImpl<IAddin, &IID
    IAddin, &LIBIDWORDADDINLib>,
    public IDispatchImpl<
    IDTExtensibility2, &IIDIDTExtensibility2, &LIBIDAddInDesignerObjects>,
    public IDispEventSimpleImpl<1, CAddin, &
    uuidof(Office::CommandBarButtonEvents)>
    {
    public:
    typedef IDispEventSimpleImpl</nID =/ 1,CAddin, &_uuidof(Office::CommandBarButtonEvents)> CommandButton1Events;
    CAddin()
    {
    }


    DECLAREREGISTRYRESOURCEID(IDR_ADDIN)


    DECLAREPROTECTFINAL_CONSTRUCT()


    BEGINCOMMAP(CAddin)
    COMINTERFACEENTRY(IAddin)
    //DEL COMINTERFACEENTRY(IDispatch)
    COMINTERFACEENTRY(ISupportErrorInfo)
    COMINTERFACEENTRY2(IDispatch, IAddin)
    COMINTERFACEENTRY(IDTExtensibility2)
    END
    COM_MAP()


    BEGINSINKMAP(CAddin)
    SINKENTRYINFO(1, _uuidof(Office::CommandBarButtonEvents), /dispid/0x01, OnClickButton, &OnClickButtonInfo)
    ENDSINKMAP()


    // ISupportsErrorInfo
    STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);
    void _stdcall OnClickButton(IDispatch * /* Office::CommandBarButton**/ Ctrl, VARIANT_BOOL * CancelDefault);


    // IAddin
    public:
    // IDTExtensibility2
    STDMETHOD(OnConnection)(IDispatch * Application, ext
    ConnectMode ConnectMode, IDispatch * AddInInst, SAFEARRAY * * custom)
    {
    CComPtr < Office::_CommandBars> spCmdBars;
    CComPtr < Office::CommandBar> spCmdBar;


    CComQIPtr <Word::_Application> spApp(Application);
    ATLASSERT(spApp);


    spApp->get_CommandBars(&spCmdBars);


    ATLASSERT(spCmdBars);


    CComVariant vName("PSI Button");
    CComPtr <Office::CommandBar> spNewCmdBar;


    CComVariant vPos(1);


    CComVariant vTemp(VARIANTTRUE);
    CComVariant vEmpty(DISP
    EPARAMNOTFOUND, VTERROR);


    spNewCmdBar = spCmdBars->Add(vName, vPos, vEmpty, vTemp);
    CComPtr <Office::CommandBarControls> spBarControls;
    ATLASSERT(spBarControls);


    CComVariant vToolBarType(1);


    CComVariant vShow(VARIANT_TRUE);


    CComPtr < Office::CommandBarControl> spNewBar;


    spNewBar = spBarControls->Add(vToolBarType, vEmpty, vEmpty, vShow);
    ATLASSERT(spNewBar);


    bstrt bstrNewCaption(OLESTR("Item1"));
    bstrt bstrTipText(OLESTR("Tooltip for Item 1"));


    CComQIPtr <Office::_CommandBarButton> spCmdButton(spNewBar);


    ATLASSERT(spCmdButton);


    HBITMAP hBmp = (HBITMAP)::LoadImage(Module.GetResourceInstance(),
    MAKEINTRESOURCE(IDB
    BITMAP1), IMAGEBITMAP, 0, 0, LRLOADMAP3DCOLORS);


    ::OpenClipboard(NULL);
    ::EmptyClipboard();
    ::SetClipboardData(CF_BITMAP, (HANDLE)hBmp);
    ::CloseClipboard();
    :eleteObject(hBmp);


    spCmdButton->PutStyle(Office::msoButtonIconAndCaption);


    HRESULT hr = spCmdButton->PasteFace();
    if(FAILED(hr))
    return hr;


    spCmdButton->PutVisible(VARIANTTRUE);
    spCmdButton->PutCaption(OLESTR("Item 1"));
    spCmdButton->PutEnabled(VARIANT
    TRUE);
    spCmdButton->PutTooltipText(OLESTR("Tooltip for Item1"));
    spCmdButton->PutTag(OLESTR("Tag for Item 1"));


    spNewCmdBar->PutVisible(VARIANT_TRUE);


    m_spButton = spCmdButton;


    bstrt bstrNewMenuText(OLESTR("Menu Item 1"));


    CComPtr <Office::CommandBarControls> spCmdCtrls;
    CComPtr <Office::CommandBarControls> spCmdBarCtrls;
    CComPtr <Office::CommandBarPopup> spCmdPopup;
    CComPtr <Office::CommandBarControl> spCmdCtrl;


    hr = spCmdBars->get_ActiveMenuBar(&spCmdBar);


    if(FAILED(hr))
    return hr;


    spCmdCtrls = spCmdBar->GetControls();
    ATLASSERT(spCmdCtrls);


    CComVariant vItem(5);
    spCmdCtrl = spCmdCtrls->GetItem(vItem);
    ATLASSERT(spCmdCtrl);


    IDispatchPtr spDisp;


    spDisp = spCmdCtrl->GetControl();


    CComQIPtr <Office::CommandBarPopup> ppCmdPopup(spDisp);
    ATLASSERT(ppCmdPopup);


    spCmdBarCtrls = ppCmdPopup->GetControls();
    ATLASSERT(spCmdBarCtrls);


    CComVariant vMenuType(1);
    CComVariant vMenuPos(6);
    CComVariant vMenuEmpty(DISPEPARAMNOTFOUND, VTERROR);
    CComVariant vMenuShow(VARIANT
    TRUE);
    CComVariant vMenuTemp(VARIANT_TRUE);


    CComPtr <Office::CommandBarControl> spNewMenu;


    spNewMenu = spCmdBarCtrls->Add(vMenuType, vMenuEmpty, vMenuEmpty, vMenuEmpty, vMenuTemp);
    ATLASSERT(spNewMenu);


    spNewMenu->PutCaption(bstrNewMenuText);
    spNewMenu->PutEnabled(VARIANTTRUE);
    spNewMenu->PutVisible(VARIANT
    TRUE);


    CComQIPtr <Office::_CommandBarButton> spCmdMenuButton(spNewMenu);
    ATLASSERT(spCmdMenuButton);


    spCmdMenuButton->PutStyle(Office::msoButtonIconAndCaption);


    spCmdMenuButton->PasteFace();
    spNewMenu->PutVisible(VARIANT_TRUE);


    hr = CommandButton1Events:ispEventAdvise((IDispatch*)


    m_spButton);
    if(FAILED(hr))
    return hr;


    bConnected = true;


    return S_OK;




    }


    STDMETHOD(OnDisconnection)(ext_DisconnectMode RemoveMode, SAFEARRAY * * custom)
    {
    if(bConnected)
    {
    HRESULT hr = CommandButton1Events:ispEventUnadvise((IDispatch


    *)mspButton);
    if(FAILED(hr))
    return hr;
    }
    return S
    OK;
    }


    STDMETHOD(OnAddInsUpdate)(SAFEARRAY * * custom)
    {
    return ENOTIMPL;
    }
    STDMETHOD(OnStartupComplete)(SAFEARRAY * * custom)
    {
    return E
    NOTIMPL;
    }
    STDMETHOD(OnBeginShutdown)(SAFEARRAY * * custom)
    {
    return ENOTIMPL;
    }
    private:
    CComPtr<Office::
    CommandBarButton> m_spButton;
    bool bConnected;
    };


    endif //_ADDINH_




    my addin.cpp file looks like:


    // Addin.cpp : Implementation of CAddin

    include "stdafx.h"


    include "WordAddin.h"


    include "Addin.h"



    /////////////////////////////////////////////////////////////////////////////
    // CAddin
    ATLFUNCINFO OnClickButtonInfo ={CCSTDCALL,VTEMPTY,2,{VTDISPATCH,VTBYREF | VTBOOL}};


    STDMETHODIMP CAddin::InterfaceSupportsErrorInfo(REFIID riid)
    {
    static const IID* arr[] =
    {
    &IIDIAddin
    };
    for (int i=0; i < sizeof(arr) / sizeof(arr[0]); i++)
    {
    if (InlineIsEqualGUID(*arr,riid))
    return S
    OK;
    }
    return S_FALSE;
    }


    void _stdcall CAddin::OnClickButton(IDispatch* /*Office::CommandBarButton* */ Ctrl,VARIANTBOOL * CancelDefault)
    {
    USES
    CONVERSION;
    CComQIPtr<Office::CommandBarButton> pCommandBarButton(Ctrl);
    //the button that raised the event. Do something with this...
    // MessageBox(NULL, "Clicked Button1", "OnClickButton", MB
    OK);


    }


Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Linux is only free if your time has no value” - Jamie Zawinski