Skip to content

Commit 240f19e

Browse files
adds some XML documentation to TypeLibsAbstract
1 parent 5141435 commit 240f19e

File tree

1 file changed

+91
-14
lines changed

1 file changed

+91
-14
lines changed

Rubberduck.VBEEditor/ComManagement/TypeLibs/TypeLibsAbstract.cs

Lines changed: 91 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
namespace Rubberduck.VBEditor.ComManagement.TypeLibsAbstract
66
{
7+
/// <summary>
8+
/// Windows API structure used by VirtualQuery, see https://msdn.microsoft.com/en-us/library/windows/desktop/aa366775.aspx
9+
/// </summary>
710
[StructLayout(LayoutKind.Sequential)]
811
public struct MEMORY_BASIC_INFORMATION
912
{
@@ -16,6 +19,9 @@ public struct MEMORY_BASIC_INFORMATION
1619
public uint Type;
1720
}
1821

22+
/// <summary>
23+
/// Windows API constants used by VirtualQuery, see https://msdn.microsoft.com/en-us/library/windows/desktop/aa366786.aspx
24+
/// </summary>
1925
public enum ALLOCATION_PROTECTION : uint
2026
{
2127
PAGE_EXECUTE = 0x00000010,
@@ -30,7 +36,11 @@ public enum ALLOCATION_PROTECTION : uint
3036
PAGE_NOCACHE = 0x00000200,
3137
PAGE_WRITECOMBINE = 0x00000400
3238
}
33-
39+
40+
/// <summary>
41+
/// A version of IDispatch that allows us to call its members explicitly
42+
/// see https://msdn.microsoft.com/en-us/library/windows/desktop/ms221608(v=vs.85).aspx
43+
/// </summary>
3444
[ComImport(), Guid("00020400-0000-0000-C000-000000000046")]
3545
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
3646
public interface IDispatch
@@ -52,13 +62,23 @@ int Invoke([In] int dispIdMember,
5262

5363
public static class ComHelper
5464
{
65+
/// <summary>
66+
/// Equivalent of the Windows FAILED() macro in C
67+
/// see https://msdn.microsoft.com/en-us/library/windows/desktop/ms693474(v=vs.85).aspx
68+
/// </summary>
69+
/// <param name="hr">HRESULT from a COM API call</param>
70+
/// <returns>true if the HRESULT indicated failure</returns>
5571
public static bool HRESULT_FAILED(int hr) => hr < 0;
5672
}
5773

5874
public static class IDispatchHelper
5975
{
6076
static Guid GUID_NULL = new Guid();
6177

78+
/// <summary>
79+
/// IDispatch::Invoke flags
80+
/// see https://msdn.microsoft.com/en-gb/library/windows/desktop/ms221479(v=vs.85).aspx
81+
/// </summary>
6282
public enum InvokeKind : int
6383
{
6484
DISPATCH_METHOD = 1,
@@ -67,6 +87,10 @@ public enum InvokeKind : int
6787
DISPATCH_PROPERTYPUTREF = 8,
6888
}
6989

90+
/// <summary>
91+
/// Simplified equivalent of VARIANT structure often used in COM
92+
/// see https://msdn.microsoft.com/en-us/library/windows/desktop/ms221627(v=vs.85).aspx
93+
/// </summary>
7094
[StructLayout(LayoutKind.Sequential)]
7195
public struct VARIANT
7296
{
@@ -78,7 +102,12 @@ public struct VARIANT
78102
IntPtr data2;
79103
}
80104

81-
// Convert input args into a contigious array of real COM VARIANTs for the DISPPARAMS struct
105+
/// <summary>
106+
/// Convert input args into a contigious array of real COM VARIANTs for the DISPPARAMS struct used by IDispatch::Invoke
107+
/// see https://msdn.microsoft.com/en-us/library/windows/desktop/ms221416(v=vs.85).aspx
108+
/// </summary>
109+
/// <param name="args">An array of arguments to wrap</param>
110+
/// <returns>DISPPARAMS structure ready to pass to IDispatch::Invoke</returns>
82111
private static ComTypes.DISPPARAMS PrepareDispatchArgs(object[] args)
83112
{
84113
var pDispParams = new ComTypes.DISPPARAMS();
@@ -106,7 +135,11 @@ private static ComTypes.DISPPARAMS PrepareDispatchArgs(object[] args)
106135
[DllImport("oleaut32.dll", SetLastError = true, CallingConvention = CallingConvention.StdCall)]
107136
static extern Int32 VariantClear(IntPtr pvarg);
108137

109-
// frees all unmanaged memory assoicated with the DISPPARAMS
138+
/// <summary>
139+
/// frees all unmanaged memory assoicated with a DISPPARAMS structure
140+
/// see https://msdn.microsoft.com/en-us/library/windows/desktop/ms221416(v=vs.85).aspx
141+
/// </summary>
142+
/// <param name="pDispParams"></param>
110143
private static void UnprepareDispatchArgs(ComTypes.DISPPARAMS pDispParams)
111144
{
112145
if (pDispParams.rgvarg != IntPtr.Zero)
@@ -125,7 +158,15 @@ private static void UnprepareDispatchArgs(ComTypes.DISPPARAMS pDispParams)
125158
}
126159
}
127160

128-
// TODO support DISPATCH_PROPERTYPUTREF (property-set) which requires special handling
161+
/// <summary>
162+
/// A basic helper for IDispatch::Invoke
163+
/// </summary>
164+
/// <param name="obj">The IDispatch object of which you want to invoke a member on</param>
165+
/// <param name="memberId">The dispatch ID of the member to invoke</param>
166+
/// <param name="invokeKind">See InvokeKind enumeration</param>
167+
/// <param name="args">Array of arguments to pass to the call, or null for no args</param>
168+
/// <remarks>TODO support DISPATCH_PROPERTYPUTREF (property-set) which requires special handling</remarks>
169+
/// <returns>An object representing the return value from the called routine</returns>
129170
public static object Invoke(IDispatch obj, int memberId, InvokeKind invokeKind, object[] args = null)
130171
{
131172
var pDispParams = PrepareDispatchArgs(args);
@@ -149,7 +190,10 @@ public static object Invoke(IDispatch obj, int memberId, InvokeKind invokeKind,
149190
}
150191
}
151192

152-
// A compatible version of ITypeInfo, where COM objects are outputted as IntPtrs instead of objects
193+
/// <summary>
194+
/// A compatible version of ITypeInfo, where COM objects are outputted as IntPtrs instead of objects
195+
/// see https://msdn.microsoft.com/en-gb/library/windows/desktop/ms221696(v=vs.85).aspx
196+
/// </summary>
153197
[ComImport(), Guid("00020401-0000-0000-C000-000000000046")]
154198
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
155199
public interface ITypeInfo_Ptrs
@@ -175,6 +219,10 @@ public interface ITypeInfo_Ptrs
175219
void ReleaseVarDesc(IntPtr pVarDesc);
176220
}
177221

222+
/// <summary>
223+
/// An internal interface exposed by VBA for all components (modules, class modules, etc)
224+
/// </summary>
225+
/// <remarks>This internal interface is known to be supported since the very earliest version of VBA6</remarks>
178226
[ComImport(), Guid("DDD557E1-D96F-11CD-9570-00AA0051E5D4")]
179227
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
180228
public interface IVBEComponent
@@ -214,8 +262,12 @@ public interface IVBEComponent
214262
void Placeholder33();
215263
void GetSomeRelatedTypeInfoPtrs(out IntPtr A, out IntPtr B); // returns 2 TypeInfos, seemingly related to this ITypeInfo, but slightly different.
216264
}
217-
218-
// An extended version of ITypeInfo, hosted by the VBE that includes a particularly helpful member, GetStdModAccessor
265+
266+
/// <summary>
267+
/// An extended version of ITypeInfo, hosted by the VBE that includes a particularly helpful member, GetStdModAccessor
268+
/// see https://msdn.microsoft.com/en-gb/library/windows/desktop/ms221696(v=vs.85).aspx
269+
/// </summary>
270+
/// <remarks>This extended interface is known to be supported since the very earliest version of VBA6</remarks>
219271
[ComImport(), Guid("CACC1E82-622B-11D2-AA78-00C04F9901D2")]
220272
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
221273
public interface IVBETypeInfo
@@ -244,7 +296,10 @@ public interface IVBETypeInfo
244296
IDispatch GetStdModAccessor(); // a handy extra vtable entry we can use to invoke members in standard modules.
245297
}
246298

247-
// A compatible version of ITypeLib, where COM objects are outputted as IntPtrs instead of objects
299+
/// <summary>
300+
/// A compatible version of ITypeLib, where COM objects are outputted as IntPtrs instead of objects
301+
/// see https://msdn.microsoft.com/en-us/library/windows/desktop/ms221549(v=vs.85).aspx
302+
/// </summary>
248303
[ComImport(), Guid("00020402-0000-0000-C000-000000000046")]
249304
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
250305
public interface ITypeLib_Ptrs
@@ -261,8 +316,10 @@ public interface ITypeLib_Ptrs
261316
void ReleaseTLibAttr(IntPtr pTLibAttr);
262317
}
263318

264-
// An internal representation of the VBE References collection object, as returned from the VBE.ActiveVBProject.References, or similar
265-
// These offsets are known to be valid across 32-bit and 64-bit versions of VBA and VB6, right back from when VBA6 was first released.
319+
/// <summary>
320+
/// An internal representation of the VBE References collection object, as returned from VBE.ActiveVBProject.References, or similar
321+
/// These offsets are known to be valid across 32-bit and 64-bit versions of VBA and VB6, right back from when VBA6 was first released.
322+
/// </summary>
266323
[StructLayout(LayoutKind.Sequential)]
267324
struct VBEReferencesObj
268325
{
@@ -276,8 +333,11 @@ struct VBEReferencesObj
276333
IntPtr Placeholder2;
277334
IntPtr RefCount;
278335
}
279-
280-
// A ITypeLib object hosted by the VBE, also providing Prev/Next pointers for a double linked list of all loaded project ITypeLibs
336+
337+
/// <summary>
338+
/// An internal representation of the ITypeLib object hosted by the VBE.
339+
/// Also provides Prev/Next pointers, exposing a double linked list of all loaded project ITypeLibs
340+
/// </summary>
281341
[StructLayout(LayoutKind.Sequential)]
282342
struct VBETypeLibObj
283343
{
@@ -288,7 +348,11 @@ struct VBETypeLibObj
288348
public IntPtr Next;
289349
}
290350

291-
// IVBEProject, obtainable from a VBE hosted ITypeLib in order to access a few extra features...
351+
/// <summary>
352+
/// An internal interface supported by VBA for all projects. Obtainable from a VBE hosted ITypeLib
353+
/// in order to access a few extra features...
354+
/// </summary>
355+
/// <remarks>This internal interface is known to be supported since the very earliest version of VBA6</remarks>
292356
[ComImport(), Guid("DDD557E0-D96F-11CD-9570-00AA0051E5D4")]
293357
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
294358
interface IVBEProject
@@ -317,6 +381,8 @@ interface IVBEProject
317381
void CompileProject(); // throws COM exception 0x800A9C64 if error occurred during compile.
318382
}
319383

384+
/*
385+
Not currently used.
320386
// IVBEProject2, vtable position just before the IVBEProject, not queryable, so needs aggregation
321387
[ComImport(), Guid("FFFFFFFF-0000-0000-C000-000000000046")] //
322388
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
@@ -330,7 +396,12 @@ interface IVBEProject2
330396
void SetProjectHelpFileName(string value);
331397
void SetProjectHelpContext(int value);
332398
}
399+
*/
333400

401+
/// <summary>
402+
/// An extended version of TYPEKIND, which VBA uses internally to identify VBA classes as a seperate type
403+
/// see https://msdn.microsoft.com/en-us/library/windows/desktop/ms221643(v=vs.85).aspx
404+
/// </summary>
334405
public enum TYPEKIND_VBE
335406
{
336407
TKIND_ENUM = 0,
@@ -342,14 +413,20 @@ public enum TYPEKIND_VBE
342413
TKIND_ALIAS = 6,
343414
TKIND_UNION = 7,
344415

345-
TKIND_VBACLASS = 8, // extended by VBA, this is used for the outermost interface
416+
TKIND_VBACLASS = 8,
346417
}
347418

419+
/// <summary>
420+
/// Used by methods in the ITypeInfo and ITypeLib interfaces. Usually used to get the root type or library name.
421+
/// </summary>
348422
public enum TypeLibConsts : int
349423
{
350424
MEMBERID_NIL = -1,
351425
}
352426

427+
/// <summary>
428+
/// Some known COM HRESULTs used in our code
429+
/// </summary>
353430
public enum KnownComHResults : int
354431
{
355432
E_VBA_COMPILEERROR = unchecked((int)0x800A9C64),

0 commit comments

Comments
 (0)