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.

268 lines
6.7 KiB

  1. // UserInfo.cpp : Implementation of CUserInfo
  2. #include "stdafx.h"
  3. #include "icwhelp.h"
  4. #include "UserInfo.h"
  5. #include <regstr.h>
  6. #include <winnls.h>
  7. LPCTSTR lpcsz_FirstName = TEXT("Default First Name");
  8. LPCTSTR lpcsz_LastName = TEXT("Default Last Name");
  9. LPCTSTR lpcsz_Company = TEXT("Default Company");
  10. LPCTSTR lpcsz_Address1 = TEXT("Mailing Address");
  11. LPCTSTR lpcsz_Address2 = TEXT("Additional Address");
  12. LPCTSTR lpcsz_City = TEXT("City");
  13. LPCTSTR lpcsz_State = TEXT("State");
  14. LPCTSTR lpcsz_ZIPCode = TEXT("ZIP Code");
  15. LPCTSTR lpcsz_PhoneNumber = TEXT("Daytime Phone");
  16. /////////////////////////////////////////////////////////////////////////////
  17. // CUserInfo
  18. HRESULT CUserInfo::OnDraw(ATL_DRAWINFO& di)
  19. {
  20. return S_OK;
  21. }
  22. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  23. // Collect registered user information from the registry.
  24. //
  25. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  26. STDMETHODIMP CUserInfo::CollectRegisteredUserInfo(BOOL * pbRetVal)
  27. {
  28. USES_CONVERSION; // We will be converting from ANSI to BSTR
  29. HKEY hkey = NULL;
  30. TCHAR szRegValue[REGSTR_MAX_VALUE_LENGTH];
  31. // Initialize the function return value.
  32. *pbRetVal = FALSE;
  33. //Try to get the info form the win98/NT5 location
  34. if (RegOpenKey(HKEY_LOCAL_MACHINE,REGSTR_PATH_USERINFO,&hkey) != ERROR_SUCCESS)
  35. //try to get it form the win95 spot
  36. RegOpenKey(HKEY_CURRENT_USER,REGSTR_PATH_USERINFO,&hkey);
  37. if(hkey != NULL)
  38. {
  39. DWORD dwSize;
  40. DWORD dwType = REG_SZ;
  41. for (int iX = 0; iX < NUM_USERINFO_ELEMENTS; iX ++)
  42. {
  43. // Set the size each time
  44. dwSize = sizeof(TCHAR)*REGSTR_MAX_VALUE_LENGTH;
  45. if (RegQueryValueEx(hkey,
  46. m_aUserInfoQuery[iX].lpcszRegVal,
  47. NULL,
  48. &dwType,
  49. (LPBYTE)szRegValue,
  50. &dwSize) == ERROR_SUCCESS)
  51. {
  52. *m_aUserInfoQuery[iX].pbstrVal = A2BSTR(szRegValue);
  53. *pbRetVal = TRUE;
  54. }
  55. }
  56. RegCloseKey(hkey);
  57. }
  58. LCID lcid;
  59. lcid = GetUserDefaultLCID();
  60. m_lLcid = LOWORD(lcid);
  61. return S_OK;
  62. }
  63. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  64. // Persist collected registered user information to the registry.
  65. //
  66. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  67. STDMETHODIMP CUserInfo::PersistRegisteredUserInfo(BOOL * pbRetVal)
  68. {
  69. USES_CONVERSION; // We will be converting from ANSI to BSTR
  70. HKEY hkey = NULL;
  71. // Initialize the function return value.
  72. *pbRetVal = TRUE;
  73. //Try to get the userinfo form the win98/NT5 location
  74. if (RegOpenKey(HKEY_LOCAL_MACHINE,REGSTR_PATH_USERINFO,&hkey) != ERROR_SUCCESS)
  75. //try to get it form the win95 spot
  76. if (RegOpenKey(HKEY_CURRENT_USER,REGSTR_PATH_USERINFO,&hkey) != ERROR_SUCCESS)
  77. {
  78. // Create the key
  79. RegCreateKey(HKEY_LOCAL_MACHINE,REGSTR_PATH_USERINFO,&hkey);
  80. }
  81. if(hkey != NULL)
  82. {
  83. LPTSTR lpszRegVal;
  84. DWORD cbData;
  85. // Loop for each of the values to be persisted
  86. for (int iX = 0; iX < NUM_USERINFO_ELEMENTS; iX ++)
  87. {
  88. if (NULL != *m_aUserInfoQuery[iX].pbstrVal)
  89. {
  90. // Convert the BSTR to an ANSI string. the converted string will
  91. // be on the stack, so it will get freed when this function exits.
  92. lpszRegVal = OLE2A(*m_aUserInfoQuery[iX].pbstrVal);
  93. cbData = lstrlen(lpszRegVal);
  94. // Set the value
  95. if (RegSetValueEx(hkey,
  96. m_aUserInfoQuery[iX].lpcszRegVal,
  97. 0,
  98. REG_SZ,
  99. (LPBYTE) lpszRegVal,
  100. sizeof(TCHAR)*(cbData+1)) != ERROR_SUCCESS)
  101. {
  102. *pbRetVal = FALSE;
  103. }
  104. }
  105. }
  106. RegCloseKey(hkey);
  107. }
  108. return S_OK;
  109. }
  110. STDMETHODIMP CUserInfo::get_FirstName(BSTR * pVal)
  111. {
  112. if (pVal == NULL)
  113. return E_POINTER;
  114. *pVal = m_bstrFirstName.Copy();
  115. return S_OK;
  116. }
  117. STDMETHODIMP CUserInfo::put_FirstName(BSTR newVal)
  118. {
  119. m_bstrFirstName = newVal;
  120. return S_OK;
  121. }
  122. STDMETHODIMP CUserInfo::get_LastName(BSTR * pVal)
  123. {
  124. if (pVal == NULL)
  125. return E_POINTER;
  126. *pVal = m_bstrLastName.Copy();
  127. return S_OK;
  128. }
  129. STDMETHODIMP CUserInfo::put_LastName(BSTR newVal)
  130. {
  131. m_bstrLastName = newVal;
  132. return S_OK;
  133. }
  134. STDMETHODIMP CUserInfo::get_Company(BSTR * pVal)
  135. {
  136. if (pVal == NULL)
  137. return E_POINTER;
  138. *pVal = m_bstrCompany.Copy();
  139. return S_OK;
  140. }
  141. STDMETHODIMP CUserInfo::put_Company(BSTR newVal)
  142. {
  143. m_bstrCompany = newVal;
  144. return S_OK;
  145. }
  146. STDMETHODIMP CUserInfo::get_Address1(BSTR * pVal)
  147. {
  148. if (pVal == NULL)
  149. return E_POINTER;
  150. *pVal = m_bstrAddress1.Copy();
  151. return S_OK;
  152. }
  153. STDMETHODIMP CUserInfo::put_Address1(BSTR newVal)
  154. {
  155. m_bstrAddress1 = newVal;
  156. return S_OK;
  157. }
  158. STDMETHODIMP CUserInfo::get_Address2(BSTR * pVal)
  159. {
  160. if (pVal == NULL)
  161. return E_POINTER;
  162. *pVal = m_bstrAddress2.Copy();
  163. return S_OK;
  164. }
  165. STDMETHODIMP CUserInfo::put_Address2(BSTR newVal)
  166. {
  167. m_bstrAddress2 = newVal;
  168. return S_OK;
  169. }
  170. STDMETHODIMP CUserInfo::get_City(BSTR * pVal)
  171. {
  172. if (pVal == NULL)
  173. return E_POINTER;
  174. *pVal = m_bstrCity.Copy();
  175. return S_OK;
  176. }
  177. STDMETHODIMP CUserInfo::put_City(BSTR newVal)
  178. {
  179. m_bstrCity = newVal;
  180. return S_OK;
  181. }
  182. STDMETHODIMP CUserInfo::get_State(BSTR * pVal)
  183. {
  184. if (pVal == NULL)
  185. return E_POINTER;
  186. *pVal = m_bstrState.Copy();
  187. return S_OK;
  188. }
  189. STDMETHODIMP CUserInfo::put_State(BSTR newVal)
  190. {
  191. m_bstrState = newVal;
  192. return S_OK;
  193. }
  194. STDMETHODIMP CUserInfo::get_ZIPCode(BSTR * pVal)
  195. {
  196. if (pVal == NULL)
  197. return E_POINTER;
  198. *pVal = m_bstrZIPCode.Copy();
  199. return S_OK;
  200. }
  201. STDMETHODIMP CUserInfo::put_ZIPCode(BSTR newVal)
  202. {
  203. m_bstrZIPCode = newVal;
  204. return S_OK;
  205. }
  206. STDMETHODIMP CUserInfo::get_PhoneNumber(BSTR * pVal)
  207. {
  208. if (pVal == NULL)
  209. return E_POINTER;
  210. *pVal = m_bstrPhoneNumber.Copy();
  211. return S_OK;
  212. }
  213. STDMETHODIMP CUserInfo::put_PhoneNumber(BSTR newVal)
  214. {
  215. m_bstrPhoneNumber = newVal;
  216. return S_OK;
  217. }
  218. STDMETHODIMP CUserInfo::get_Lcid(long * pVal) //BSTR * pVal)
  219. {
  220. if (pVal == NULL)
  221. return E_POINTER;
  222. *pVal = m_lLcid;
  223. return S_OK;
  224. }