11
11
12
12
// TODO add memory address validation in ReadStructureSafe
13
13
// TODO split into TypeInfos.cs
14
- // references expose the raw ITypeLibs
15
14
16
15
/// <summary>
17
16
/// For usage examples, please see VBETypeLibsAPI
@@ -302,6 +301,9 @@ public void Document(StringLineBuilder output)
302
301
/// </summary>
303
302
public class TypeInfoReference
304
303
{
304
+ TypeLibWrapper _vbeTypeLib ;
305
+ int _typeLibIndex ;
306
+
305
307
readonly string _rawString ;
306
308
readonly Guid _guid ;
307
309
readonly uint _majorVersion ;
@@ -318,8 +320,11 @@ public class TypeInfoReference
318
320
public string Path { get => _path ; }
319
321
public string Name { get => _name ; }
320
322
321
- public TypeInfoReference ( string referenceStringRaw )
323
+ public TypeInfoReference ( TypeLibWrapper vbeTypeLib , int typeLibIndex , string referenceStringRaw )
322
324
{
325
+ _vbeTypeLib = vbeTypeLib ;
326
+ _typeLibIndex = typeLibIndex ;
327
+
323
328
// Example: "*\G{000204EF-0000-0000-C000-000000000046}#4.1#9#C:\PROGRA~2\COMMON~1\MICROS~1\VBA\VBA7\VBE7.DLL#Visual Basic For Applications"
324
329
// LibidReference defined at https://msdn.microsoft.com/en-us/library/dd922767(v=office.12).aspx
325
330
// The string is split into 5 parts, delimited by #
@@ -346,6 +351,8 @@ public TypeInfoReference(string referenceStringRaw)
346
351
_name = referenceStringParts [ 4 ] ;
347
352
}
348
353
354
+ public TypeLibWrapper TypeLib { get => _vbeTypeLib . GetVBEReferenceTypeLibByIndex ( _typeLibIndex ) ; }
355
+
349
356
public void Document ( StringLineBuilder output )
350
357
{
351
358
output . AppendLine ( "- VBE Reference: " + Name + " [path: " + Path + ", majorVersion: " + MajorVersion +
@@ -1238,7 +1245,29 @@ public TypeInfoReference GetVBEReferenceByIndex(int index)
1238
1245
{
1239
1246
if ( index < target_IVBEProject . GetReferencesCount ( ) )
1240
1247
{
1241
- return new TypeInfoReference ( target_IVBEProject . GetReferenceString ( index ) ) ;
1248
+ return new TypeInfoReference ( this , index , target_IVBEProject . GetReferenceString ( index ) ) ;
1249
+ }
1250
+
1251
+ throw new ArgumentException ( $ "Specified index not valid for the references collection { index } .") ;
1252
+ }
1253
+ else
1254
+ {
1255
+ throw new ArgumentException ( "This TypeLib does not represent a VBE project, so we cannot get reference strings from it" ) ;
1256
+ }
1257
+ }
1258
+
1259
+ public TypeLibWrapper GetVBEReferenceTypeLibByIndex ( int index )
1260
+ {
1261
+ if ( HasVBEExtensions )
1262
+ {
1263
+ if ( index < target_IVBEProject . GetReferencesCount ( ) )
1264
+ {
1265
+ IntPtr referenceTypeLibPtr = target_IVBEProject . GetReferenceTypeLib ( index ) ;
1266
+ if ( referenceTypeLibPtr == IntPtr . Zero )
1267
+ {
1268
+ throw new ArgumentException ( "$Reference TypeLib not available - probably a missing reference." ) ;
1269
+ }
1270
+ return new TypeLibWrapper ( referenceTypeLibPtr ) ;
1242
1271
}
1243
1272
1244
1273
throw new ArgumentException ( $ "Specified index not valid for the references collection { index } .") ;
@@ -1320,7 +1349,7 @@ private void InitCommon()
1320
1349
public TypeLibWrapper ( IntPtr rawObjectPtr )
1321
1350
{
1322
1351
target_ITypeLib = ( ComTypes . ITypeLib ) Marshal . GetObjectForIUnknown ( rawObjectPtr ) ;
1323
- Marshal . Release ( rawObjectPtr ) ; // _wrappedObject holds a reference to this now
1352
+ Marshal . Release ( rawObjectPtr ) ; // target_ITypeLib holds a reference to this now
1324
1353
InitCommon ( ) ;
1325
1354
}
1326
1355
0 commit comments