Sunday, April 17, 2011

Building an OCX with VS.NET?

What happened to OCX's? Are they no longer possible to create with the latest tools?

I need to create an ActiveX control that I can place in Word, PowerPoint and Excel documents. If I use VS.NET, I can only create a UserControl DLL with COM Interop, but I don't think I can add that using the "More Controls" toolbox of PowerPoint's Developer Tab.

What would you do?

From stackoverflow
  • Yes, you can still create them. But you can't create an OCX with a .NET language. Need to be unmanaged C++ (or VB). The DLLs with COM interop you can create in C# or VB.NET are just .NET objects that are invoked via CCW.

    Jason : Are they on their way out (OCXs)?
    DannySmurf : I'd say that's very likely. With the move to .NET, COM is really a legacy technology now in any form. There's little reason these days to use an OCX. A CCW-invoked .NET assembly is almost always a better solution now.
    recursive : What is CCW? I assume you're referring to something other than concealed carry.
    DannySmurf : COM-Callable Wrapper
  • Use a C++ or VB compiler which can target native code + ActiveX.

    kenny : yup. they were so easy to create in VB6.
  • You can still use .NET to create ActiveX components. However, this is experimental and not recommended. If you still want to try it you can find information in the blog of Andrew Whitechapel:

    Using Managed Controls as ActiveX Controls

    But as Andrew says:

    This seems to work OK for Excel (with the very limited testing I've done), partly works with PowerPoint, but fails miserably with Word.

    So if you don't want to spend a lot of time debugging strange errors I would recommend you to use the old VB 6.0 and Visual Studio 6.0 to build you ActiveX components.

  • Depending on what you need to do, an Add-in may be more appropriate than an OCX, and you can certainly create those with .NET. You should also look at the Visual Studio Tools for Office, not as a direct replacement for an OCX, but only to understand the new capabilities. It may show you new approaches to the problems you're now solving with an OCX.


Post a Comment