ActiveX Controls: Converting a CDK Project to a Visual C++ Project
This article discusses converting existing OLE Custom Control Developer's Kit (CDK) projects (versions 1.0 and 1.1) to current Visual C++ projects. Because the support for ActiveX controls has been fully integrated into MFC, there are several changes that need to be made to an existing project before the control can be built successfully.
In summary, the necessary changes are:
Remove all references to the OCS30 libraries.
Remove RESIDENTNAME from the module definition (.DEF) file.
- Delete the contents of the project's output directories and TLB16 directory.
For demonstration purposes, this article converts a project named SAMPLE32.
To remove all references to the OCS30 libraries
In Visual C++, open the control's 32-bit project file, in this case, SAMPLE32.MAK.
On the Build menu, click Settings to open the Project Settings dialog box.
Click the Link tab.
Select the first target in the Output File Name box, in this case, Win32 ANSI Debug (SAMPLE.OCX).
In the Object/Library Modules box, delete any library name of the form "OCS30*.LIB." For example, when the Win32 ANSI Debug target is selected, delete the library name "OCS30D.LIB."
Repeat steps 4 and 5 for each target in the Output File Name box.
- Click the OK button to accept the changes and close the Object/Library Modules box.
To remove RESIDENTNAME from the module definition file
In Visual C++, open the control's 32-bit module definition file, in this case, SAMPLE32.DEF.
Delete each occurrence of the string
RESIDENTNAMEfrom the file. There are typically four occurrences of this string.
For example, the following line of code:
DllCanUnloadNow @1 RESIDENTNAME
should be changed to:
DllCanUnloadNow @1 PRIVATE
Note that using the PRIVATE modifier avoids warnings from the linker. Similarly, symbols such as DllRegisterServer and DllUnregisterServer should also have the PRIVATE modifier.
- On the File menu, click Save.
The final step is to remove any existing directories and project files from earlier builds. This ensures a clean build with the new project settings.
To delete the contents of the project's output directories and the TLB16 subdirectory
- At the DOS command prompt, File Manager, or Windows Explorer, delete the directories named “TLB16”, "OBJ32", "OBJD32", "OBJU32" and "OBJDU32" from the project directory.
One of the changes that occurred between the original release of the CDK and its integration into VC ++ 4.0, was the removal of the MFCANS32 DLL. This DLL was responsible for the ANSI/Unicode translation layer used for Unicode-based OLE interfaces with an ANSI-targeted control. If your control supported licensing, it was affected by this change.
In order for your control to function properly, you will need to make some code changes to the control implementation (.CPP) files.
If your control supports licensing, change the declaration of the license string, found in the control implementation (.CPP) file, to the following:
static const OLECHAR BASED_CODE _szLicString = OLESTR("Licensed Control Copyright (c) 1994-1995 My Corporation");
Every direct call to the OLE API that passes a string as a parameter must first convert the string by making a call to MultiByteToWideChar, and then passing the result to the SysAllocString function. The following example uses new MFC conversion macros to simplify calling the SysAllocString function:
USES_CONVERSION; TCHAR szMyString = _T("Licensed Control Copyright (c) 1994-1995 My Corporation"); //a multi-byte string BSTR strWide = SysAllocString(T2OLE(szMyString));
The USES_CONVERSION macro and the T2OLE macro are described in https://msdn.microsoft.com/en-us/library/805c56f8(v=vs.60).aspx , Using MFC MBCS/Unicode Conversion Macros. These macros simplify calling functions that require conversion between Unicode and MBCS, particularly OLE API functions such as SysAllocString.