Skip to content

Commit 57ddf99

Browse files
author
Tor Lillqvist
committed
Cache DISPID->name mappings from CProxiedDispatch::GetIDsOfNames() for logging
Useful when the object being handled doesn't provide any type information at run-time. Changes Word.?<00843628>.33064() into Word.?<00797FA8>.MailMergeMainDocumentType() (TODO: Yes, that "?" could also be replaced by the actual name, if we cached the information earlier.)
1 parent 0fc41bf commit 57ddf99

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

include/CProxiedDispatch.hpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ class CProxiedDispatch : public CProxiedUnknown
2828
private:
2929
IDispatch* const mpDispatchToProxy;
3030

31+
// Cached results from GetIDsOfNames() calls, to use for logging in case no type information is
32+
// available.
33+
std::map<DISPID, std::string>* mpDispIdToName;
34+
3135
protected:
3236
CProxiedDispatch(IUnknown* pBaseClassUnknown, IDispatch* pDispatchToProxy,
3337
const char* sLibName);
@@ -36,6 +40,20 @@ class CProxiedDispatch : public CProxiedUnknown
3640
CProxiedDispatch(IUnknown* pBaseClassUnknown, IDispatch* pDispatchToProxy, const IID& rIID1,
3741
const IID& rIID2, const char* sLibName);
3842

43+
#if 0
44+
// We can't have a non-virtual destructor because of the "class has virtual functions, but
45+
// destructor is not virtual" problem and we can't make the destructor virtual because our
46+
// vtable should have *only* the entries from IUnknown plus the ones from this class
47+
// (corresponding to the entries for IDispatch). So ideally we should delete mpDispIdToName in
48+
// Release() when the reference count reaches zero.
49+
50+
~CProxiedDispatch()
51+
{
52+
delete mpDispIdToName;
53+
}
54+
55+
#endif
56+
3957
public:
4058
static CProxiedDispatch* get(IUnknown* pBaseClassUnknown, IDispatch* pDispatchToProxy,
4159
const char* sLibName);

proxies/CProxiedDispatch.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#pragma warning(push)
1111
#pragma warning(disable : 4668 4820 4917)
1212

13+
#include <cassert>
1314
#include <cstdlib>
1415
#include <iostream>
1516
#include <string>
@@ -43,6 +44,7 @@ CProxiedDispatch::CProxiedDispatch(IUnknown* pBaseClassUnknown, IDispatch* pDisp
4344
const IID& rIID1, const IID& rIID2, const char* sLibName)
4445
: CProxiedUnknown(pBaseClassUnknown, pDispatchToProxy, rIID1, rIID2, sLibName)
4546
, mpDispatchToProxy(pDispatchToProxy)
47+
, mpDispIdToName(new std::map<DISPID, std::string>)
4648
{
4749
if (getParam()->mbVerbose)
4850
std::cout << this << "@CProxiedDispatch::CTOR(" << pBaseClassUnknown << ", "
@@ -232,6 +234,15 @@ HRESULT STDMETHODCALLTYPE CProxiedDispatch::GetIDsOfNames(REFIID riid, LPOLESTR*
232234
}
233235
nResult = mpDispatchToProxy->GetIDsOfNames(riid, rgszNames, cNames, lcid, rgDispId);
234236

237+
if (rgszNames && rgDispId && nResult == S_OK && getParam()->mbTrace)
238+
{
239+
std::string sName = convertUTF16ToUTF8(rgszNames[0]);
240+
if (mpDispIdToName->count(rgDispId[0]))
241+
assert((*maDispIdToName)[rgDispId[0]] == sName);
242+
else
243+
(*mpDispIdToName)[rgDispId[0]] = sName;
244+
}
245+
235246
if (getParam()->mbVerbose)
236247
{
237248
std::cout << "..." << this << "@CProxiedDispatch::GetIDsOfNames: ";
@@ -312,7 +323,10 @@ HRESULT STDMETHODCALLTYPE CProxiedDispatch::Invoke(DISPID dispIdMember, REFIID r
312323
std::cout << "<" << (mpBaseClassUnknown ? mpBaseClassUnknown : this) << ">.";
313324

314325
if (pTI == NULL)
315-
std::cout << dispIdMember;
326+
if (mpDispIdToName->count(dispIdMember))
327+
std::cout << (*mpDispIdToName)[dispIdMember];
328+
else
329+
std::cout << dispIdMember;
316330
else
317331
{
318332
BSTR sFuncName = NULL;

0 commit comments

Comments
 (0)