I have a C++ DLL with 100+ exported functions which I want to transform into an OCX file. However, I only know how to export functions from an OCX which reside in the main class (called CmyCtrl by the Visual Studio 10 ActiveX control wizard) … by doing this:
BEGIN_DISPATCH_MAP(CmyCtrl, COleControl)
DISP_FUNCTION_ID(CmyCtrl, "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE)
END_DISPATCH_MAP()
and using appropriate IDL definitions.
I'm not really keen on restructuring the whole large project and moving every single function definition (which are spread out across 20 or so files) into the class. Can I export functions from an OCX (with full support for Intellisense etc. in VB6, where the control will be used) which are not in the class? How do I do that and what do I have to keep in mind?
You should have a wizard somewhere to add a new "ATlObject" that mean create a ne class instantiable via COM. With this you can split your function in different classes. Supposing you have an ATLproject, when adding a new class this wizard should appear:
By creating a new ATL simple object you have another class with exported function in the classical COM way. If you want you can always export a function with dllexport, but in this case you cannot use COM to interface with your component. You can even call function exported with the dll ( ocx ) the regular way by using the strategy:
Private Declare Function MyFuncName Lib "yourocx.ocx" ([.. parameters]) As [Return type]
but it is probably not the way to go in your case.