This article describes how to provide run-time license data for the MsComm32 control in a Microsoft Visual C++ MFC program. The MsComm32.ocx custom control that is included with Visual C++ is a licensed control. When you install Visual Studio 6.0, a design-time license is installed with the control. For a non-developer computer, a run-time license is required.
The following list outlines the recommended hardware, software, network infrastructure, and service packs that are required:
Visual C++ 6.0
This article assumes that you are familiar with the following topics:
C++ programming experience for Windows
Obtain the License Key for MsComm32.ocx
Obtain the Licreqst.exe file from the Microsoft Download Center. To download this file, visit the following Microsoft Web site:
Double-click the self-extracting Licreqst.exe file.
You are prompted to specify a folder in which to extract the files. Specify a different folder from the folder in which the Licreqst.exe file is located because one of the files that is extracted is also named Licreqst.exe. Click Unzip.
Run the extracted Licreqst.exe file. The License Key Requestor program starts. In the Registered Controls box, click MSCOMMLib.MSComm.1. The license key data for the Currently Selected Control box displays license key data in the form of a C/C++ array declaration:
Click Copy Data to Clipboard to copy this text to the Clipboard for later use in a C/C++ program.
Use the License Key in a Visual C++ MFC Program
This section describes how to build a simple program that creates an instance of the MsComm32 control in an MFC program by using run-time license information.
Start Visual C++, and then create a new MFC AppWizard (EXE) project that is named called CommDemo.
The MFC AppWizard Wizard starts. In step 1, the user interface type must be Single Document. Click Finish to accept all of the defaults for this kind of program.
On the Project menu, click Add to project. Click Components and Controls to display the Components and Controls Gallery dialog box.
Click Registered ActiveX Controls, and then click Microsoft Communications Control 6.0. Click Insert, and then confirm that you want to add this component to the project. Confirm the generated class name of CMSComm. Click OK, and then click Close to close the gallery.
Edit the MainFrm.cpp file:
Add the following include file after the existing #include line for MainFrm.h:
Add the declaration for pwchLicenseKey, which you placed on the Clipboard earlier by using the License Key Requester tool:
Add the following code to the end of the CMainFrame::OnCreate method just before the final return statement. This code creates an instance of the CMSComm class by using the run-time license data that is found in pwchLicenseKey. This example only tests to determine if creation is possible, and then displays a diagnostic message.
// Create the license string
BSTR bStrLicense = ::SysAllocStringLen(pwchLicenseKey,
// Create the CMSComm object with run-time license data
CMSComm * pComm = new CMSComm;
pComm->Create(NULL, WS_VISIBLE, CRect(0,0,0,0),
this, 999, NULL, FALSE, bStrLicense);
// Release the memory for license string
// Display a success or failure message to the user
(pComm->m_hWnd ? "Created OK" : "Not created"),
Run the program in the developer environment. A message box containing the text "Created OK" appears. The program also works correctly on computers on which MsComm32.ocx has been installed without a developer license.
Do not use this technique to violate software licenses. You can, however, use this technique for MsComm32.ocx. You have vendor-supplied license keys for controls that you have legitimately licensed for distribution.
Note that running the LicReqst sample on a licensed computer to obtain an object's license key, and then distributing that key to allow programs to be developed on other non-licensed computers, may be a violation of established copyrights. For more information and to determine if an object's license key can be legally redistributed, see the License Agreement that is provided with the object, or contact the creator of the object.