Skip navigation.

Blog

OCX wrappers for .Net - The joy of AxInterop

Why are certain ActiveX Property definitions marked as ReadOnly when you drop an OCX into .Net? And why do some Method and Event definitions not appear as expected?

There is a Microsoft article - PRB: Name Collision in the ActiveX Wrapper Class, plus a note against the description of AxImp.exe - but it's not easy to find if you don't know what you're searching for.

The issue is that certain Property, Method and Event members are reserved words to AxImp, and so the resulting member in the AxInterop version has the letters Ctl appended to the front. In our case EditMode became CtlEditMode and Text became CtlText.

Unfortunately you still cannot override some of these properties like EditMode even in .Net so when converting code, you just have to remember that the (e.g.) .EditMode property isn't the one you actually need and you have to use .CtlEditMode instead. This is fine when trying to set the property as .Net will flag it as ReadOnly anyway, but reading from it accidentally could easily return a different result than that expected.

The list is probably quite extensive (all Microsoft have to say on the matter is "If the name of a member of the ActiveX control matches a name defined in the .NET Framework, Aximp.exe will prefix the member name with 'Ctl' when it creates the AxHost derived class"); a quick search of the web brings up things like the .State property, .Refresh method and .Layout event as other candidates for the Ctl treatment - so please add your own conversions to the comments below.

By on June 13, 2008 | Permalink | Comment


Reader Comments

Skip to form

There are currently no comments about this article.


Comment on This Article:

Your Name:
Your Email Address:
 

Your Email Address will not be made public,
but the MD5 hash of it will be used to display your Gravatar.
Comment:
All HTML, except <i>, <b>, <u> will require your comment to be moderated before it is publicly displayed.
 
If you would like your own avatar displayed, read about comment avatars.