Re: Question on how to debug COM
"ccccoder" <ccccoder@discussions.microsoft.com> wrote in message
news:37C8826F-BB5D-490C-8211-33930D66E88A@microsoft.com
"Igor Tandetnik" wrote:
"ccccoder" <ccccoder@discussions.microsoft.com> wrote in message
news:5CD94D07-6EB5-46C4-9F42-3EC944585719@microsoft.com
Well, the author is Microsoft, and there is no documentation for
that. At least, it's not telling what is passing in the pDispParams.
I'm developing an addin for Excel
I assume you have seen the documentation here and found it lacking:
http://msdn2.microsoft.com/en-us/library/bb149081.aspx
What exactly do you believe is wrong with this documentation?
Well, that's not what I said. I've never said there is anything wrong
with that.
In fact, I can get all this information just fine from the Excel type
library.
Then what did you mean by "there is no documentation" ?
What I'm saying is that, when you implement an event sink, and you
must implement the Invoke() method from IDispatch, and when Excel
dispatches
the event by calling Invoke() of your event sink, there is no
documentation about what data are being sent in, specifically, I want
to know what
is sent in pDispParams. That 's what I said.
The documentation does list parameters that accompany every event Excel
might fire. These parameters are packed into DISPPARAMS structure. This
article documents how:
http://msdn.microsoft.com/library/en-us/automat/html/f0b7c325-844b-42c3-9581-ec025111a898.asp
And as a way to figure that out, I'm asking a question on how to find
out the real type of an IDispatch in the debugger if you don't know
it in advance.
What do you mean by "real type"? I'm afraid I'm not familiar with the
term. In any case, how is this question related to "what's sent in
DISPPARAMS" one?
So, as an investigation, I just want to see what is passed in by
Excel to my Invoke() method when the print event is fired.
According to the documentation at
http://msdn2.microsoft.com/en-us/library/bb210446.aspx
you should get DISPPARAMS structure with a single VARIANT of type
VT_BOOL | VT_BYREF. This means that pboolVal member of this VARIANT
holds a pointer to VARIANT_BOOL variable. You should set that
variable, via the pointer, to VARIANT_TRUE if you want to cancel
print operation.
Again, thanks for sharing the information here, but you did it
without reading the thread. I already said that I know how to do it
with VBA or .NET, but those
are not an option, because we had everything in C++ (ATL/COM).
My answer was indeed for C++. In fact, this answer is meaningless for a
VBA or .NET programmer, and is only good for a C++ programmer. I'm not
sure how I could be any more clear or explicit without actually writing
code for you. Since you insist:
STDMETHODIMP MyEventListener::Invoke(
DISPID dispIdMember, REFIID riid, LCID lcid,
WORD wFlags, DISPPARAMS* pDispParams,
VARIANT* pVarResult, EXCEPINFO* pExcepInfo,
UINT* puArgErr) {
if (dispIdMember == /* DISPID for BeforePrint event */) {
ATLASSERT(pDispParams->cArgs >= 1);
VARIANT* pvarCancel = &pDispParams->rgvarg[pDispParams->cArgs -
1];
ATLASSERT(V_VT(pvarCancel) == (VT_BOOL | VT_BYREF) );
*V_BOOLREF(pvarCancel) = VARIANT_TRUE;
}
return S_OK;
}
Better still, since you are using ATL, use IDispEvent[Simple]Impl to
implement your sink. Then you would have a regular method taking
VARIANT_BOOL*, and ATL will handle parsing of DISPPARAMS structure for
you. See AtlEventHandling sample:
http://msdn2.microsoft.com/en-us/library/e85w507k.aspx
Don't people need to know what kind of
IDispatch they receive, from time to time?
Perhaps. Note than, in a particular case of Workbook.BeforePrint
event, you don't receive any kind of IDispatch. Which, I guess,
renders your profound philosophical observation somewhat moot.
In C++, you do receive an IDispatch to the Invoke() method.
No you don't. I mean, some events may have an IDispatch parameter, but
Workbook.BeforePrint doesn't. So in this particular case, you do _not_,
I repeat do _not_, get an IDispatch pointer in any way, shape or form in
your Invoke implementation (other than your own, of course, in the form
of 'this' pointer).
And since
the documentation is not saying what is sent in
The documentation is perfectly clear. The event gets a ByRef boolean
parameter, not an IDispath one.
I want to figure
that out, maybe, using some tricks I don't know yet inside the
debugger.
"The hardest thing of all is to find a black cat in a dark room...
especially if there is no cat." -- Confucius
I was asking the question if there is a way to figure out the real
type of an IDispatch if you don't know it in advance.
Again, what's a "real type"?
This question
keeps on coming
back when you work with COM technologies, and when you don't have the
right documentation or the symbols.
It appears that, in this particular case, you do have the right
documentation. What exactly do you feel is wrong with it? Personally, I
find it quite helpful.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925