|
What kind of errors are you getting?
In the appid key in the registry, set the AuthenticationLevel = 1, the RemoteServerName = the server machine name, and RunAs = "Interactive User".
Win9x machines must have the server app running.
Jason Henderson quasi-homepage articles "Like it or not, I'm right!"
|
|
|
|
|
Thank you for your reply,
but I finally managed it doing it like I was told in the fabolous articel:
Code Project/COM / DCOM / COM+ - DCOM D-Mystified: A DCOM Tutorial, Step 1-7 by Brian Hart
so I think I just have to implement some kind of installation-tool to adjust dcomcnfg.exe, so that I'm able to install the server and config the registry at the same time, so that everything is worling fine (good luck (:oD)).
have a nice day,
bye,
stefan
|
|
|
|
|
Hey, can anyone give any recommendations of good books that I can get that will help with my COM/OLE/ATL woes? I am using COM/OLE (and/or ATL) and trying to incorporate MS Word into an application, add a toolbar button dynamically, and other processing, and I was wondering if anyone knew of any books that might be good, possibly show some examples, etc. I would like to get a couple of books that might be working with Word in them. Any ideas would be appreciated!!!
I have looked at various posts on this website and a few others and they have helped alot. But they just don't seem to work in my application and I am not sure why...
|
|
|
|
|
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!!!
|
|
|
|
|
Thanks in advance for any help. I am trying to create an ATL server using the example "Building an Office2K COM addin with VC++/ATL". I am having a problem with the imports. Here is my stdafx.h:
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently,
// but are changed infrequently
#if !defined(AFX_STDAFX_H__613C434D_55D9_45D2_937E_C26FA13D3F22__INCLUDED_)
#define AFX_STDAFX_H__613C434D_55D9_45D2_937E_C26FA13D3F22__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#define STRICT
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0400
#endif
#define _ATL_APARTMENT_THREADED
#include
//You may derive a class from CComModule and use it if you want to override
//something, but do not change the name of _Module
extern CComModule _Module;
#include
//{{AFX_INSERT_LOCATION}}
#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;
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_STDAFX_H__613C434D_55D9_45D2_937E_C26FA13D3F22__INCLUDED)
Unfortunately, I keep getting the error message:
StdAfx.obj : fatal error LNK1179: invalid or corrupt file: duplicate comdat "_IID_CanvasShapes"
Any ideas what I need to do to fix this problem? I am new to ATL but I was thinking the "using namespace Word" should have taken care of any duplicates. I used the article as an example because I am not using Outlook, instead I am using MS Word. Any thoughts?
|
|
|
|
|
How does your stdafx.cpp look. Mail me the code if possible. It happens sometimes if you use Interface refernce in the main project file.
|
|
|
|
|
Any luck on the code? I have been trying different things but nothing has worked yet???
|
|
|
|
|
I can guess that you are using Office XP but are you using VS.NET? the #import statements works fine for me (MSVC6.0 and Office2k), so I really can't say what the problem is. Once you get over your #import, I think the code will work fine.
Anyway, have you tried the exclude keyword to exclude redundant/duplicate IID's/GUID's in #import?
You yard yellow years yieldingly; you yanked your yearning yoke.-Jeremy Falcon-CPite.
Amit Dey
sonork: 100:18407
msn: visualcdev
|
|
|
|
|
No, I am using VC 6.0, I have not used VC.NET yet. I have tried to exclude the duplicate IID's but after the 10th or 15th one, I thought this is not the correct way to do this. It seems that there are several (A LOT) of duplicates, not just the on. I used the example of the Office2K and Outlook and Outlook does not have the same IID's as Office. But apparently, Word does for some reason???
|
|
|
|
|
Yeah, I came across a similar duplicate IID problem while building Word addin. I know how frustrating this is!!
If you already haven't figured out, the solution is to move the #import statement for importing Word typelib(the 2nd #import) to your addins .h file.
e.g. I put the following #imports in my Addin.h file. so it looks like :
#ifndef __ADDIN_H_
#define __ADDIN_H_
#include "resource.h" // main symbols
#import "D:\Program Files\Common Files\designer\MSADDNDR.TLB" raw_interfaces_only, raw_native_types, no_namespace, named_guids
#import "D:\Program Files\Microsoft Office\Office\MSWORD9.olb" rename_namespace("MSWORD"), rename("ExitWindows","WordExitWindows"), named_guids, raw_interfaces_only
using namespace MSWORD;
and then rebuild.
HTH,
'My capacity for happiness', he added, 'you could fit into a matchbox without taking out the matches first'.
- Marvin, the robot.
Amit Dey
sonork: 100:18407
msn: visualcdev
|
|
|
|
|
Thanks, I will try it out!
|
|
|
|
|
I've a question about this example: It opens excel and inserts an eventsink to catch the events inside excel.
HOWTO: Catch Microsoft Excel Application Events Using VC++ Q186427
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q186427
I've tried this example using an MFC-EXE, and all works fine. When you press start, the excel application shows up. Clicking with the mouse results in a event messagebox.
But, if you want to include this functionality inside an MFC-DLL, it will not work. Excel shows up alright, but when you click something or press a button, the excel application will block. After a while a messagebox shows up saying: "Microsoft Excel is waiting for another application to complete an OLE action."
Short: using a .exe works fine, but the .dll blocks.
Why?
What's the difference here? (I've used MFC in both cases)
[VISUAL STUDIO 6.0] [MFC] [WIN98/2]
Bluute tette!
|
|
|
|
|
must do:
while(GetMessage())
DispatchMessage();
soptest
|
|
|
|
|
Hello,
I have a problem, the CoCreateInstance of some COM object that is in DLL, fails every two or three times.
I kill all processes involved, and then reload.
it tells me that interlocked increment has failed
any hint to how it might be traced out and eliminated?
thanks
s.
|
|
|
|
|
ATL has some macros that help you trace your problem:
_ATL_DEBUG_REFCOUNT
_ATL_DEBUG_QI
_ATL_DEBUG_INTERFACES
Read the following article in MSDN:
"Debugging Tips for ATL Objects".
Goodluck,
Dudi
|
|
|
|
|
I'm controlling excel from another app: create sheets, set ranges, modify properties and so on.
Now, I've implemented an eventlistener like described as on the msdn-website, automation, creating our own IDispatch for catching events.
The strange thing is that it handles pretty well events like WINDOW_ACTIVATE, SHEET_CALCULATE, ... if those things are modified from the outside-application. BUT if we select a range or double click on the sheet, excel blocks. Our app doesn't block, but it doesn't receive anymore events. We still can close excel though.
Is this a common problem? Anybody solved it yet? Or where to look?
initialising:
CEventsDispatch g_XLEventDispatch;
IConnectionPoint *m_pConnectionPoint;
DWORD m_adviseCookie;
static const GUID IID_IExcel8AppEvents =
{0x00024413,0x000,0x0000,{0xc0,0x00,0x0,0x00,0x00,0x00,0x00,0x46 } };
HRESULT hr;
IConnectionPointContainer *pConnPtContainer;
hr = m_pXlApp->QueryInterface(IID_IConnectionPointContainer,(void **)&pConnPtContainer);
if(hr!=0)
return;
hr = pConnPtContainer->FindConnectionPoint(IID_IExcel8AppEvents,&m_pConnectionPoint);
if(hr!=0)
return;
hr = m_pConnectionPoint->Advise(&g_XLEventDispatch, &m_adviseCookie);
if(hr!=0)
return;
pConnPtContainer->Release();
our idispatch:
class CEventsDispatch : public IDispatch
{
public:
ULONG refCount;
CEventsDispatch::CEventsDispatch()
{
refCount=1;
}
CEventsDispatch::~CEventsDispatch()
{
}
virtual HRESULT __stdcall QueryInterface(REFIID riid, void **ppvObject)
{
if(IsEqualGUID(riid, IID_IDispatch) || IsEqualGUID(riid, IID_IUnknown))
{
this->AddRef();
*ppvObject = this;
return S_OK;
}
*ppvObject = NULL;
return E_NOINTERFACE;
}
virtual ULONG _stdcall AddRef(void)
{
return ++refCount;
}
virtual ULONG _stdcall Release(void)
{
if(--refCount <= 0)
{
return 0;
}
return refCount;
}
virtual HRESULT _stdcall GetTypeInfoCount(UINT *pctinfo)
{
if(pctinfo) *pctinfo = 0;
return E_NOTIMPL;
}
virtual HRESULT _stdcall GetTypeInfo(UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
{
return E_NOTIMPL;
}
virtual HRESULT _stdcall GetIDsOfNames(REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid,DISPID *rgDispId)
{
return E_NOTIMPL;
}
virtual HRESULT _stdcall Invoke(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags,DISPPARAMS *pDispParams, VARIANT *pVarResult,EXCEPINFO *pExcepInfo, UINT *puArgErr)
{
return S_OK;
}
};
[VISUAL STUDIO 6.0] [MFC] [WIN98/2]
Bluute tette!
|
|
|
|
|
After a few minutes, a messagebox comes up saying: "Microsoft excel is waiting for another application to complete an OLE action."
I've implemented everything I've found on the msdn example (automating excel using vc++), so they must have forgotten something?
[VISUAL STUDIO 6.0] [MFC] [WIN98/2]
Bluute tette!
|
|
|
|
|
Try :
while(GetMessage())
DispatchMessage();
in your thread.
soptest
|
|
|
|
|
Does anyone know how to properly marshal the data from legacy app to
a .Net component? The legacy app uses the following IDL interface
definition:
interface IMyInterface2 : IUnknown
{
HRESULT doit( [in, size_is(msgLength)]UCHAR* msg, [in] ULONG
msgLength );
};
When my legacy COM Client calls my .Net component that implements this
interface, an access violation (0xC0000005) exception is thrown. I've
tried everything and can not figure out why the exception is thrown in
the
COM Client.
Here is the COM Client:
#include "stdafx.h"
#include "IMyInterface2_h.h"
#include "IMyInterface2_i.c"
int _tmain(int argc, _TCHAR* argv[])
{
HRESULT hr = S_OK;
hr = ::CoInitialize( NULL );
CLSID rcid = { 0x5F850215, 0x7AC2, 0x48b8, { 0xA8, 0xCF, 0xA0, 0x08,
0xF7, 0x33, 0xD6, 0x61 } };
{
CComPtr<imyinterface2> iMyInterface2;
hr = iMyInterface2.CoCreateInstance( rcid, NULL, CLSCTX_INPROC_SERVER
);
UCHAR* pBytes = (UCHAR*)::CoTaskMemAlloc( 20 );
::ZeroMemory( pBytes, 20 );
iMyInterface2->doit( pBytes, 20 );
}
::CoUninitialize();
return 0;
}
The exception is thrown on the statement:
iMyInterface2->doit( pBytes, 20 );
The call never gets to the .Net component's method
And here is the .Net service component. The .Net component must be
copied in the same directory as the COM client.
using System;
using System.Runtime.InteropServices;
namespace ComSrv
{
[GuidAttribute("5F850215-7AC2-48b8-A8CF-A008F733D661")]
public class MyClass : IMyInterface2
{
public void doit( byte[] msg, ulong msgLength )
{
}
}
[ComImport]
[GuidAttribute("B55AFAEB-BC7D-4ca9-8065-F9A45FE378B6")]
[InterfaceTypeAttribute
ComInterfaceType.InterfaceIsIUnknown)]
public interface IMyInterface2
{
void doit(
[In, MarshalAs( UnmanagedType.LPArray,
SizeParamIndex=1, ArraySubType=UnmanagedType.U1 )]byte[]
msg, [In]ulong msgLength );
}
}
|
|
|
|
|
I have an application that is a MFC-based COM object that opens MS Word and opens a word document. I have added a custom button ontot he MS Word toolbar to the MS Word toolbar so that if the user hits this button, the document will be saved and MS Word will close down. Unfortunately, I do not know how to catch the event that my button has been pressed. I have looked and looked and looked and all the info I can find deals with sinking events and an ATL server. I did not create this as an ATL server and most of the information I can find deals with an ATL server. I need help badly, I am clueless as to how to continue. Can anybody help? How do I catch the event that my button has been pressed? Am I going to have to convert it to an ATL server and if so, how do I go about doing that?
PLEASE HELP!!!
|
|
|
|
|
On the topic of sinking events, please take a look here. The project contains code that sinks events to a custom toolbar created thru an Office addin. Ofcourse it is a pure ATL project.
HTH,
You yard yellow years yieldingly; you yanked your yearning yoke.-Jeremy Falcon-CPite.
Amit Dey
sonork: 100:18407
msn: visualcdev
|
|
|
|
|
I have tried to implement something like that, using MSWord in place of Outlook and I cannot get it to work. It keeps giving me Link Errors because of duplicate IID_XXXX's. How do I get around this if I were to use pure ATL?
|
|
|
|
|
Try out various #import options keywords like no_namespace, rename etc to resolve link problem.
|
|
|
|
|
Could you be a little specific and tell me what are the errors?
|
|
|
|
|
Yeah, I came across a similar duplicate IID problem while building Word addin. I know how frustrating this is!!
If you already haven't figured out, the solution is to move the #import statement for importing Word typelib(the 2nd #import) to your addins .h file.
e.g. I put the following #imports in my Addin.h file. so it looks like :
#ifndef __ADDIN_H_
#define __ADDIN_H_
#include "resource.h" // main symbols
#import "D:\Program Files\Common Files\designer\MSADDNDR.TLB" raw_interfaces_only, raw_native_types, no_namespace, named_guids
#import "D:\Program Files\Microsoft Office\Office\MSWORD9.olb" rename_namespace("MSWORD"), rename("ExitWindows","WordExitWindows"), named_guids, raw_interfaces_only
using namespace MSWORD;
and then rebuild.
HTH,
'My capacity for happiness', he added, 'you could fit into a matchbox without taking out the matches first'.
- Marvin, the robot.
Amit Dey
sonork: 100:18407
msn: visualcdev
|
|
|
|
|