Skip to content

Commit

Permalink
Merge pull request rubberduck-vba#3702 from WaynePhillipsEA/com-colle…
Browse files Browse the repository at this point in the history
…ctor-corrections

Minor corrections to uses of ITypeLib/ITypeInfo
  • Loading branch information
retailcoder committed Jan 17, 2018
2 parents 1efea16 + d722ce3 commit 88c6e7c
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Rubberduck.Parsing/ComReflection/ComEnumerationMember.cs
Expand Up @@ -18,9 +18,9 @@ public ComEnumerationMember(ITypeInfo info, VARDESC varDesc)
Value = (int)value.Value;
ValueType = value.VariantType;

var names = new string[255];
var names = new string[1];
int count;
info.GetNames(varDesc.memid, names, 1, out count);
info.GetNames(varDesc.memid, names, names.Length, out count);
Debug.Assert(count == 1);
Name = names[0];
}
Expand Down
2 changes: 1 addition & 1 deletion Rubberduck.Parsing/ComReflection/ComMember.cs
Expand Up @@ -85,7 +85,7 @@ private void LoadParameters(FUNCDESC funcDesc, ITypeInfo info)
Parameters = new List<ComParameter>();
var names = new string[255];
int count;
info.GetNames(Index, names, 255, out count);
info.GetNames(Index, names, names.Length, out count);

for (var index = 0; index < count - 1; index++)
{
Expand Down
4 changes: 2 additions & 2 deletions Rubberduck.Parsing/ComReflection/ComModule.cs
Expand Up @@ -52,14 +52,14 @@ public ComModule(ITypeLib typeLib, ITypeInfo info, TYPEATTR attrib, int index) :

private void GetComFields(ITypeInfo info, TYPEATTR attrib)
{
var names = new string[255];
var names = new string[1];
for (var index = 0; index < attrib.cVars; index++)
{
IntPtr varPtr;
info.GetVarDesc(index, out varPtr);
var desc = (VARDESC)Marshal.PtrToStructure(varPtr, typeof(VARDESC));
int length;
info.GetNames(desc.memid, names, 255, out length);
info.GetNames(desc.memid, names, names.Length, out length);
Debug.Assert(length == 1);

_fields.Add(new ComField(names[0], desc, index, DeclarationType.Constant));
Expand Down
2 changes: 2 additions & 0 deletions Rubberduck.Parsing/ComReflection/ComProject.cs
Expand Up @@ -93,6 +93,8 @@ private void ProcessLibraryAttributes(ITypeLib typeLibrary)
MinorVersion = typeAttr.wMinorVerNum;
_flags = (TypeLibTypeFlags)typeAttr.wLibFlags;
Guid = typeAttr.guid;

typeLibrary.ReleaseTLibAttr(attribPtr);
}
catch (COMException) { }
}
Expand Down
4 changes: 2 additions & 2 deletions Rubberduck.Parsing/ComReflection/ComStruct.cs
Expand Up @@ -27,14 +27,14 @@ public ComStruct(ITypeLib typeLib, ITypeInfo info, TYPEATTR attrib, int index)

private void GetFields(ITypeInfo info, TYPEATTR attrib)
{
var names = new string[255];
var names = new string[1];
for (var index = 0; index < attrib.cVars; index++)
{
IntPtr varPtr;
info.GetVarDesc(index, out varPtr);
var desc = (VARDESC)Marshal.PtrToStructure(varPtr, typeof(VARDESC));
int length;
info.GetNames(desc.memid, names, 255, out length);
info.GetNames(desc.memid, names, names.Length, out length);
Debug.Assert(length == 1);

_fields.Add(new ComField(names[0], desc, index, DeclarationType.UserDefinedTypeMember));
Expand Down

0 comments on commit 88c6e7c

Please sign in to comment.