rubberduck-vba / Rubberduck

Every programmer needs a rubberduck. COM add-in for the VBA & VB6 IDE (VBE).
https://rubberduckvba.com
GNU General Public License v3.0
1.92k stars 302 forks source link

COM collector needs appropriate handling actions for TKIND_ALIAS and TKIND_UNION #2538

Closed comintern closed 7 years ago

comintern commented 7 years ago

Neither of these COM types appear in the VBA object browser, and there really isn't a direct analogue to them in the language. For example, in MSHTML, the union tag__MIDL_IWinTypes_0009 is declared as:

typedef union tag__MIDL_IWinTypes_0009 {

long hInproc;

long hRemote;
} __MIDL_IWinTypes_0009;  

All of the following dim statements result in a compile error "User-defined type not defined":

Dim x as hInproc
Dim y as hRemote
Dim z as tag__MIDL_IWinTypes_0009 

This declaration... Dim x As [__MIDL_IWinTypes_0009] ...gives a compile error "Automation type not supported in Visual Basic", but it isn't clear if it's due to the fact that it's a 'union' or due to the naming (__ is usually a reserved identifier).

TKIND_ALIAS is a bit trickier, because it does appear that VBA recognizes them. These are currently treated as class Declarations in the COM collector, although that is not technically correct - they are treated like intrinsic types. In MIDL these appear as typedef declarations. A good example is in VBE7.dll:

typedef [public,
  custom(F914481D-9C62-4B43-9340-E9B2E6252E5F, 1)
]
long LONG_PTR;

Basically this is letting callers know that (at least on this 32 bit version), anything declared as LONG_PTR should be treated as a Long.

I'm up in the air as to whether these need a special form declaration or something else, but down the road they do need to be handled similarly to intrinsic types when they're used as asTypeDeclarations.

comintern commented 7 years ago

As far as I've been able to determine, TKIND_ALIAS doesn't seem to be natively supported in VBA. The LONG_PTR alias appears to be handled internally by VBE7.dll and exposed as a type keyword (and already handled in the COM collection). Disabling its resolution from the typelibs - this can be reopened if anyone happens to run across a library that has a TKIND_ALIAS that's exposed to VBA.

ThunderFrame commented 7 years ago

It's not a library, but I think Access Forms/Reports use aliases for controls that have names with non-standard names in them. That is, myForm.some_control and myForm.[some control] are both references to the same control. IIRC, only one of them is declared WithEvents

comintern commented 7 years ago

@ThunderFrame - That actually looks more like the extensible interface for myForm in the first case, and the evaluate member for the second. The referenced commit above breaks the hell out of the resolver though - these need to be handled internally in the COM collector.

wqweto commented 7 years ago

stdole2.tlb contains

    typedef [uuid(66504301-BE0F-101A-8BBB-00AA00300CAB), public]
    unsigned long OLE_COLOR;

and both VBA and VB6 accept

    Dim a As OLE_COLOR

and although OLE_COLOR cannot be located by searching w/ Object Browser in the IDE, the alias is still present as param/retval type on some method declarations.