Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Reading a Registry Key Problem...
Message
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Title:
Reading a Registry Key Problem...
Miscellaneous
Thread ID:
00234601
Message ID:
00234601
Views:
54
The following is a partial export of a registry key:

[HKEY_LOCAL_MACHINE\Software\OLEforRetail\ServiceOPOS\POSPrinter\TM-T88IIP]
@="SOEPSON1.POSPrinter"
"DeviceName"="TM-T88II"

I am using Rick Strahl's registry class which works great. The problem I am having is this particular key has (Default) as the first value [denoted in the registry file as the at symbol]. Please note, I have no control over what this ActiveX control rights to the registry, I just have to deal with it.

Reading this key returns an empty value which, in this case, falsely signals the end of reading all the other keys that follow, like DeviceName in this example. IOW, nothing is returned. As a kludge, I modified Rick's code as follows [near the end]:
PROTECTED FUNCTION EnumValue
LPARAMETERS tnHKey, tcSubKey, tnIndex, tnType
LOCAL lcSubKey, lcReturn, lnResult, lcDataBuffer

* tnHKey is the HKEY_LOCAL_MACHINE constant
* tcSubKey is Software\OLEforRetail\.....
* tnIndex in this case is 0
* tnType is also 0

tnType=IIF(type("tnType")="N",tnType,0)

lnRegHandle=0

*** Open the registry key
lnResult=RegOpenKey(tnHKey,tcSubKey,@lnRegHandle)
IF lnResult#ERROR_SUCCESS
   *** Not Found
   RETURN .NULL.
ENDIF   

*** Need to define here specifically for Return Type
*** for lpdData parameter or VFP will choke.
*** Here it's STRING.
DECLARE INTEGER RegEnumValue ;
        IN Win32API ;
        INTEGER nHKey,;
        INTEGER nIndex,;
        STRING @lpszValueName,;
        INTEGER @lpdwSize,;
        INTEGER dwReserved,;
        INTEGER @lpdwType,;
        STRING @lpbData,;
        INTEGER @lpcbData

tcSubkey=SPACE(MAX_INI_BUFFERSIZE)
tcValue=SPACE(MAX_INI_BUFFERSIZE)
lnSize=MAX_INI_BUFFERSIZE
lnValSize=MAX_INI_BUFFERSIZE

lnReturn=RegEnumValue(lnRegHandle, tnIndex, @tcSubkey,@lnValSize, 0, @tnType, @tcValue, @lnSize)

=RegCloseKey(lnRegHandle)

IF lnResult#ERROR_SUCCESS 
   *** Not Found
   RETURN .NULL.
ENDIF

<b>* the next four lines are the workaround</b>

tcValue  = Alltrim(ChrTran(tcValue , Chr(0), ""))
tcSubKey = Alltrim(ChrTran(tcSubKey, Chr(0), ""))
if !empty(tcValue) and empty(tcSubKey)
   tcSubKey = "(Default)"
endif

RETURN tcSubKey
ENDFUNC
The value of tcValue is the actual value in the reg export snippet, SOEPSON1.POSPrinter, but the tcSubKey is blank. Anyone know of a better way? TIA.
Mark McCasland
Midlothian, TX USA
Reply
Map
View

Click here to load this message in the networking platform