Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

137 lines
5.1 KiB

  1. //---------------------------------------------------------------------------
  2. // Copyright (c) 1988-1996, Microsoft Corporation
  3. // All Rights Reserved
  4. // Information Contained Herein Is Proprietary and Confidential.
  5. //---------------------------------------------------------------------------
  6. readme.txt - This file
  7. vblic.h - VB Licensing support file declarations
  8. vblic.lib - VB Licensing support file
  9. vblicd.lib - VB Licensing support file
  10. ------------------------------- LICENSING -------------------------------
  11. OVERVIEW
  12. License enforcement is designed into the OLE Control architecture. The
  13. Custom Control Framework provides a simple mechanism for implementing
  14. custom licensing schemes. For Visual Basic 5.0 licensed controls, we are
  15. using the registry to store the license key. When the control is
  16. created on a form at design time the control's CheckForLicense function
  17. is called. The control should call VBValidateControlsLicense passing
  18. the license key to validate. If VBValidateControlsLicense returns TRUE
  19. then the license is valid, otherwise its not valid and your control will
  20. not load at design-time.
  21. When creating an Visual Basic compiled EXE file for a project containing
  22. your control, the GetLicenseKey function will be called to retrive your
  23. EXE license key. This key will be stored as part of the EXE. When the
  24. EXE is run, the EXE calls CheckLicenseKey passing in the license key that
  25. was stored at make EXE time. The code changes below demonstrate using
  26. the same license key for both the design environment and EXE.
  27. REQUIRED CODE CHANGES (using the Custom Control Framework)
  28. 1. If you use the CtlWiz template builder provided with the Framework,
  29. some of the licensing related code will be generated for you.
  30. The main .CPP file for the control should contain the following function:
  31. BOOL CheckForLicense()
  32. {
  33. }
  34. 2. Open the main .CPP file for your custom control project and add the
  35. following #include statement to the top:
  36. #include "vblic.h"
  37. 3. To add a license key, run GUIDGEN provided with Microsoft Visual C++ 4.0
  38. 4. Copy the generated guid value and assign it to the g_wszLicenseKey
  39. variable in the main .CPP file for the control project.
  40. For example:
  41. //Note: The following key is for demonstration purposes only
  42. // You should run GUIDGEN provided with Microsoft Visual C++
  43. // to generate your own unique GUID key.
  44. //
  45. const WCHAR g_wszLicenseKey [] = L"45DAEA50-4FF7-11cf-8ACB-00AA00C00905";
  46. 5. Add the following code to the CheckForLincense function in the main .CPP
  47. file:
  48. BOOL CheckForLicense()
  49. {
  50. MAKE_ANSIPTR_FROMWIDE(pszLicense, g_wszLicenseKey);
  51. return VBValidateControlsLicense(pszLicense);
  52. }
  53. 6. Add the following code to the CheckLicenseKey function:
  54. BOOL CheckLicenseKey
  55. (
  56. LPWSTR pwszKey
  57. )
  58. {
  59. // Compare the passed in license key w/ our EXE license key
  60. //
  61. return CompareLicenseStringsW(pwszKey, (LPWSTR) g_wszLicenseKey);
  62. }
  63. 7. Add the following code to the GetLicenseKey function:
  64. BSTR GetLicenseKey
  65. (
  66. void
  67. )
  68. {
  69. // Return our control unique license key
  70. //
  71. return SysAllocString(g_wszLicenseKey);
  72. }
  73. BUILDING THE CONTROL
  74. After following the above steps, recompile the code and link with VBLIC.LIB for
  75. a release build of VBLICD.LIB for a debug build.
  76. TESTING YOUR LICENSE KEY
  77. To test your license key you will need to add the value assigned to
  78. g_wszLicenseKey to License section of the registry under HKEY_CLASSES_ROOT.
  79. WARNING: DO NOT DISTRIBUTE LICENSE KEY OR THIS INFORMATION WITH YOUR CONTROL.
  80. The setup program, such as VB, should handle the installation of your control's
  81. license key. Below are two examples of how you can register your control's
  82. license key.
  83. Example 1, Steps using REGEDIT:
  84. - Run REGEDIT or REGEDIT32
  85. - Under the HKEY_CLASSES_ROOT section find Licenses.
  86. - If Licenses does not exist select Add Key from the Edit menu and add it
  87. under HKEY_CLASSES_ROOT
  88. - Select the Licenses key
  89. - From the Edit menu, select Add Key and enter the license value for the
  90. key name
  91. Example 2, Steps creating your own .REG file:
  92. - Run a text editor such as Notepad
  93. - Enter the following text:
  94. REGEDIT
  95. HKEY_CLASSES_ROOT\Licenses = Licensing: Copying the keys may be a violation of established copyrights.
  96. // My control license key
  97. HKEY_CLASSES_ROOT\Licenses\45DAEA50-4FF7-11cf-8ACB-00AA00C00905 = 0
  98. - Save the file using a .REG extension such as MYCTL.REG
  99. - Run RegEdit from the command line as follows to register your license key:
  100. RegEdit MYCTL.REG
  101. To test the key:
  102. - Run VB and attempt to add your control to the form
  103. - You should be able to add the control without error
  104. - Exit VB
  105. - Run REGEDIT and delete the controls license key from the registry
  106. - Run VB
  107. - Attempt to add the control to the form
  108. - You should encounter an invalid license error attempting to add the
  109. control to the form