Source code of Windows XP (NT5)
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.

110 lines
2.2 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. data.cpp
  5. Abstract:
  6. Contains registry "Data" abstraction
  7. implementation
  8. Author:
  9. Mike Cirello
  10. Vijay Jayaseelan (vijayj)
  11. Revision History:
  12. 03 March 2001 :
  13. Rewamp the whole source to make it more maintainable
  14. (particularly readable)
  15. --*/
  16. #include "Data.h"
  17. //////////////////////////////////////////////////////////////////////
  18. // Construction/Destruction
  19. //////////////////////////////////////////////////////////////////////
  20. //
  21. // this class basically converts these variable types to a BYTE pointer
  22. // so the info can be stored in the registry
  23. //
  24. // Arguments:
  25. // b - data in BYTE stream. OPTIONAL
  26. // d - data as a DWORD. OPTIONAL
  27. // t - data in TCHAR stream. OPTIONAL
  28. // flag - which data type is valid?
  29. // bSize - if data is in BYTE stream this must have the length of the stream.
  30. //
  31. Data::Data(
  32. IN PBYTE b,
  33. IN DWORD d,
  34. IN PCTSTR t,
  35. IN DWORD flag,
  36. IN int bSize)
  37. {
  38. DWORD fourthbyte = 4278190080;
  39. DWORD thirdbyte = 16711680;
  40. DWORD secondbyte = 65280;
  41. DWORD firstbyte = 255;
  42. PCTSTR ptr;
  43. pByte = b;
  44. dword = d;
  45. pTchar = t;
  46. nFlags = flag;
  47. size = -1;
  48. switch (nFlags) {
  49. case (1):
  50. size = bSize;
  51. break;
  52. case (2):
  53. if ( pByte = new BYTE[4] ){
  54. size = 4;
  55. pByte[3] = (BYTE)((dword & fourthbyte) >> 24);
  56. pByte[2] = (BYTE)((dword & thirdbyte) >> 16);
  57. pByte[1] = (BYTE)((dword & secondbyte) >> 8);
  58. pByte[0] = (BYTE)(dword & firstbyte);
  59. }
  60. break;
  61. case (4):
  62. size = wcslen(t)+1;
  63. ptr = t+size;
  64. while(*ptr!='\0') {
  65. size += wcslen(ptr)+1;
  66. ptr = t+size;
  67. }
  68. size *= 2;
  69. size += 2;
  70. case (3):
  71. if (size == -1) {
  72. size = (wcslen(t)*2)+2;
  73. }
  74. if ( pByte = new BYTE[size] ) {
  75. for (int x=0;x<((size/2)-1);x++) {
  76. pByte[x*2] = (BYTE)(pTchar[x] & firstbyte);
  77. pByte[1+(x*2)] = (BYTE)((pTchar[x] & secondbyte) >> 8);
  78. }
  79. pByte[size-1] = pByte[size-2] = '\0';
  80. }
  81. break;
  82. default:
  83. break;
  84. }
  85. }