Skip to content

Commit 110a79b

Browse files
committed
Fill in some holes from testing and further abstract out the container. Have tracer support the internal interfaces, too.
1 parent c72b8a6 commit 110a79b

File tree

5 files changed

+94
-17
lines changed

5 files changed

+94
-17
lines changed

Rubberduck.VBEEditor/ComManagement/TypeLibs/DebugInternal/TypeInfoWrapperTracer.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55

66
namespace Rubberduck.VBEditor.ComManagement.TypeLibs.DebugInternal
77
{
8-
internal class TypeInfoWrapperTracer : ITypeInfoWrapper
8+
internal class TypeInfoWrapperTracer : ITypeInfoWrapper, ITypeInfoInternal
99
{
1010
private readonly ITypeInfoWrapper _wrapper;
11+
private readonly ITypeInfoInternal _inner;
1112

12-
internal TypeInfoWrapperTracer(ITypeInfoWrapper wrapper)
13+
internal TypeInfoWrapperTracer(ITypeInfoWrapper wrapper, ITypeInfoInternal inner)
1314
{
1415
_wrapper = wrapper;
16+
_inner = inner;
1517
}
1618

1719
private static void Before(string parameters = null, [CallerMemberName] string methodName = null)
@@ -115,6 +117,14 @@ int ITypeInfoWrapper.GetDllEntry(int memid, INVOKEKIND invKind, IntPtr pBstrDllN
115117
return result;
116118
}
117119

120+
int ITypeInfoInternal.GetDllEntry(int memid, INVOKEKIND invKind, IntPtr pBstrDllName, IntPtr pBstrName, IntPtr pwOrdinal)
121+
{
122+
Before($"{nameof(memid)}: {memid}, {nameof(invKind)}: {invKind}, {nameof(pBstrDllName)}: {pBstrDllName}, {nameof(pBstrName)}: {pBstrName}, {nameof(pwOrdinal)}: {pwOrdinal}");
123+
var result = _inner.GetDllEntry(memid, invKind, pBstrDllName, pBstrName, pwOrdinal);
124+
After($"{nameof(result)}: {result}, {nameof(pBstrDllName)}: {pBstrDllName}, {nameof(pBstrName)}: {pBstrName}, {nameof(pwOrdinal)}: {pwOrdinal}");
125+
return result;
126+
}
127+
118128
public int GetRefTypeInfo(int hRef, IntPtr ppTI)
119129
{
120130
Before($"{nameof(hRef)}: {hRef}, {nameof(ppTI)}: {ppTI}");

Rubberduck.VBEEditor/ComManagement/TypeLibs/DebugInternal/TypeLibWrapperTracer.cs

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,19 @@
22
using System.Runtime.CompilerServices;
33
using System.Runtime.InteropServices.ComTypes;
44
using Rubberduck.VBEditor.ComManagement.TypeLibs.Abstract;
5+
using Rubberduck.VBEditor.ComManagement.TypeLibs.Unmanaged;
56

67
namespace Rubberduck.VBEditor.ComManagement.TypeLibs.DebugInternal
78
{
8-
internal class TypeLibWrapperTracer : ITypeLibWrapper
9+
internal class TypeLibWrapperTracer : ITypeLibWrapper, ITypeLibInternal
910
{
1011
private readonly ITypeLibWrapper _wrapper;
12+
private readonly ITypeLibInternal _inner;
1113

12-
internal TypeLibWrapperTracer(ITypeLibWrapper wrapper)
14+
internal TypeLibWrapperTracer(ITypeLibWrapper wrapper, ITypeLibInternal inner)
1315
{
1416
_wrapper = wrapper;
17+
_inner = inner;
1518
}
1619

1720
private static void Before(string parameters = null, [CallerMemberName] string methodName = null)
@@ -32,6 +35,70 @@ public int GetTypeInfoCount()
3235
return result;
3336
}
3437

38+
public int GetTypeInfo(int index, IntPtr ppTI)
39+
{
40+
Before($"{nameof(index)}: {index}, {nameof(ppTI)}: {ppTI}");
41+
var result = _inner.GetTypeInfo(index, ppTI);
42+
After($"{nameof(result)}: {result}, {nameof(ppTI)}: {ppTI}");
43+
return result;
44+
}
45+
46+
public int GetTypeInfoType(int index, IntPtr pTKind)
47+
{
48+
Before($"{nameof(index)}: {index}, {nameof(pTKind)}: {pTKind}");
49+
var result = _inner.GetTypeInfoType(index, pTKind);
50+
After($"{nameof(result)}: {result}, {nameof(pTKind)}: {pTKind}");
51+
return result;
52+
}
53+
54+
public int GetTypeInfoOfGuid(ref Guid guid, IntPtr ppTInfo)
55+
{
56+
Before($"{nameof(guid)}: {guid}, {nameof(ppTInfo)}: {ppTInfo}");
57+
var result = _inner.GetTypeInfoOfGuid(ref guid, ppTInfo);
58+
After($"{nameof(result)}: {result}, {nameof(ppTInfo)}: {ppTInfo}");
59+
return result;
60+
}
61+
62+
public int GetLibAttr(IntPtr ppTLibAttr)
63+
{
64+
Before($"{nameof(ppTLibAttr)}: {ppTLibAttr}");
65+
var result = _inner.GetLibAttr(ppTLibAttr);
66+
After($"{nameof(result)}: {result}, {nameof(ppTLibAttr)}: {ppTLibAttr}");
67+
return result;
68+
}
69+
70+
public int GetTypeComp(IntPtr ppTComp)
71+
{
72+
Before($"{nameof(ppTComp)}: {ppTComp}");
73+
var result = _inner.GetTypeComp(ppTComp);
74+
After($"{nameof(result)}: {result}, {nameof(ppTComp)}: {ppTComp}");
75+
return result;
76+
}
77+
78+
public int GetDocumentation(int index, IntPtr strName, IntPtr strDocString, IntPtr dwHelpContext, IntPtr strHelpFile)
79+
{
80+
Before($"{nameof(index)}: {index}, {nameof(strName)}: {strName}, {nameof(strDocString)}: {strDocString}, {nameof(dwHelpContext)}: {dwHelpContext}, {nameof(strHelpFile)}: {strHelpFile}");
81+
var result = _inner.GetDocumentation(index, strName, strDocString, dwHelpContext, strHelpFile);
82+
After($"{nameof(result)}: {result}, {nameof(strName)}: {strName}, {nameof(strDocString)}: {strDocString}, {nameof(dwHelpContext)}: {dwHelpContext}, {nameof(strHelpFile)}: {strHelpFile}");
83+
return result;
84+
}
85+
86+
public int IsName(string szNameBuf, int lHashVal, IntPtr pfName)
87+
{
88+
Before($"{nameof(szNameBuf)}: {szNameBuf}, {nameof(lHashVal)}: {lHashVal}, {nameof(pfName)}: {pfName}");
89+
var result = _inner.IsName(szNameBuf, lHashVal, pfName);
90+
After($"{nameof(result)}: {result}, {nameof(pfName)}: {pfName}");
91+
return result;
92+
}
93+
94+
public int FindName(string szNameBuf, int lHashVal, IntPtr ppTInfo, IntPtr rgMemId, IntPtr pcFound)
95+
{
96+
Before($"{nameof(szNameBuf)}: {szNameBuf}, {nameof(lHashVal)}: {lHashVal}, {nameof(ppTInfo)}: {ppTInfo}, {nameof(rgMemId)}: {rgMemId}, {nameof(pcFound)}: {pcFound}");
97+
var result = _inner.FindName(szNameBuf, lHashVal, ppTInfo, rgMemId, pcFound);
98+
After($"{nameof(result)}: {result}, {nameof(ppTInfo)}: {ppTInfo}, {nameof(rgMemId)}: {rgMemId}, {nameof(pcFound)}: {pcFound}");
99+
return result;
100+
}
101+
35102
public void GetTypeInfo(int index, out ITypeInfo ppTI)
36103
{
37104
Before($"{nameof(index)}: {index}");

Rubberduck.VBEEditor/ComManagement/TypeLibs/TypeApiFactory.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#define TRACE_TYPEAPI
1+
// #define TRACE_TYPEAPI
22

33
using System;
44
using System.Runtime.InteropServices.ComTypes;
@@ -16,7 +16,7 @@ internal static ITypeLibWrapper GetTypeLibWrapper(IntPtr rawObjectPtr, bool addR
1616
{
1717
var wrapper = new TypeLibWrapper(rawObjectPtr, addRef);
1818
#if DEBUG && TRACE_TYPEAPI
19-
return new TypeLibWrapperTracer(wrapper);
19+
return new TypeLibWrapperTracer(wrapper, wrapper);
2020
#else
2121
return wrapper;
2222
#endif
@@ -26,7 +26,7 @@ internal static ITypeInfoWrapper GetTypeInfoWrapper(IntPtr rawObjectPtr, int? pa
2626
{
2727
var wrapper = new TypeInfoWrapper(rawObjectPtr, parentUserFormUniqueId);
2828
#if DEBUG && TRACE_TYPEAPI
29-
return new TypeInfoWrapperTracer(wrapper);
29+
return new TypeInfoWrapperTracer(wrapper, wrapper);
3030
#else
3131
return wrapper;
3232
#endif
@@ -36,7 +36,7 @@ internal static ITypeInfoWrapper GetTypeInfoWrapper(ITypeInfo rawTypeInfo)
3636
{
3737
var wrapper = new TypeInfoWrapper(rawTypeInfo);
3838
#if DEBUG && TRACE_TYPEAPI
39-
return new TypeInfoWrapperTracer(wrapper);
39+
return new TypeInfoWrapperTracer(wrapper, wrapper);
4040
#else
4141
return wrapper;
4242
#endif

Rubberduck.VBEEditor/ComManagement/TypeLibs/TypeInfoWrapper.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ internal sealed class TypeInfoWrapper : TypeInfoInternalSelfMarshalForwarderBase
5151
private ITypeInfoInternal _target_ITypeInfo => _typeInfoPointer.Interface;
5252
private ITypeInfoInternal _target_ITypeInfoAlternate => _typeInfoAlternatePointer.Interface;
5353

54-
private TypeLibInternalSelfMarshalForwarderBase _container { get; set; }
55-
public ComTypes.ITypeLib Container => _container;
54+
private ComTypes.ITypeLib _container { get; set; }
55+
public ComTypes.ITypeLib Container => (ComTypes.ITypeLib)_container;
5656

5757
public int ContainerIndex { get; private set; }
5858
public bool HasModuleScopeCompilationErrors { get; private set; }
@@ -133,7 +133,7 @@ private void InitCommon()
133133
if (!ComHelper.HRESULT_FAILED(hr))
134134
{
135135
// We have to wrap the ITypeLib returned by GetContainingTypeLib
136-
_container = (TypeLibInternalSelfMarshalForwarderBase)TypeApiFactory.GetTypeLibWrapper(typeLibPtr.Value, addRef: false);
136+
_container = TypeApiFactory.GetTypeLibWrapper(typeLibPtr.Value, addRef: false);
137137
ContainerIndex = containerTypeLibIndex.Value;
138138
}
139139
else
@@ -225,7 +225,7 @@ public void Dispose()
225225

226226
_vbeExtensions?.Dispose();
227227
_cachedReferencedTypeInfos?.Dispose();
228-
_container?.Dispose();
228+
(_container as IDisposable)?.Dispose();
229229

230230
_typeInfoPointer.Dispose();
231231
_typeInfoAlternatePointer.Dispose();

Rubberduck.VBEEditor/ComManagement/TypeLibs/Unmanaged/ComPointer.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ private ComPointer(IntPtr pUnk, bool addRef)
107107

108108
Interface = (TComInterface)RdMarshal.GetTypedObjectForIUnknown(pUnk, typeof(TComInterface));
109109

110-
#if DEBUG
110+
#if DEBUG && TRACE_COM_POINTERS
111111
Debug.Print($"ComPointer:: Created from pointer: pUnk: {RdMarshal.FormatPtr(_pUnk)} interface: {typeof(TComInterface).Name} - {Interface.GetHashCode()} addRef: {_addRef} refCount: {refCount}");
112112
#endif
113113
}
@@ -117,7 +117,7 @@ private ComPointer(IntPtr pUnk, TComInterface comInterface)
117117
_pUnk = pUnk;
118118
Interface = comInterface;
119119

120-
#if DEBUG
120+
#if DEBUG && TRACE_COM_POINTERS
121121
Debug.Print($"ComPointer:: Created from aggregation: pUnk: {RdMarshal.FormatPtr(_pUnk)} interface: {typeof(TComInterface).Name} - {Interface.GetHashCode()} addRef: {_addRef}");
122122
#endif
123123
}
@@ -127,7 +127,7 @@ private ComPointer(TComInterface comInterface)
127127
Interface = comInterface;
128128
_pUnk = RdMarshal.GetIUnknownForObject(Interface);
129129

130-
#if DEBUG
130+
#if DEBUG && TRACE_COM_POINTERS
131131
Debug.Print($"ComPointer:: Created from object: pUnk: {RdMarshal.FormatPtr(_pUnk)} interface: {typeof(TComInterface).Name} - {Interface.GetHashCode()} addRef: {_addRef}");
132132
#endif
133133
}
@@ -145,8 +145,8 @@ private void ReleaseUnmanagedResources()
145145
if(_disposed) return;
146146

147147
var rcwCount = RdMarshal.ReleaseComObject(Interface);
148-
149-
#if DEBUG
148+
149+
#if DEBUG && TRACE_COM_POINTERS
150150
if (!_addRef)
151151
{
152152
// Temporarily add a ref so that we can safely call IUnknown::Release

0 commit comments

Comments
 (0)