Skip to content

Commit

Permalink
reverted the changes to IVBProjectEx_VBE, and added IVBProjectEx2_VBE…
Browse files Browse the repository at this point in the history
… instead in case we want to use this interface in future
  • Loading branch information
WaynePhillipsEA committed Jan 22, 2018
1 parent 1e601db commit 337012e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
28 changes: 27 additions & 1 deletion Rubberduck.VBEEditor/ComManagement/TypeLibs/TypeLibs.cs
Expand Up @@ -101,7 +101,7 @@ public RestrictComInterfaceByAggregation(IntPtr outerObject)
Marshal.AddRef(_outerObject);

var aggObjPtr = Marshal.CreateAggregatedObject(_outerObject, this);
_wrappedObject = (ComTypes.ITypeInfo)Marshal.GetObjectForIUnknown(aggObjPtr); // when this CCW object gets released, it will free the aggObjInner (well, after GC)
_wrappedObject = (T)Marshal.GetObjectForIUnknown(aggObjPtr); // when this CCW object gets released, it will free the aggObjInner (well, after GC)
Marshal.Release(aggObjPtr); // _wrappedObject holds a reference to this now
}

Expand Down Expand Up @@ -494,6 +494,7 @@ public class TypeLibWrapper : ComTypes.ITypeLib, IDisposable
private DisposableList<TypeInfoWrapper> _typeInfosWrapped;
private readonly ComTypes.ITypeLib _wrappedObject;
private readonly bool _wrappedObjectIsWeakReference;
private RestrictComInterfaceByAggregation<IVBProjectEx2_VBE> _cachedIVBProjectEx2;

private string _name;
private string _docString;
Expand Down Expand Up @@ -524,6 +525,30 @@ private IVBProjectEx_VBE _IVBProjectEx
}
}
}
private IVBProjectEx2_VBE _IVBProjectEx2
{
// This is not yet used, but defined in case we want to use this interface at some point.
get
{
if (_cachedIVBProjectEx2 == null)
{
if (HasVBEExtensions())
{
// This internal VBE interface doesn't have a queryable IID.
// The vtable for this interface directly preceeds the _IVBProjectEx, and we can access it through an aggregation helper
var objIVBProjectExPtr = Marshal.GetComInterfaceForObject(_wrappedObject, typeof(IVBProjectEx_VBE));
objIVBProjectExPtr -= IntPtr.Size;
_cachedIVBProjectEx2 = new RestrictComInterfaceByAggregation<IVBProjectEx2_VBE>(objIVBProjectExPtr);
}
else
{
throw new ArgumentException("This ITypeLib is not hosted by the VBE, so does not support _IVBProjectEx");
}
}

return (IVBProjectEx2_VBE)_cachedIVBProjectEx2.WrappedObject;
}
}

private void CacheCommonProperties()
{
Expand All @@ -550,6 +575,7 @@ public void Dispose()
if (_isDisposed) return;
_isDisposed = true;

_cachedIVBProjectEx2?.Dispose();
_typeInfosWrapped?.Dispose();
if (!_wrappedObjectIsWeakReference) Marshal.ReleaseComObject(_wrappedObject);
}
Expand Down
20 changes: 17 additions & 3 deletions Rubberduck.VBEEditor/ComManagement/TypeLibs/TypeLibsAbstract.cs
Expand Up @@ -119,17 +119,31 @@ struct TypeLibObj_VBE
[ComImport(), Guid("DDD557E0-D96F-11CD-9570-00AA0051E5D4")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface IVBProjectEx_VBE
{
void Placeholder1();
void Placeholder2();
int VBE_LCID();
void Placeholder3();
void Placeholder4();
void Placeholder5();
void Placeholder6();
void Placeholder7();
string get_ConditionalCompilationArgs();
void set_ConditionalCompilationArgs(string args);
}

// IVBProjectEx2_VBE, vtable position just before the IVBProjectEx_VBE, not queryable, so needs aggregation
[ComImport(), Guid("FFFFFFFF-0000-0000-C000-000000000046")] //
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface IVBProjectEx2_VBE
{
void Placeholder1(); // returns E_NOTIMPL
void set_ProjectName(string value);
int VBE_LCID();
void set_ProjectVersion(ushort wMajorVerNum, ushort wMinorVerNum);
void set_ProjectGUID(ref Guid value);
void set_ProjectDescription(string value);
void set_ProjectHelpFileName(string value);
void set_ProjectHelpContext(int value);
string get_ConditionalCompilationArgs();
void set_ConditionalCompilationArgs(string args);
}

public enum TYPEKIND_VBE
Expand Down

0 comments on commit 337012e

Please sign in to comment.