Using an OCX control in a C# .NET console application

Leeron picture Leeron · Jul 12, 2010 · Viewed 10.5k times · Source

As the title points out, what I want to do is use an .OCX control (namely AxShockwaveFlashObject) in a C# console application. I assume that it's possible, as I've seen it done before. but it was C++, and I don't even sure it was .NET. So, is it possible? and if so, how?

Thanks, Leeron

Answer

Ed Noepel picture Ed Noepel · Jul 12, 2010

An OCX file is just a native DLL with a different file extension. You should be able to interop with it without creating any UI, unless the control itself relies on creation of a window handle, in which case the hidden form approach would be best.

If you do not already have the interop DLLs (which expose the managed interface for the COM component), you can generate them using the commandline aximp (Windows Forms ActiveX Control Importer) tool or by dragging the OCX into the Visual Studio Toolbox.