RegOpenKeyEx和RegCreateKeyEx函数
来源:互联网 发布:js 百分比校验 编辑:程序博客网 时间:2024/04/30 02:30
由于电脑经常会关闭,或者应用程序也会经常关闭,但有一些参数是经常需要保存。比如当你打开程序,并设置了窗口的大小,想每次打开时都设置窗口为上次打开的大小。这样就需要保存窗口的大小,那么窗口大小的参数保存到那里呢?其实在Windows里最方便的做法,就是保存到注册表里。又比如游戏登录时,总是想保存最后一个登录的用户,那么也需要保存这个用户到注册表里。其实注册表是Windows保存系统配置的数据库,比如不同的语言设置,不同的时区设置,不同的用户登录,不同的权限等等。下面就来学习怎么样使用函数RegOpenKeyEx来打开注册表里的键和用函数RegCreateKeyEx来创建新的键。
函数RegOpenKeyEx和RegCreateKeyEx声明如下:
WINADVAPI
LONG
APIENTRY
RegOpenKeyExA (
__in HKEY hKey,
__in_opt LPCSTR lpSubKey,
__reserved DWORD ulOptions,
__in REGSAM samDesired,
__out PHKEY phkResult
);
WINADVAPI
LONG
APIENTRY
RegOpenKeyExW (
__in HKEY hKey,
__in_opt LPCWSTR lpSubKey,
__reserved DWORD ulOptions,
__in REGSAM samDesired,
__out PHKEY phkResult
);
#ifdef UNICODE
#define RegOpenKeyEx RegOpenKeyExW
#else
#define RegOpenKeyEx RegOpenKeyExA
#endif // !UNICODE
WINADVAPI
LONG
APIENTRY
RegCreateKeyExA (
__in HKEY hKey,
__in LPCSTR lpSubKey,
__reserved DWORD Reserved,
__in_opt LPSTR lpClass,
__in DWORD dwOptions,
__in REGSAM samDesired,
__in_opt LPSECURITY_ATTRIBUTES lpSecurityAttributes,
__out PHKEY phkResult,
__out_opt LPDWORD lpdwDisposition
);
WINADVAPI
LONG
APIENTRY
RegCreateKeyExW (
__in HKEY hKey,
__in LPCWSTR lpSubKey,
__reserved DWORD Reserved,
__in_opt LPWSTR lpClass,
__in DWORD dwOptions,
__in REGSAM samDesired,
__in_opt LPSECURITY_ATTRIBUTES lpSecurityAttributes,
__out PHKEY phkResult,
__out_opt LPDWORD lpdwDisposition
);
#ifdef UNICODE
#define RegCreateKeyEx RegCreateKeyExW
#else
#define RegCreateKeyEx RegCreateKeyExA
#endif // !UNICODE
hKey是主键。
lpSubKey是子键。
ulOptions是选项。
samDesired是键的操作。
phkResult是打开的键返回。
lpClass是新键值。
调用函数的例子如下:
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/caimouse/archive/2007/11/02/1864163.aspx
函数RegOpenKeyEx和RegCreateKeyEx声明如下:
WINADVAPI
LONG
APIENTRY
RegOpenKeyExA (
__in HKEY hKey,
__in_opt LPCSTR lpSubKey,
__reserved DWORD ulOptions,
__in REGSAM samDesired,
__out PHKEY phkResult
);
WINADVAPI
LONG
APIENTRY
RegOpenKeyExW (
__in HKEY hKey,
__in_opt LPCWSTR lpSubKey,
__reserved DWORD ulOptions,
__in REGSAM samDesired,
__out PHKEY phkResult
);
#ifdef UNICODE
#define RegOpenKeyEx RegOpenKeyExW
#else
#define RegOpenKeyEx RegOpenKeyExA
#endif // !UNICODE
WINADVAPI
LONG
APIENTRY
RegCreateKeyExA (
__in HKEY hKey,
__in LPCSTR lpSubKey,
__reserved DWORD Reserved,
__in_opt LPSTR lpClass,
__in DWORD dwOptions,
__in REGSAM samDesired,
__in_opt LPSECURITY_ATTRIBUTES lpSecurityAttributes,
__out PHKEY phkResult,
__out_opt LPDWORD lpdwDisposition
);
WINADVAPI
LONG
APIENTRY
RegCreateKeyExW (
__in HKEY hKey,
__in LPCWSTR lpSubKey,
__reserved DWORD Reserved,
__in_opt LPWSTR lpClass,
__in DWORD dwOptions,
__in REGSAM samDesired,
__in_opt LPSECURITY_ATTRIBUTES lpSecurityAttributes,
__out PHKEY phkResult,
__out_opt LPDWORD lpdwDisposition
);
#ifdef UNICODE
#define RegCreateKeyEx RegCreateKeyExW
#else
#define RegCreateKeyEx RegCreateKeyExA
#endif // !UNICODE
hKey是主键。
lpSubKey是子键。
ulOptions是选项。
samDesired是键的操作。
phkResult是打开的键返回。
lpClass是新键值。
调用函数的例子如下:
#001 //打注册表。HKEY_CURRENT_USER\"Software"\"Wincpp"\"testreg"#002 //蔡军生 2007/11/02 QQ:9073204 深圳#003 HKEY GetAppRegistryKey(void)#004 {#005 HKEY hAppKey = NULL;#006 HKEY hSoftKey = NULL;#007 HKEY hCompanyKey = NULL;#008 #009 //打开HKEY_CURRENT_USER\"Software"。#010 if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("software"), 0, KEY_WRITE|KEY_READ,#011 &hSoftKey) == ERROR_SUCCESS)#012 {#013 DWORD dw;#014 //创建并打开HKEY_CURRENT_USER\"Software"\"Wincpp"#015 if (RegCreateKeyEx(hSoftKey, _T("Wincpp"), 0, REG_NONE,#016 REG_OPTION_NON_VOLATILE, KEY_WRITE|KEY_READ, NULL,#017 &hCompanyKey, &dw) == ERROR_SUCCESS)#018 {#019 //创建并打开HKEY_CURRENT_USER\"Software"\"Wincpp"\"testreg"#020 RegCreateKeyEx(hCompanyKey, _T("testreg"), 0, REG_NONE,#021 REG_OPTION_NON_VOLATILE, KEY_WRITE|KEY_READ, NULL,#022 &hAppKey, &dw);#023 }#024 }#025 #026 //关闭打开的键值。#027 if (hSoftKey != NULL)#028 {#029 RegCloseKey(hSoftKey);#030 } #031 #032 if (hCompanyKey != NULL)#033 {#034 RegCloseKey(hCompanyKey);#035 } #036 #037 return hAppKey;#038 }
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/caimouse/archive/2007/11/02/1864163.aspx
- RegOpenKeyEx和RegCreateKeyEx函数
- RegOpenKeyEx和RegCreateKeyEx函数
- RegOpenKeyEx和RegCreateKeyEx函数
- RegOpenKeyEx和RegCreateKeyEx函数
- RegOpenKeyEx和RegCreateKeyEx函数
- Windows API一日一练(63)RegOpenKeyEx和RegCreateKeyEx函数
- Windows API一日一练(63)RegOpenKeyEx和RegCreateKeyEx函数
- Windows API一日一练(63)RegOpenKeyEx和RegCreateKeyEx函数
- Windows API一日一练(63)RegOpenKeyEx和RegCreateKeyEx函数
- Windows API一日一练(63)RegOpenKeyEx和RegCreateKeyEx函数
- Windows API一日一练(63)RegOpenKeyEx和RegCreateKeyEx函数
- Windows API一日一练(63)RegOpenKeyEx和RegCreateKeyEx函数
- Windows API一日一练(63)RegOpenKeyEx和RegCreateKeyEx函数
- Windows API一日一练(63)RegOpenKeyEx和RegCreateKeyEx函数
- Windows API一日一练(63)RegOpenKeyEx和RegCreateKeyEx函数
- Windows API一日一练(63)RegOpenKeyEx和RegCreateKeyEx函数
- Windows API一日一练(63)RegOpenKeyEx和RegCreateKeyEx函数
- Windows API一日一练(63)RegOpenKeyEx和RegCreateKeyEx函数
- Searchable之自定义Suggestions(下)
- 优酷视频真实地址解析
- python邮件【mail】相关模块简单操作
- Silverlight+IIS7.5+WCF Unhandled Error in Silverlight Application Load operation failed for query
- Dell D380 XP sp3下VS2010经常会crash的问题 (intel graphics driver)
- RegOpenKeyEx和RegCreateKeyEx函数
- 解析C#中is和as操作符的用法
- Android电池状态的监听
- Extjs中PagingToolbar的使用
- VS2008 中编译错误error PRJ0003 : Error spawning 'cmd.exe'
- jquery 常用的选择器
- 常用SQL语句
- 收录一个合并grivView合并同一列中的相同单元格
- SYBASE 12.5 维护手册 1. 基本概念篇