IRWERegTabFunction.cpp
上传用户:yatsl7111
上传日期:2007-01-08
资源大小:1433k
文件大小:8k
- // IRWERegTabFunction.cpp - 图像读写引擎系统注册表助手函数
- //
- #include "stdafx.h"
- #include "IRWERegTabFunction.h"
- // HKEY_CURRENT_USER
- static BYTE _rtd_PluginsPathInRegTable[] =
- "Software\VCHelp Software\coPathway\ISee Workgroup\IRWPlugins";
- static BYTE _rtd_PlugInsNumberName[] = "PluginsNumber";
- static BYTE _rtd_PlugInsNamesName[] = "PluginsNames";
- static BYTE _rtd_PlugInsPathName[] = "PluginsPath";
- static BYTE _rtd_FileName[] = "FileName";
- static BYTE _rtd_PRI[] = "PRI";
- static BYTE _rtd_Class[] = "ISeeIRWP";
- // 打开插件注册信息句柄(插件总句柄)
- HKEY _IRWERTF_OpenRegTab()
- {
- HKEY hKey = NULL;
- LONG result = ::RegOpenKeyEx(HKEY_CURRENT_USER,
- (LPCTSTR)_rtd_PluginsPathInRegTable,
- 0,
- KEY_ALL_ACCESS,
- (PHKEY)&hKey);
- return (result == ERROR_SUCCESS) ? hKey:NULL;
- }
- // 创建插件注册信息句柄(插件总句柄)
- HKEY _IRWERTF_CreateRegTab()
- {
- HKEY hKey = NULL;
- DWORD dwDisp = 0;
- LONG result = ::RegCreateKeyEx(HKEY_CURRENT_USER,
- (LPCTSTR)_rtd_PluginsPathInRegTable,
- NULL,
- (LPTSTR)_rtd_Class,
- REG_OPTION_NON_VOLATILE,
- KEY_ALL_ACCESS,
- NULL,
- &hKey,
- &dwDisp);
- return (result == ERROR_SUCCESS) ? hKey:NULL;
- }
- // 关闭指定关键字
- LONG _IRWERTF_CloseRegTab(HKEY hKey /*指定关键字*/)
- {
- ASSERT(hKey);
- return ::RegCloseKey(hKey);
- }
- // 获取插件个数值
- DWORD _IRWERTF_GetPluginNumber(HKEY hPlugKey /*插件总句柄*/)
- {
- ASSERT(hPlugKey);
- DWORD dwNumber = 0, dwSize = sizeof(DWORD);
- LONG result = ::RegQueryValueEx(hPlugKey,
- (LPCTSTR)_rtd_PlugInsNumberName,
- NULL,
- NULL,
- (LPBYTE)&dwNumber,
- &dwSize);
- return (result == ERROR_SUCCESS) ? dwNumber:0;
- }
- // 设置插件个数值
- DWORD _IRWERTF_SetPluginNumber(HKEY hPlugKey /*插件总句柄*/, DWORD dwNewNum /*插件个数值*/)
- {
- ASSERT(hPlugKey);
- ASSERT(dwNewNum);
- DWORD dwNumber = dwNewNum, dwSize = sizeof(DWORD);
- LONG result = ::RegSetValueEx(hPlugKey,
- (LPCTSTR)_rtd_PlugInsNumberName,
- 0,
- REG_DWORD,
- (CONST BYTE *)&dwNumber,
- dwSize);
- return (result == ERROR_SUCCESS) ? dwNumber:0;
- // 如果成功,返回值等于入口参数dwNewNum的值,否则
- // 为0。(dwNewNum的值不能是0)
- }
- // 获取插件的名称串
- LPTSTR _IRWERTF_GetPluginNames(HKEY hPlugKey /*插件总句柄*/)
- {
- ASSERT(hPlugKey);
- LPTSTR pNames;
- DWORD dwSize = 0;
- LONG result = ::RegQueryValueEx(hPlugKey,
- (LPCTSTR)_rtd_PlugInsNamesName,
- NULL,
- NULL,
- NULL,
- &dwSize);
- if ((result != ERROR_SUCCESS)||(dwSize == 0))
- return NULL;
- pNames = (LPTSTR)::GlobalAlloc(GPTR, dwSize);
- if (!pNames)
- return NULL;
- result = ::RegQueryValueEx(hPlugKey,
- (LPCTSTR)_rtd_PlugInsNamesName,
- NULL,
- NULL,
- (LPBYTE)pNames,
- &dwSize);
- if (result != ERROR_SUCCESS)
- {
- ::GlobalFree(pNames);
- return NULL;
- }
- return pNames;
- }
- // 设置插件的名称串
- LPCTSTR _IRWERTF_SetPluginNames(HKEY hPlugKey /*插件总句柄*/, LPCTSTR lpNewNames /*名称串*/)
- {
- ASSERT(hPlugKey);
- ASSERT(lpNewNames);
- ASSERT(::lstrlen(lpNewNames));
- LONG result = ::RegSetValueEx(hPlugKey,
- (LPCTSTR)_rtd_PlugInsNamesName,
- 0,
- REG_SZ,
- (CONST BYTE *)lpNewNames,
- ::lstrlen(lpNewNames)+1); // 包括尾部的NULL字节
- return (result == ERROR_SUCCESS) ? lpNewNames:NULL;
- // 如果成功,返回值等于入口参数lpNewNames的值,否则
- // 为NULL。(lpNewNames不能为空)
- }
- // 获取插件所在的路径
- LPTSTR _IRWERTF_GetPluginsPath(HKEY hPlugKey /*插件总句柄*/)
- {
- ASSERT(hPlugKey);
- LPTSTR pPath;
- DWORD dwSize = 0;
- LONG result = ::RegQueryValueEx(hPlugKey,
- (LPCTSTR)_rtd_PlugInsPathName,
- NULL,
- NULL,
- NULL,
- &dwSize);
- if ((result != ERROR_SUCCESS)||(dwSize == 0))
- return NULL;
- pPath = (LPTSTR)::GlobalAlloc(GPTR, dwSize);
- if (!pPath)
- return NULL;
- result = ::RegQueryValueEx(hPlugKey,
- (LPCTSTR)_rtd_PlugInsPathName,
- NULL,
- NULL,
- (LPBYTE)pPath,
- &dwSize);
- if (result != ERROR_SUCCESS)
- {
- ::GlobalFree(pPath);
- return NULL;
- }
- return pPath;
- }
- // 设置插件所在的路径
- LPCTSTR _IRWERTF_SetPluginsPath(HKEY hPlugKey /*插件总句柄*/, LPCTSTR lpNewPath /*路径串*/)
- {
- ASSERT(hPlugKey);
- ASSERT(lpNewPath);
- ASSERT(::lstrlen(lpNewPath));
- LONG result = ::RegSetValueEx(hPlugKey,
- (LPCTSTR)_rtd_PlugInsPathName,
- 0,
- REG_SZ,
- (CONST BYTE *)lpNewPath,
- ::lstrlen(lpNewPath)+1); // 包括尾部的NULL字节
- return (result == ERROR_SUCCESS) ? lpNewPath:NULL;
- // 如果成功,返回值等于入口参数lpNewPath的值,否则
- // 为NULL。(lpNewPath不能为空)
- }
- // 打开指定插件句柄
- HKEY _IRWERTF_OpenPlugins(HKEY hPlugKey /*插件总句柄*/, LPCTSTR PluginsName /*插件名子串*/)
- {
- ASSERT(hPlugKey);
- HKEY hKey = NULL;
- LONG result = ::RegOpenKeyEx(hPlugKey,
- PluginsName,
- 0,
- KEY_ALL_ACCESS,
- (PHKEY)&hKey);
- return (result == ERROR_SUCCESS) ? hKey:NULL;
- }
- // 创建指定插件句柄
- HKEY _IRWERTF_CreatePlugins(HKEY hPlugKey /*插件总句柄*/, LPCTSTR PluginsName /*插件名字串*/)
- {
- ASSERT(hPlugKey);
- HKEY hKey = NULL;
- DWORD dwDisp = 0;
- LONG result = ::RegCreateKeyEx(hPlugKey,
- PluginsName,
- NULL,
- (LPTSTR)_rtd_Class,
- REG_OPTION_NON_VOLATILE,
- KEY_ALL_ACCESS,
- NULL,
- &hKey,
- &dwDisp);
- return (result == ERROR_SUCCESS) ? hKey:NULL;
- }
- // 获取插件文件名
- LPTSTR _IRWERTF_GetPluginsFileName(HKEY hPlugKey /*指定插件句柄*/)
- {
- ASSERT(hPlugKey);
- LPTSTR pFileName;
- DWORD dwSize = 0;
- LONG result = ::RegQueryValueEx(hPlugKey,
- (LPCTSTR)_rtd_FileName,
- NULL,
- NULL,
- NULL,
- &dwSize);
- if ((result != ERROR_SUCCESS)||(dwSize == 0))
- return NULL;
- pFileName = (LPTSTR)::GlobalAlloc(GPTR, dwSize);
- if (!pFileName)
- return NULL;
- result = ::RegQueryValueEx(hPlugKey,
- (LPCTSTR)_rtd_FileName,
- NULL,
- NULL,
- (LPBYTE)pFileName,
- &dwSize);
- if (result != ERROR_SUCCESS)
- {
- ::GlobalFree(pFileName);
- return NULL;
- }
- return pFileName;
- }
- // 设置插件文件名
- LPCTSTR _IRWERTF_SetPluginsFileName(HKEY hPlugKey /*指定插件句柄*/, LPCTSTR lpNewFileName /*插件文件名*/)
- {
- ASSERT(hPlugKey);
- ASSERT(lpNewFileName);
- ASSERT(::lstrlen(lpNewFileName));
- LONG result = ::RegSetValueEx(hPlugKey,
- (LPCTSTR)_rtd_FileName,
- 0,
- REG_SZ,
- (CONST BYTE *)lpNewFileName,
- ::lstrlen(lpNewFileName)+1);// 包括尾部的NULL字节
- return (result == ERROR_SUCCESS) ? lpNewFileName:NULL;
- // 如果成功,返回值等于入口参数lpNewFileName的值,否则
- // 为NULL。(lpNewFileName不能为空)
- }
- // 获取插件优先级
- DWORD _IRWERTF_GetPluginPRI(HKEY hPlugKey /*指定插件句柄*/)
- {
- ASSERT(hPlugKey);
- DWORD dwPRI = 0, dwSize = sizeof(DWORD);
- LONG result = ::RegQueryValueEx(hPlugKey,
- (LPCTSTR)_rtd_PRI,
- NULL,
- NULL,
- (LPBYTE)&dwPRI,
- &dwSize);
- return (result == ERROR_SUCCESS) ? dwPRI:0; // 此时,优先级数就不能
- // 再是0了,否则将分不
- // 清是优先级数为0,还
- // 是函数执行失败。
- }
- // 设置插件优先级
- DWORD _IRWERTF_SetPluginPRI(HKEY hPlugKey /*指定插件句柄*/, DWORD dwNewPRI /*优先级数*/)
- {
- ASSERT(hPlugKey);
- DWORD dwPRI = dwNewPRI, dwSize = sizeof(DWORD);
- LONG result = ::RegSetValueEx(hPlugKey,
- (LPCTSTR)_rtd_PRI,
- 0,
- REG_DWORD,
- (CONST BYTE *)&dwPRI,
- dwSize);
- return (result == ERROR_SUCCESS) ? dwPRI:0;
- // 如果成功,返回值等于入口参数dwNewPRI的值,否则
- // 为0。(dwNewPRI的值不能是0)
- }
- LONG _IRWERTF_CloseKey(HKEY hKey)
- {
- return ::RegCloseKey(hKey);
- }