Click here to Skip to main content
15,915,734 members
Home / Discussions / COM
   

COM

 
GeneralRe: Ref to ActiveX control using C Pin
Amit Dey1-Jul-02 6:44
Amit Dey1-Jul-02 6:44 
QuestionActiveX is "unsafe" huh? Pin
Philip Patrick22-Jun-02 6:08
professionalPhilip Patrick22-Jun-02 6:08 
AnswerRe: ActiveX is "unsafe" huh? Pin
Michael Dunn22-Jun-02 6:50
sitebuilderMichael Dunn22-Jun-02 6:50 
GeneralDCom-security question.... Pin
stefanb22-Jun-02 5:27
stefanb22-Jun-02 5:27 
GeneralRe: DCom-security question.... Pin
Jason Henderson24-Jun-02 9:20
Jason Henderson24-Jun-02 9:20 
GeneralRe: DCom-security question.... Pin
stefanb24-Jun-02 9:58
stefanb24-Jun-02 9:58 
GeneralThis one is easy! Pin
Al_Pennyworth21-Jun-02 8:24
Al_Pennyworth21-Jun-02 8:24 
GeneralDifferent Kind of problem Pin
Al_Pennyworth20-Jun-02 8:46
Al_Pennyworth20-Jun-02 8:46 
Hey, I know I posted a message about a problem not too long ago but I am working on a different approach and I ran into some trouble. I am trying to capture the event and I tried to use the Building Office2k Addin as a guide. I had a problem with the last approach so I tried to rework it. No luck, now I am getting the message:

error C2787: '_CommandBarButtonEvents' : no GUID has been associated with this object

My Addin.h file looks like this:

// Addin.h : Declaration of the CAddin

#ifndef __ADDIN_H_
#define __ADDIN_H_

#include "resource.h" // main symbols
#include "mso.h"
#include "msword.h"
#import "C:\Program Files\Common Files\Designer\MSADDNDR.DLL" raw_interfaces_only, raw_native_types, no_namespace, named_guids

/////////////////////////////////////////////////////////////////////////////
// CAddin
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_autoproject3lib="">,
public IDispatchImpl<_IDTExtensibility2, &IID__IDTExtensibility2, &LIBID_AddInDesignerObjects>,
public IDispEventSimpleImpl<1, CAddin, &__uuidof(Office::_CommandBarButtonEvents)>
{
public:
typedef IDispEventSimpleImpl 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)
{
COleVariant covTrue((short) TRUE),
covFalse((short) FALSE),
covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);

Word::_Application Wordapp;
Office::_CommandBars oBars = Wordapp.GetCommandBars(); // New CommandBars
// collection object

Office::CommandBar oBar;
Office::CommandBarControls oControls;
Office::_CommandBarButton oButton;

VARIANT vName;
vName.vt = VT_BSTR;
vName.bstrVal = SysAllocString(L"PSI");

VARIANT vPosition;
vPosition.vt = VT_I2;
vPosition.iVal = 1; // 4 = Floating; 0 = top;

// Add new bar to the command bars collection
Office::CommandBar oNewBar = oBars.Add(vName, // const Variant Name
vPosition, // const Variant Position
covFalse, // const Variant (replace)MenuBar
covTrue // const Variant Temporary
);

oNewBar.SetVisible(TRUE);

// Get the collection (now empty) of controls on the new commandbar
Office::CommandBarControls oNewControls = oNewBar.GetControls();

VARIANT vType;
vType.vt = VT_I4;
vType.lVal = (long)1;

Office::_CommandBarButton oNewButton1 = // Office XP - note leading underscore
oNewControls.Add(vType, // Type = msoControlButton
covOptional, // Id
covOptional, // Parameter
covOptional, // Before
covTrue // Temporary
);

oNewButton1.SetStyle(3); // msoButtonIconAndCaption
oNewButton1.SetCaption("PSI Save & Exit");
oNewButton1.SetTooltipText("This is a new button");
oNewButton1.SetVisible(TRUE);
oNewButton1.SetState(0); // msoButtonUp

OpenClipboard(NULL); // Reserve clipboard for this program

CBitmap MyBitmap;
MyBitmap.LoadBitmap(IDB_BITMAP1); // A Bitmap you drew in the
// Resource Editor
HBITMAP MyBitmapHandle = (HBITMAP)MyBitmap; // Cast it to a HBITMAP
SetClipboardData(CF_BITMAP, MyBitmapHandle);
CloseClipboard(); // Free clipboard so PasteFace() can use it

oNewButton1.PasteFace();

hr = CommandButton1Events::DispEventAdvise((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::DispEventUnadvise((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:
Office::_CommandBarButton m_spButton;
bool bConnected;
// _IDTExtensibility2
};

#endif //__ADDIN_H_


I am new to COM/ATL programming and I am getting confused. Can Anyone Help!!!
QuestionAny Idea? Pin
Al_Pennyworth20-Jun-02 4:27
Al_Pennyworth20-Jun-02 4:27 
AnswerRe: Any Idea? Pin
Rama Krishna Vavilala20-Jun-02 8:02
Rama Krishna Vavilala20-Jun-02 8:02 
GeneralRe: Any Idea? Pin
Al_Pennyworth24-Jun-02 7:05
Al_Pennyworth24-Jun-02 7:05 
AnswerRe: Any Idea? Pin
Amit Dey1-Jul-02 3:35
Amit Dey1-Jul-02 3:35 
GeneralRe: Any Idea? Pin
1-Jul-02 7:31
suss1-Jul-02 7:31 
AnswerRe: Any Idea? Pin
Amit Dey27-Aug-02 13:49
Amit Dey27-Aug-02 13:49 
GeneralRe: Any Idea? Pin
Anonymous28-Aug-02 3:04
Anonymous28-Aug-02 3:04 
GeneralExcel events inside a DLL Pin
Zizilamoroso19-Jun-02 23:48
Zizilamoroso19-Jun-02 23:48 
GeneralRe: Excel events inside a DLL Pin
soptest20-Jun-02 7:54
soptest20-Jun-02 7:54 
GeneralInterlocked increment failed Pin
sefip19-Jun-02 20:56
sefip19-Jun-02 20:56 
GeneralRe: Interlocked increment failed Pin
Dudi Avramov20-Jun-02 2:05
Dudi Avramov20-Jun-02 2:05 
Generallock-up catching excel events Pin
Zizilamoroso18-Jun-02 23:54
Zizilamoroso18-Jun-02 23:54 
GeneralRe: lock-up catching excel events Pin
Zizilamoroso19-Jun-02 1:20
Zizilamoroso19-Jun-02 1:20 
GeneralRe: lock-up catching excel events Pin
soptest20-Jun-02 7:52
soptest20-Jun-02 7:52 
GeneralLegacy COM calling .NET DLL: LPArray problem Pin
bad_english18-Jun-02 21:01
bad_english18-Jun-02 21:01 
GeneralCatching Events Pin
18-Jun-02 4:48
suss18-Jun-02 4:48 
GeneralRe: Catching Events Pin
Amit Dey18-Jun-02 11:14
Amit Dey18-Jun-02 11:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.