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.

296 lines
6.9 KiB

  1. /* $Header: "%n;%v %f LastEdit=%w Locker=%l" */
  2. /* "PROFLSPT.C;2 23-Dec-92,17:54:44 LastEdit=IGOR Locker=IGOR" */
  3. /************************************************************************
  4. * Copyright (c) Wonderware Software Development Corp. 1991-1992. *
  5. * All Rights Reserved. *
  6. *************************************************************************/
  7. /* $History: Beg
  8. $History: End */
  9. #include "api1632.h"
  10. #define NOCOMM
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #include "windows.h"
  14. #include "tmpbuf.h"
  15. #include "proflspt.h"
  16. #define NDDE_REG_PARAMETERS "Software\\Microsoft\\NetDDE\\Parameters"
  17. BOOL
  18. WINAPI
  19. TestPrivateProfile(
  20. LPCSTR lpszSection,
  21. LPCSTR lpszKey,
  22. LPCSTR lpszFile )
  23. {
  24. HKEY hKey;
  25. LONG ret;
  26. char szKeySpec[ 1024 ];
  27. DWORD cbId = 1024;
  28. DWORD dwType = 0;
  29. wsprintf( szKeySpec, "%s\\%s", NDDE_REG_PARAMETERS, lpszSection );
  30. ret = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
  31. szKeySpec,
  32. 0,
  33. KEY_READ,
  34. &hKey );
  35. if( ret == ERROR_SUCCESS ) {
  36. ret = RegQueryValueEx( hKey,
  37. (LPSTR)lpszKey,
  38. NULL,
  39. &dwType,
  40. (LPBYTE)szKeySpec,
  41. &cbId );
  42. RegCloseKey( hKey );
  43. }
  44. return(ret == ERROR_SUCCESS);
  45. }
  46. BOOL
  47. WINAPI
  48. MyWritePrivateProfileString(
  49. LPCSTR lpszSection,
  50. LPCSTR lpszKey,
  51. LPCSTR lpszString,
  52. LPCSTR lpszFile )
  53. {
  54. HKEY hKey;
  55. int ret = -1;
  56. char szKeySpec[ 1024 ];
  57. WCHAR szValueBuf[512];
  58. WCHAR szKeyBuf[256];
  59. DWORD cbSize;
  60. DWORD dwDisposition;
  61. wsprintf( szKeySpec, "%s\\%s", NDDE_REG_PARAMETERS, lpszSection );
  62. cbSize = MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED,
  63. lpszString, -1,
  64. (LPWSTR)szValueBuf, 512);
  65. if (cbSize) {
  66. ret = RegCreateKeyEx( HKEY_LOCAL_MACHINE,
  67. szKeySpec,
  68. 0,
  69. "NetDDEParameter",
  70. REG_OPTION_NON_VOLATILE,
  71. KEY_ALL_ACCESS,
  72. (LPSECURITY_ATTRIBUTES) NULL,
  73. &hKey,
  74. &dwDisposition );
  75. if( ret == ERROR_SUCCESS ) {
  76. MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED,
  77. lpszKey, -1,
  78. (LPWSTR)szKeyBuf, 256);
  79. ret = RegSetValueExW( hKey,
  80. (LPWSTR)szKeyBuf,
  81. (DWORD_PTR)NULL,
  82. REG_SZ,
  83. (LPBYTE)szValueBuf,
  84. cbSize * sizeof(WCHAR) );
  85. RegCloseKey( hKey );
  86. }
  87. }
  88. return( ret == ERROR_SUCCESS );
  89. }
  90. BOOL
  91. FAR PASCAL
  92. MyWritePrivateProfileInt(
  93. LPSTR lpAppName,
  94. LPSTR lpKeyName,
  95. int nValue,
  96. LPSTR lpFileName )
  97. {
  98. HKEY hKey;
  99. int ret;
  100. char szKeySpec[ 1024 ];
  101. DWORD dwDisposition;
  102. wsprintf( szKeySpec, "%s\\%s", NDDE_REG_PARAMETERS, lpAppName );
  103. ret = RegCreateKeyEx( HKEY_LOCAL_MACHINE,
  104. szKeySpec,
  105. 0,
  106. "NetDDEParameter",
  107. REG_OPTION_NON_VOLATILE,
  108. KEY_ALL_ACCESS,
  109. (LPSECURITY_ATTRIBUTES) NULL,
  110. &hKey,
  111. &dwDisposition );
  112. if( ret == ERROR_SUCCESS ) {
  113. ret = RegSetValueEx( hKey,
  114. (LPSTR)lpKeyName,
  115. (DWORD_PTR)NULL,
  116. REG_DWORD,
  117. (LPBYTE)&nValue,
  118. sizeof(nValue) );
  119. RegCloseKey( hKey );
  120. }
  121. return( ret == ERROR_SUCCESS );
  122. }
  123. BOOL
  124. FAR PASCAL
  125. WritePrivateProfileLong(
  126. LPSTR lpAppName,
  127. LPSTR lpKeyName,
  128. LONG lValue,
  129. LPSTR lpFileName )
  130. {
  131. return( MyWritePrivateProfileInt( lpAppName, lpKeyName,
  132. lValue, lpFileName ) );
  133. }
  134. UINT
  135. WINAPI
  136. MyGetPrivateProfileInt(
  137. LPCSTR lpszSection,
  138. LPCSTR lpszKey,
  139. INT dwDefault,
  140. LPCSTR lpszFile )
  141. {
  142. HKEY hKey;
  143. int ret;
  144. char szKeySpec[ 1024 ];
  145. BOOL bRetrieved = FALSE;
  146. DWORD dwValue;
  147. DWORD cbId = sizeof(dwValue);
  148. DWORD dwType = 0;
  149. wsprintf( szKeySpec, "%s\\%s", NDDE_REG_PARAMETERS, lpszSection );
  150. ret = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
  151. szKeySpec,
  152. 0,
  153. KEY_READ,
  154. &hKey );
  155. if( ret == ERROR_SUCCESS ) {
  156. ret = RegQueryValueEx( hKey,
  157. (LPSTR)lpszKey,
  158. NULL,
  159. &dwType,
  160. (LPBYTE)&dwValue,
  161. &cbId );
  162. if( ret == ERROR_SUCCESS ) {
  163. if( dwType == REG_DWORD ) {
  164. bRetrieved = TRUE;
  165. }
  166. }
  167. RegCloseKey( hKey );
  168. }
  169. if( bRetrieved ) {
  170. return( dwValue );
  171. } else {
  172. return( dwDefault );
  173. }
  174. }
  175. DWORD
  176. WINAPI
  177. MyGetPrivateProfileString(
  178. LPCSTR lpszSection,
  179. LPCSTR lpszKey,
  180. LPCSTR lpszDefault,
  181. LPSTR lpszReturnBuffer,
  182. DWORD cbReturnBuffer,
  183. LPCSTR lpszFile )
  184. {
  185. HKEY hKey;
  186. int ret;
  187. char szKeySpec[ 1024 ];
  188. WCHAR szKeyBuf[256];
  189. WCHAR szValueBuf[512];
  190. BOOL bRetrieved = FALSE;
  191. DWORD cbId = 512*sizeof(WCHAR);
  192. DWORD dwType = 0;
  193. BOOL fWide;
  194. wsprintf( szKeySpec, "%s\\%s", NDDE_REG_PARAMETERS, lpszSection );
  195. ret = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
  196. szKeySpec,
  197. 0,
  198. KEY_READ,
  199. &hKey );
  200. if( ret == ERROR_SUCCESS ) {
  201. MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED,
  202. lpszKey, -1,
  203. (LPWSTR)szKeyBuf, 256);
  204. ret = RegQueryValueExW( hKey,
  205. (LPWSTR)szKeyBuf,
  206. NULL,
  207. &dwType,
  208. (LPBYTE)szValueBuf,
  209. &cbId );
  210. if (ret == ERROR_SUCCESS) {
  211. if( dwType == REG_SZ ) {
  212. cbId = WideCharToMultiByte(
  213. CP_ACP,
  214. WC_COMPOSITECHECK,
  215. (LPWSTR) szValueBuf,
  216. cbId / sizeof(WCHAR),
  217. lpszReturnBuffer,
  218. cbReturnBuffer,
  219. NULL,
  220. &fWide );
  221. if (cbId) {
  222. bRetrieved = TRUE;
  223. }
  224. }
  225. }
  226. RegCloseKey( hKey );
  227. }
  228. if( !bRetrieved ) {
  229. strncpy( lpszReturnBuffer, lpszDefault, cbReturnBuffer );
  230. }
  231. if( cbReturnBuffer > 0 ) {
  232. lpszReturnBuffer[cbReturnBuffer-1] = '\0';
  233. }
  234. return( lstrlen(lpszReturnBuffer) );
  235. }
  236. LONG
  237. FAR PASCAL
  238. GetPrivateProfileLong(
  239. LPSTR lpAppName,
  240. LPSTR lpKeyName,
  241. LONG lDefault,
  242. LPSTR lpFileName )
  243. {
  244. return( MyGetPrivateProfileInt( lpAppName, lpKeyName,
  245. lDefault, lpFileName ) );
  246. }