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 "_IID_CanvasShapes"
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" rename_namespace("Office") named_guids
using namespace Office;
#import "C:\Program Files\Microsoft Office\Office10\MSWORD.olb" rename("ExitWindows", "WordExitWindows"), named_guids, raw_interfaces_only
using namespace Word;
-----------------------------------------------------------------------------------
My stdafx.cpp looks like this:
#include "stdafx.h"
#ifdef _ATL_STATIC_REGISTRY
#include
#include
#endif
#include
-----------------------------------------------------------------------------------
my addin.h looks like this:
#ifndef __ADDIN_H_
#define __ADDIN_H_
#include "resource.h" // main symbols
#import "C:\Program Files\Common Files\Designer\MSADDNDR.DLL" raw_interfaces_only, raw_native_types, no_namespace, named_guids
/////////////
extern _ATL_FUNC_INFO OnClickButtonInfo;
class ATL_NO_VTABLE CAddin :
public CComObjectRootEx<CComSingleThreadModel>,
public CComCoClass<CAddin, &CLSID_Addin>,
public ISupportErrorInfo,
public IDispatchImpl<IAddin, &IID_IAddin, &LIBID_WORDADDINLib>,
public IDispatchImpl<_IDTExtensibility2, &IID__IDTExtensibility2, &LIBID_AddInDesignerObjects>,
public IDispEventSimpleImpl<1, CAddin, &__uuidof(Office::_CommandBarButtonEvents)>
{
public:
typedef IDispEventSimpleImpl</*nID =*/ 1,CAddin, &__uuidof(Office::_CommandBarButtonEvents)> CommandButton1Events;
CAddin()
{
}
DECLARE_REGISTRY_RESOURCEID(IDR_ADDIN)
DECLARE_PROTECT_FINAL_CONSTRUCT()
BEGIN_COM_MAP(CAddin)
COM_INTERFACE_ENTRY(IAddin)
//DEL COM_INTERFACE_ENTRY(IDispatch)
COM_INTERFACE_ENTRY(ISupportErrorInfo)
COM_INTERFACE_ENTRY2(IDispatch, IAddin)
COM_INTERFACE_ENTRY(_IDTExtensibility2)
END_COM_MAP()
BEGIN_SINK_MAP(CAddin)
SINK_ENTRY_INFO(1, __uuidof(Office::_CommandBarButtonEvents), /*dispid*/0x01, OnClickButton, &OnClickButtonInfo)
END_SINK_MAP()
// 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(VARIANT_TRUE);
CComVariant vEmpty(DISP_E_PARAMNOTFOUND, VT_ERROR);
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);
_bstr_t bstrNewCaption(OLESTR("Item1"));
_bstr_t bstrTipText(OLESTR("Tooltip for Item 1"));
CComQIPtr <Office::_CommandBarButton> spCmdButton(spNewBar);
ATLASSERT(spCmdButton);
HBITMAP hBmp = (HBITMAP)::LoadImage(_Module.GetResourceInstance() ,
MAKEINTRESOURCE(IDB_BITMAP1), IMAGE_BITMAP, 0, 0, LR_LOADMAP3DCOLORS);
::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(VARIANT_TRUE);
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;
_bstr_t 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(DISP_E_PARAMNOTFOUND, VT_ERROR);
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(VARIANT_TRUE);
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
*)m_spButton);
if(FAILED(hr))
return hr;
}
return S_OK;
}
STDMETHOD(OnAddInsUpdate)(SAFEARRAY * * custom)
{
return E_NOTIMPL;
}
STDMETHOD(OnStartupComplete)(SAFEARRAY * * custom)
{
return E_NOTIMPL;
}
STDMETHOD(OnBeginShutdown)(SAFEARRAY * * custom)
{
return E_NOTIMPL;
}
private:
CComPtr<Office::_CommandBarButton> m_spButton;
bool bConnected;
};
#endif //__ADDIN_H_
------------------------------------------------------------------------------------
my addin.cpp file looks like:
// Addin.cpp : Implementation of CAddin
#include "stdafx.h"
#include "WordAddin.h"
#include "Addin.h"
/////////////////////////////////////////////////////////////////////////////
// CAddin
_ATL_FUNC_INFO OnClickButtonInfo ={CC_STDCALL,VT_EMPTY,2,{VT_DISPATCH,VT_BYREF | VT_BOOL}};
STDMETHODIMP CAddin::InterfaceSupportsErrorInfo(REFIID riid)
{
static const IID* arr[] =
{
&IID_IAddin
};
for (int i=0; i < sizeof(arr) / sizeof(arr[0]); i++)
{
if (InlineIsEqualGUID(*arr[i],riid))
return S_OK;
}
return S_FALSE;
}
void __stdcall CAddin::OnClickButton(IDispatch* /*Office::_CommandBarButton* */ Ctrl,VARIANT_BOOL * 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);
}