ctllic.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992-1998 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Foundation Classes Reference and related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Microsoft Foundation Classes product.
  10. #include "stdafx.h"
  11. #ifdef AFXCTL_FACT_SEG
  12. #pragma code_seg(AFXCTL_FACT_SEG)
  13. #endif
  14. #ifdef _DEBUG
  15. #undef THIS_FILE
  16. static char THIS_FILE[] = __FILE__;
  17. #endif
  18. #define new DEBUG_NEW
  19. /////////////////////////////////////////////////////////////////////////////
  20. // AfxVerifyLicFile - Checks that a license file exists and contains a
  21. // specific byte pattern.
  22. BOOL AFXAPI AfxVerifyLicFile(HINSTANCE hInstance, LPCTSTR pszLicFileName,
  23. LPCOLESTR pszLicFileContents, UINT cch)
  24. {
  25. // Assume the worst...
  26. BOOL bVerified = FALSE;
  27. // Look for license file in same directory as this DLL.
  28. TCHAR szPathName[_MAX_PATH];
  29. ::GetModuleFileName(hInstance, szPathName, _MAX_PATH);
  30. LPTSTR pszFileName = _tcsrchr(szPathName, '\\') + 1;
  31. lstrcpy(pszFileName, pszLicFileName);
  32. #ifndef OLE2ANSI
  33. LPSTR pszKey = NULL;
  34. #endif
  35. LPBYTE pbContent = NULL;
  36. TRY
  37. {
  38. // Open file, read content and compare.
  39. CFile file(szPathName, CFile::modeRead);
  40. if (cch == -1)
  41. #ifdef OLE2ANSI
  42. cch = lstrlen(pszLicFileContents);
  43. #else
  44. cch = wcslen(pszLicFileContents);
  45. pszKey = (char*)_alloca(cch*2 + 1);
  46. cch = _wcstombsz(pszKey, pszLicFileContents, cch*2 + 1);
  47. #endif
  48. if (cch != 0)
  49. {
  50. --cch; // license file won't contain the terminating null char
  51. pbContent = (BYTE*)_alloca(cch);
  52. file.Read(pbContent, cch);
  53. #ifndef OLE2ANSI
  54. if (memcmp(pszKey, pbContent, (size_t)cch) == 0)
  55. #else
  56. if (memcmp(pszLicFileContents, pbContent, (size_t)cch) == 0)
  57. #endif
  58. bVerified = TRUE;
  59. }
  60. }
  61. END_TRY
  62. return bVerified;
  63. }
  64. /////////////////////////////////////////////////////////////////////////////
  65. // Force any extra compiler-generated code into AFX_INIT_SEG
  66. #ifdef AFX_INIT_SEG
  67. #pragma code_seg(AFX_INIT_SEG)
  68. #endif