Can't use OCX components on x64 - failed to create AxHost

So, I was plying around with OCX components, or rather I tried to do so unsuccessfully… I’m getting error pop-ups when trying to apply an OCX component to a form by dragging and dropping it over from the Toolbox. I get an error message that says “failed to create axhost”, see screenshot.


Any suggestions on how to deal with that? The weird thing is, it worked in the past and I’m not sure what I’m doing wrong just now. Also, I can compile the CVB tutorials just fine but I can’t add any additional OCX components.

I’m using CVB 13 64bit, C# and VS 2015.

This might be a Visual Studio issue. There are two ways you can compile for 64 bit: x64 as target platform and AnyCPU as target platform. If CVB 64 bit is installed, both variants should do the same, from what I understand.

Applying OCX to a form while the target platform is set to x64 worked fine in the past, for instance with VS 2008 and 2010. Though, the behavior seems to have change in 2015 and 2017.

Also, this is only an issue for OCX components of which VS does not yet have created the local wrappers and references like these ones here:


These wrappers and references are created by VS automatically when an OCX is placed on the form for the first time, as far as I know - Something about this behavior seems to have changed.

To sum up: change the target platform to AnyCPU and it all should work fine.


That worked, thanks!

I’m always a bit hesitant to use AnyCPU since I’m not really sure what it does. I only use x64 as target platform for 64 bit builds.

This is really weird behavior, and it would in fact be interesting to learn what the logic behind requiring AnyCPU for ActiveX instantiation in the Forms Designer is (after all, the Forms Designer is still a 32 bit process and will always open and parse the type library of the installed 32 bit version of the ActiveX control). You’re right in that this used to work in the past.

One thing I’d like to point out is that AnyCPU and x64 are not the same thing. You’re right if you say that they feel like the same thing if you are launching your application built with AnyCPU on a 64 bit system, but conceptually, AnyCPU leaves the architecture decision to the operating system, whereas x64 will insist on an x86-64 based system. Therefore AnyCPU programs may also start on a plain x86 operating system or even on one of the rare Windows ARM builds - as long as the things they depend on are available (which, for :cvb:, is unfortunately not that easy).

The fact that the :cvb: tutorials for the .Net languages for 64 bit are all set to AnyCPU is more than anything else a coincidence: When the first C# and VB.Net tutorials were written some 15 years ago, AnyCPU was the default that Visual Studio did come up with and it did not really make much of a difference which setting you chose for lack of a 64 bit operating system. When the first WOW-capable version of the 32 bit build of :cvb: was built, the tutorials for 32 bit were switched to x86, while those that entered the 64 bit build were simply left at AnyCPU

1 Like