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



The information in this article applies to:

  • Microsoft Visual Studio, Enterprise Edition 6.0

This article was previously published under Q315501

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

  1. Obtain the Licreqst.exe file from the Microsoft Download Center. To download this file, visit the following Microsoft Web site:
  2. Double-click the self-extracting Licreqst.exe file.
  3. 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.
  4. 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
    };
    					
  5. 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.
  1. Start Visual C++, and then create a new MFC AppWizard (EXE) project that is named called CommDemo.
  2. 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.
  3. On the Project menu, click Add to project. Click Components and Controls to display the Components and Controls Gallery dialog box.
  4. 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.
  5. Edit the MainFrm.cpp file:
    1. Add the following include file after the existing #include line for MainFrm.h:
      #include "CMSComm.h"
      						
    2. Add the declaration for pwchLicenseKey[], which you placed on the Clipboard earlier by using the License Key Requester tool:
      /*
      Copyright (c) 1994 
      */ 
      
      WCHAR pwchLicenseKey[] =
      {
           0x0043,     0x006F,     0x0070,     0x0079,     0x0072,     0x0069,     
           0x0067,     0x0068,     0x0074,     0x0020,     0x0028,     0x0063,     
           0x0029,     0x0020,     0x0031,     0x0039,     0x0039,     0x0034,     
           0x0020
      };
      						
  6. 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 ? "Created OK" : "Not created"),
                 "Debug", MB_OK);
    					
back to the top

Verification

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.

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

REFERENCES

For additional information about licensing, click the article number below to view the article in the Microsoft Knowledge Base:

151771 LICREQST.EXE: Requesting a License Key from an Object

This article contains the sample LicReqst.exe program. This program demonstrates how to use the IClassFactory2 interface to request an object's license key.

For additional information about how to download Microsoft Support files, click the article number below to view the article in the Microsoft Knowledge Base:

119591 How to Obtain Microsoft Support Files from Online Services

back to the top

Modification Type:MinorLast Reviewed:8/15/2005
Keywords:kbdownload kbhowto kbHOWTOmaster KB315501 kbAudDeveloper