4
4
5
5
namespace Rubberduck . VBEditor . ComManagement . TypeLibsAbstract
6
6
{
7
+ /// <summary>
8
+ /// Windows API structure used by VirtualQuery, see https://msdn.microsoft.com/en-us/library/windows/desktop/aa366775.aspx
9
+ /// </summary>
7
10
[ StructLayout ( LayoutKind . Sequential ) ]
8
11
public struct MEMORY_BASIC_INFORMATION
9
12
{
@@ -16,6 +19,9 @@ public struct MEMORY_BASIC_INFORMATION
16
19
public uint Type ;
17
20
}
18
21
22
+ /// <summary>
23
+ /// Windows API constants used by VirtualQuery, see https://msdn.microsoft.com/en-us/library/windows/desktop/aa366786.aspx
24
+ /// </summary>
19
25
public enum ALLOCATION_PROTECTION : uint
20
26
{
21
27
PAGE_EXECUTE = 0x00000010 ,
@@ -30,7 +36,11 @@ public enum ALLOCATION_PROTECTION : uint
30
36
PAGE_NOCACHE = 0x00000200 ,
31
37
PAGE_WRITECOMBINE = 0x00000400
32
38
}
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>
34
44
[ ComImport ( ) , Guid ( "00020400-0000-0000-C000-000000000046" ) ]
35
45
[ InterfaceType ( ComInterfaceType . InterfaceIsIUnknown ) ]
36
46
public interface IDispatch
@@ -52,13 +62,23 @@ int Invoke([In] int dispIdMember,
52
62
53
63
public static class ComHelper
54
64
{
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>
55
71
public static bool HRESULT_FAILED ( int hr ) => hr < 0 ;
56
72
}
57
73
58
74
public static class IDispatchHelper
59
75
{
60
76
static Guid GUID_NULL = new Guid ( ) ;
61
77
78
+ /// <summary>
79
+ /// IDispatch::Invoke flags
80
+ /// see https://msdn.microsoft.com/en-gb/library/windows/desktop/ms221479(v=vs.85).aspx
81
+ /// </summary>
62
82
public enum InvokeKind : int
63
83
{
64
84
DISPATCH_METHOD = 1 ,
@@ -67,6 +87,10 @@ public enum InvokeKind : int
67
87
DISPATCH_PROPERTYPUTREF = 8 ,
68
88
}
69
89
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>
70
94
[ StructLayout ( LayoutKind . Sequential ) ]
71
95
public struct VARIANT
72
96
{
@@ -78,7 +102,12 @@ public struct VARIANT
78
102
IntPtr data2 ;
79
103
}
80
104
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>
82
111
private static ComTypes . DISPPARAMS PrepareDispatchArgs ( object [ ] args )
83
112
{
84
113
var pDispParams = new ComTypes . DISPPARAMS ( ) ;
@@ -106,7 +135,11 @@ private static ComTypes.DISPPARAMS PrepareDispatchArgs(object[] args)
106
135
[ DllImport ( "oleaut32.dll" , SetLastError = true , CallingConvention = CallingConvention . StdCall ) ]
107
136
static extern Int32 VariantClear ( IntPtr pvarg ) ;
108
137
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>
110
143
private static void UnprepareDispatchArgs ( ComTypes . DISPPARAMS pDispParams )
111
144
{
112
145
if ( pDispParams . rgvarg != IntPtr . Zero )
@@ -125,7 +158,15 @@ private static void UnprepareDispatchArgs(ComTypes.DISPPARAMS pDispParams)
125
158
}
126
159
}
127
160
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>
129
170
public static object Invoke ( IDispatch obj , int memberId , InvokeKind invokeKind , object [ ] args = null )
130
171
{
131
172
var pDispParams = PrepareDispatchArgs ( args ) ;
@@ -149,7 +190,10 @@ public static object Invoke(IDispatch obj, int memberId, InvokeKind invokeKind,
149
190
}
150
191
}
151
192
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>
153
197
[ ComImport ( ) , Guid ( "00020401-0000-0000-C000-000000000046" ) ]
154
198
[ InterfaceType ( ComInterfaceType . InterfaceIsIUnknown ) ]
155
199
public interface ITypeInfo_Ptrs
@@ -175,6 +219,10 @@ public interface ITypeInfo_Ptrs
175
219
void ReleaseVarDesc ( IntPtr pVarDesc ) ;
176
220
}
177
221
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>
178
226
[ ComImport ( ) , Guid ( "DDD557E1-D96F-11CD-9570-00AA0051E5D4" ) ]
179
227
[ InterfaceType ( ComInterfaceType . InterfaceIsIUnknown ) ]
180
228
public interface IVBEComponent
@@ -214,8 +262,12 @@ public interface IVBEComponent
214
262
void Placeholder33 ( ) ;
215
263
void GetSomeRelatedTypeInfoPtrs ( out IntPtr A , out IntPtr B ) ; // returns 2 TypeInfos, seemingly related to this ITypeInfo, but slightly different.
216
264
}
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>
219
271
[ ComImport ( ) , Guid ( "CACC1E82-622B-11D2-AA78-00C04F9901D2" ) ]
220
272
[ InterfaceType ( ComInterfaceType . InterfaceIsIUnknown ) ]
221
273
public interface IVBETypeInfo
@@ -244,7 +296,10 @@ public interface IVBETypeInfo
244
296
IDispatch GetStdModAccessor ( ) ; // a handy extra vtable entry we can use to invoke members in standard modules.
245
297
}
246
298
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>
248
303
[ ComImport ( ) , Guid ( "00020402-0000-0000-C000-000000000046" ) ]
249
304
[ InterfaceType ( ComInterfaceType . InterfaceIsIUnknown ) ]
250
305
public interface ITypeLib_Ptrs
@@ -261,8 +316,10 @@ public interface ITypeLib_Ptrs
261
316
void ReleaseTLibAttr ( IntPtr pTLibAttr ) ;
262
317
}
263
318
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>
266
323
[ StructLayout ( LayoutKind . Sequential ) ]
267
324
struct VBEReferencesObj
268
325
{
@@ -276,8 +333,11 @@ struct VBEReferencesObj
276
333
IntPtr Placeholder2 ;
277
334
IntPtr RefCount ;
278
335
}
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>
281
341
[ StructLayout ( LayoutKind . Sequential ) ]
282
342
struct VBETypeLibObj
283
343
{
@@ -288,7 +348,11 @@ struct VBETypeLibObj
288
348
public IntPtr Next ;
289
349
}
290
350
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>
292
356
[ ComImport ( ) , Guid ( "DDD557E0-D96F-11CD-9570-00AA0051E5D4" ) ]
293
357
[ InterfaceType ( ComInterfaceType . InterfaceIsIUnknown ) ]
294
358
interface IVBEProject
@@ -317,6 +381,8 @@ interface IVBEProject
317
381
void CompileProject ( ) ; // throws COM exception 0x800A9C64 if error occurred during compile.
318
382
}
319
383
384
+ /*
385
+ Not currently used.
320
386
// IVBEProject2, vtable position just before the IVBEProject, not queryable, so needs aggregation
321
387
[ComImport(), Guid("FFFFFFFF-0000-0000-C000-000000000046")] //
322
388
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
@@ -330,7 +396,12 @@ interface IVBEProject2
330
396
void SetProjectHelpFileName(string value);
331
397
void SetProjectHelpContext(int value);
332
398
}
399
+ */
333
400
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>
334
405
public enum TYPEKIND_VBE
335
406
{
336
407
TKIND_ENUM = 0 ,
@@ -342,14 +413,20 @@ public enum TYPEKIND_VBE
342
413
TKIND_ALIAS = 6 ,
343
414
TKIND_UNION = 7 ,
344
415
345
- TKIND_VBACLASS = 8 , // extended by VBA, this is used for the outermost interface
416
+ TKIND_VBACLASS = 8 ,
346
417
}
347
418
419
+ /// <summary>
420
+ /// Used by methods in the ITypeInfo and ITypeLib interfaces. Usually used to get the root type or library name.
421
+ /// </summary>
348
422
public enum TypeLibConsts : int
349
423
{
350
424
MEMBERID_NIL = - 1 ,
351
425
}
352
426
427
+ /// <summary>
428
+ /// Some known COM HRESULTs used in our code
429
+ /// </summary>
353
430
public enum KnownComHResults : int
354
431
{
355
432
E_VBA_COMPILEERROR = unchecked ( ( int ) 0x800A9C64 ) ,
0 commit comments