Here is the API code to read the Windows Registry. You will want to do this is you use 3rd party OCX or DLL files, or if you create your own DLLs using VFP.
By default, a VFP DLL is registered on the computer when it is created on. However, if you need to distribute the application it must be registered on the other computers. One way to handle this is by reading the registry, and register it using REGSRV32 if it does not exist.
Example of registering an OCX or DLL
RUN /n regsvr32 myDLL.DLL /S
Code to read the registry. In this example I am checking for the ôProduct IDö of Visual Foxpro 7.0. You can change the version in the program and try it for other version.
* To test this code: copy from here on down and paste into a program. Run it.
*-- Registry Read by Jim Osieczonek û www.deltabg.com
LOCAL lcVersion
lcVersion = "7.0"
PUBLIC goApp
goApp = CREATEOBJECT('capp')
MESSAGEBOX(goApp.ReadReg('HLM','Software\Microsoft\VisualFoxpro\' + lcVersion +;
'\Registration','ProductID'))
**************************************************
*
DEFINE CLASS capp AS container
*-- Reads the windows Registry.
PROCEDURE readreg
* Start of Code
LPARAMETERS tcKey,tcSubKey,tcValue
IF PCOUNT() = 2
tcValue = ""
ENDIF
* here is where we will actually read the registry
cValueRead = THIS.ReadREG_SZ(nKey, cSubKey, cValue)
IF (EMPTY(cValueRead)) THEN
cValueRead = "REGISTRY KEY NOT FOUND"
* MESSAGEBOX("Function Not Successful.") && testing only
ELSE
* MESSAGEBOX("Function Successful. " + cValueRead) && testing only
ENDIF
RETURN cValueRead
ENDPROC
*-- API's used by the ReadReg method.
PROCEDURE readreg_sz
* This function reads a REG_SZ value from the registry. If successful,
* it will return the value read. If not successful, it will return an empty string.
PARAMETERS nKey, cSubKey, cValue
* nKey The root key to open. It can be any of the constants defined below.
* #DEFINE HKEY_CLASSES_ROOT -2147483648
* #DEFINE HKEY_CURRENT_USER -2147483647
* #DEFINE HKEY_LOCAL_MACHINE -2147483646
* #DEFINE HKEY_USERS -2147483645
* cSubKey The SubKey to open.
* cValue The value that is going to be read.
* Constants that are needed for Registry functions
#DEFINE REG_SZ 1
* WIN 32 API functions that are used
DECLARE Integer RegOpenKey IN Win32API ;
Integer nHKey, String @cSubKey, Integer @nResult
DECLARE Integer RegQueryValueEx IN Win32API ;
Integer nHKey, String lpszValueName, Integer dwReserved,;
Integer @lpdwType, String @lpbData, Integer @lpcbData
DECLARE Integer RegCloseKey IN Win32API Integer nHKey
* Local variables used
LOCAL nErrCode && Error Code returned from Registry functions
LOCAL nKeyHandle && Handle to Key that is opened in the Registry
LOCAL lpdwValueType && Type of Value that we are looking for
LOCAL lpbValue && The data stored in the value
LOCAL lpcbValueSize && Size of the variable
LOCAL lpdwReserved && Reserved Must be 0
nErrCode = RegOpenKey(nKey, cSubKey, @nKeyHandle)
* If the error code isn't 0, then the key doesn't exist or can't be opened.
IF (nErrCode # 0) THEN
RETURN ""
ENDIF
lpcbValueSize = 1
* Get the size of the data in the value
nErrCode=RegQueryValueEx(nKeyHandle, cValue, lpdwReserved, @lpdwValueType, @lpbValue, @lpcbValueSize)
* Make the buffer big enough
lpbValue = SPACE(lpcbValueSize)
nErrCode=RegQueryValueEx(nKeyHandle, cValue, lpdwReserved, @lpdwValueType, @lpbValue, @lpcbValueSize)
=RegCloseKey(nKeyHandle)
IF (nErrCode # 0) THEN
RETURN ""
ENDIF
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.