Microsoft KB Archive/315501

= HOW TO: Provide Run-Time License Information for MsComm32.ocx in Microsoft Visual C++ =

Article ID: 315501

Article Last Modified on 8/15/2005

-

APPLIES TO


 * Microsoft Visual Studio 6.0 Enterprise Edition

-



This article was previously published under Q315501



IN THIS TASK
SUMMARY
 * Requirements
 * Obtain the License Key for MsComm32.ocx
 * Use the License Key in a Visual C++ MFC Program
 * Verification
 * Additional Information

REFERENCES



SUMMARY
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.

back to the top

Requirements
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

back to the top

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:

http://download.microsoft.com/download/vc60std/sample/1.1/NT45/EN-US/Licreqst.exe

 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: /* Copyright (c) 1994 WCHAR pwchLicenseKey[] = {    0x0043,     0x006F,     0x0070,     0x0079,     0x0072,     0x0069, 0x0067,    0x0068,     0x0074,     0x0020,     0x0028,     0x0063, 0x0029,    0x0020,     0x0031,     0x0039,     0x0039,     0x0034, 0x0020 };                    Click Copy Data to Clipboard to copy this text to the Clipboard for later use in a C/C++ program.

back to the top

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.</li> 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.</li> On the Project menu, click Add to project. Click Components and Controls to display the Components and Controls Gallery dialog box.</li> 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.</li> Edit the MainFrm.cpp file:   Add the following include file after the existing #include line for MainFrm.h:                        </li>  Add the declaration for pwchLicenseKey[], which you placed on the Clipboard earlier by using the License Key Requester tool: /* Copyright (c) 1994
 * 1) include &quot;CMSComm.h&quot;

WCHAR pwchLicenseKey[] = {    0x0043,     0x006F,     0x0070,     0x0079,     0x0072,     0x0069, 0x0067,    0x0068,     0x0074,     0x0020,     0x0028,     0x0063, 0x0029,    0x0020,     0x0031,     0x0039,     0x0039,     0x0034, 0x0020 };                       </li></ol> </li>  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,   sizeof(pwchLicenseKey)/sizeof(WCHAR)); // 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
 * SysFreeString(bStrLicense);

// Display a success or failure message to the user
 * MessageBox(NULL,

(pComm->m_hWnd ? &quot;Created OK&quot; : &quot;Not created&quot;), &quot;Debug&quot;, MB_OK);                   </li></ol>

back to the top

Verification
Run the program in the developer environment. A message box containing the text &quot;Created OK&quot; appears. The program also works correctly on computers on which MsComm32.ocx has been installed without a developer license.

back to the top

Additional Information
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.

back to the top

<div class="references_section">