I ran into what seems
to be a bug in AXIMP.EXE (and the corresponding process in Visual Studio .NET)
recently. I tried using one of our older, MFC-based ActiveX controls in
Visual Studio .NET toolbox. It barfed generating the interop DLLs, giving the
error "Cannot apply indexing with [] to an expression of type <classname>.
AxImp.exe generated the same error.
Looking at the generated source code for the wrapper control
(which AxImp is kind enough to keep around for you) revealed the problem. The
AxImp process generates two DLLs - an interop DLL for the types in the COM type
library (the equivalent of doing a tlbimp.exe), and a control DLL which
contains Windows Forms control wrappers. The control wrappers delegate their
calls to a contained instance of the interop type. So if you have an
ActiveX control called MyControl, two classes are generated - an interop
class MyControl, and a wrapper Windows Forms control called AxMyControl.
AxMyControl basically delegates most of its work to a contained instance of the
interop class MyControl.
Well, in this case apparently the code that generates the
interop dll and the code that generates the wrapper control disagree on how to
interpret the type library. Our ActiveX control has a property on it called
Item. The wrapper control was converting that call into an indexer (this[]) -
presumably based on the name. But the interop dll doesn't - it leaves it has
get_Item(). This seems to be because the Item property doesn't have a DISPID of
DISPID_VALUE (don't ask why, it's a weird historical quirk). If I change the
DISPID to be DISPID_VALUE, everything works.
I guess it's a pretty
obscure case, but it's a pain.
I was able to hand
edit the generated wrapper control source to get it to compile. Unfortunately, I
then discovered the second bit of silliness - if you run AxImp by
hand, it doesn't add the ToolboxItem attribute to the generated controls. It
seems that you have to add it by
hand, which isn't required when using Visual Studio .NET. That makes the
standalone tool a lot less convenient to use.