📄 vmenvironment.h
字号:
#ifndef VM_OP_SYS_ENVIRONMENT_H_INCLUDED
#define VM_OP_SYS_ENVIRONMENT_H_INCLUDED
/*****************************************************************************/
/* HEADER FILE */
/*****************************************************************************/
/*
$Archive: $
$Revision: $
$Date: $
$Author: $
Description: Declaration of a class that knows how to interface to the NT
process environment
TOOL And XML FORMS License
==========================
Except where otherwise noted, all of the documentation
and software included in the TOOL package is
copyrighted by Michael Swartzendruber.
Copyright (C) 2005 Michael John Swartzendruber.
All rights reserved.
Access to this code, whether intentional or accidental,
does NOT IMPLY any transfer of rights.
This software is provided "as-is," without any express
or implied warranty. In no event shall the author be held
liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for
any purpose, including commercial applications, and to
alter and redistribute it, provided that the following
conditions are met:
1. All redistributions of source code files must retain
all copyright notices that are currently in place,
and this list of conditions without modification.
2. The origin of this software must not be misrepresented;
you must not claim that you wrote the original software.
3. If you use this software in another product, an acknowledgment
in the product documentation would be appreciated but is
not required.
4. Modified versions in source or binary form must be plainly
marked as such, and must not be misrepresented as being
the original software.
*/
/*****************************************************************************/
#include <map>
#include <functional>
#include "VMString.h"
// derived class for handling environment stuff
//
class VMEnvironmentRegistry
{
public:
VMEnvironmentRegistry( void );
virtual ~VMEnvironmentRegistry( void );
int AddEnvironmentVariable( char* pchName, char* pchValue );
int RemoveEnvironmentVariable( char* pchName );
protected:
bool Connect( HKEY hKeyToOpen, const char* pchSystemName = NULL );
bool Open( const char* pchKeyName, DWORD dwAccessMask );
private:
bool DeleteValue( char* pchDelete );
bool QueryInfo( void );
private:
HKEY m_hRegistryHandle;
HKEY m_hKeyHandle;
DWORD m_dwErrorCode;
VMString m_oComputerName;
VMString m_oRegistryName;
VMString m_oClassName;
VMString m_oKeyName;
VMString m_oErrorText;
// Data items filled in by QueryInfo
//
DWORD m_dwNumberOfSubkeys;
DWORD m_dwNumberOfValues;
DWORD m_dwLongestSubkeyNameLength;
DWORD m_dwLongestClassNameLength;
DWORD m_dwLongestValueNameLength;
DWORD m_dwLongestValueDataLength;
DWORD m_dwSecurityDescriptorLength;
FILETIME m_xLastWriteTime;
};
struct VMEnvMapLess
{
bool operator()( VMString roLHS, VMString roRHS ) const
{
const char* pchLHS = (const char*) roLHS;
const char* pchRHS = (const char*) roRHS;
return( strcmp( pchLHS, pchRHS ) < 0 );
}
};
typedef std::map< VMString, VMString, VMEnvMapLess > VM_ENV_VAR_MAP;
typedef VM_ENV_VAR_MAP::iterator VM_ENV_VAR_ITER;
class VMEnvironmentVariables : public VMEnvironmentRegistry
{
public:
VMEnvironmentVariables();
virtual ~VMEnvironmentVariables();
int SetValue( char* pchVariable, char* pchValue, bool bRegWrite = false, bool bReload = false );
int GetValueDirect( char* pchVariable, VMString& roValue );
int Initialize( void )
{ return ( ReloadEnvironment() ); };
int ReloadEnvironment( void );
bool GetValueByName( VMString& roKey, VMString& roOutput );
int RemoveKey( char* pchVariable, bool bRegWrite = false );
const VMString& GetErrorText( void ) { return m_oErrorText; };
private:
int LoadEnvironment( void );
VMString m_oErrorText;
int m_iSize;
bool m_bLoaded;
VM_ENV_VAR_MAP m_oStringMap;
VM_ENV_VAR_ITER m_oMapIter;
};
#endif
/*****************************************************************************/
/* Check-in history */
/*
*$Log: $
*/
/*****************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -