Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Viewing Word documents from VFP
Message
From
21/06/2000 03:32:17
 
 
To
19/06/2000 15:24:13
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
00376075
Message ID:
00382567
Views:
71
Sam:

This is also a continuation of the previous message. Save evcerything below as GeRegistryProcs.prg

*--------------------------------------------------------------------------
*
* GenRegistryProcs
* ----------------
*
* This library contains all the functions necessary to read, write and
* create registry keys.
*
* Contents : CloseRegistryKey - Close a registry key.
* GetRegistryKey - Read a registry key value.
* OpenRegistryKey - Open a registry key.
*
* Notes : GenRegistryProcs first use was to fetch the 'path' entry
* for Microsoft Word. This information was use to launch
* Word with the RUN command (CREATEOBHJECT() didn't work
* correctly at runtime).
*
* I did not spend much time on these functions and it
* explains why their use is restriced to character key
* values.
*--------------------------------------------------------------------------
#INCLUDE constants.h

*==============================================================================
* OpenRegistryKey
* ---------------
*
* Purpose.......: Opens an existing Windows Registry key.
* Author........: Daniel Rouleau - Metro Information Services
* email: Daniel.Rouleau@MetroIs.com
* Last Revision.: 1998-09-18
*
* Syntax........: OpenRegistryKey( tcSubKey, tnMainKey )
* Returns.......: numeric
* Arguments.....: tcSubKey
* Specifies the subkey.
*
* tnMainKey
* Specifies the handle of the main key.
* Defaults to the value of the class MainKey property.
*
* Remarks.......: OpenRegistryKey returns the handle of the opened key or 0
* if an error is raised.
*==============================================================================
FUNCTION OpenRegistryKey
LPARAMETERS tcSubkey, tnMainKey

DECLARE INTEGER RegOpenKeyEx IN Win32API ;
INTEGER nKey, ;
STRING @cSubKey, ;
INTEGER nReserved, ;
INTEGER nAccessMask, ;
INTEGER @nKeyHandle


LOCAL lnRetVal && Value returned by this function.
LOCAL lnKeyHandle && KeyHandle parameter of RegOpenEx.
LOCAL lnReserved && Reserved parameter of RegOpenEx.

lnRetVal = 0
lnKeyHandle = 0
lnReserved = 0

lnRegError = RegOpenKeyEx( tnMainKey, ;
tcSubKey, ;
lnReserved, ;
REGKEY_READ, ;
@lnKeyHandle ;
)

IF lnRegError = REGERROR_SUCCESS
lnRetVal = lnKeyHandle
ELSE
lnRetVal = 0
ENDIF


RETURN ( lnRetVal )


*==============================================================================
* CloseRegistryKey
* ----------------
*
* Purpose.......: Closes a Windows Registry key.
* Author........: Daniel Rouleau - Metro Information Services
* email: Daniel.Rouleau@MetroIs.com
* Last Revision.: 1998-09-18
*
* Syntax........: CloseRegistryKey( tnKeyHandle )
* Returns.......: logical
* Arguments.....: tnKeyHandle
* Specifies the key handle to close.
*
* Remarks.......: CloseRegistryKey always returns True.
*==============================================================================
FUNCTION CloseRegistryKey
LPARAMETERS tnKeyHandle

DECLARE INTEGER RegCloseKey IN Win32API ;
INTEGER nKey

=RegCloseKey(tnKeyHandle)


RETURN ( .T. )


*==============================================================================
* GetRegistryKey
* --------------
*
* Purpose.......: Reads the value of a Windows Registry key.
* Author........: Daniel Rouleau - Metro Information Services
* email: Daniel.Rouleau@MetroIs.com
* Last Revision.: 1998-09-18
*
* Syntax........: GetRegistryKey( tcSubKey, ;
* tcValueName, ;
* [tuDefault], ;
* [tnMainKey] ;
* )
* Returns.......: variant
* Arguments.....: tcSubKey
* Specifies the registry SubKey.
*
* tcProperty
* Specifies the property to fetch.
*
* tuDefault
* Specifies the default value if the entry is not found.
* Defaults to an empty string.
*
* tnMainKey
* Specifies the handle of the main key.
* Defaults to the HKEY_LOCAL_MACHINE
*
* Remarks.......: GetRegistryKey returns the registry key value or the
* specified default value if an error is raised.
*==============================================================================
FUNCTION GetRegistryKey
LPARAMETERS tcSubKey, tcValueName, tuDefault, tnMainKey

DECLARE INTEGER RegQueryValueEx IN Win32API ;
INTEGER nKey, ;
STRING cValueName, ;
INTEGER nReserved, ;
INTEGER @nType, ;
STRING @cBuffer, ;
INTEGER @nBufferSize

LOCAL luRetVal && Value returned by this method
LOCAL lcBuffer && Buffer parameter of RegQueryValueEx.
LOCAL lnBufferSize && BufferSize parameter of RegQueryValueEx.
LOCAL luDefault && Value to use if the entry was not found.
LOCAL lnKeyHandle && Handle of the registry key to read.
LOCAL lnMainKey && Handle of the registry main key.
LOCAL lnRegError && Value returmed by RegQueryValueEx.
LOCAL lnReserved && Reserved parameter of RegQueryValueEx.
LOCAL lnType && Type parameter of RegQueryValueEx.

lcBuffer = SPACE(256)
lnBufferSize = LEN(lcBuffer)
luDefault = IIF(PCOUNT() >= 3, tuDefault, .NULL.)
lnMainKey = IIF((PCOUNT() < 4) OR (TYPE("tnMainKey") <> "N"), HKEY_LOCALMACHINE, tnMainKey)
lnReserved = 0
luRetVal = luDefault
lnType = 0

lnKeyHandle = OpenRegistryKey(tcSubKey, .F., lnMainKey)
IF m.lnKeyHandle <> 0
lnRegError = RegQueryValueEx( lnKeyHandle, ;
tcValueName, ;
lnReserved, ;
@lnType, ;
@lcBuffer, ;
@lnBufferSize ;
)
=CloseRegistryKey(lnKeyHandle)
IF lnRegError = REGERROR_SUCCESS
luRetVal = LTRIM(STRTRAN(LEFT(lcBuffer, lnBufferSize), CHR(0), ""))
ENDIF
ENDIF


RETURN ( luRetVal )
Previous
Reply
Map
View

Click here to load this message in the networking platform