Link to home
Start Free TrialLog in
Avatar of philw
philw

asked on

Accessing NT4.0 Registry

I am having problems reading values from the NT4.0 registry.  I can write to the reg OK but then cannot read my values, or values already there, in any way.

I am using a win32 api called 'regopenkey' to get the values and this seems to work fine on win95.
Avatar of bwoods
bwoods

It depends on what type of values you are reading/writing and what procedures you are using to do so.  There is no way I can tell you what you are doing wrong without seeing the actual code.
If you would, post back with your code...
Just cut it down to the actual API calls you are using to write and read the data.  There are some issues with NT registry over 95 in practice, but as long as you are careful, the NT registry is just as accessible as 95's.  
Avatar of philw

ASKER

Here is the code for the whole function.

Public Function GetOrderPrefix95()

    Dim lReturn As Long
    Dim hwndSettings As Long
    Dim lpName As String
    Dim lpcbName As Long
    Dim lpClass As String
    Dim lpcbClass As Long
    Dim lpData As String
    Dim lpcbData As Long
   
    lpcbName = 255
    lpName = Space$(lpcbName)
    lpcbClass = 255
    lpClass = Space$(lpcbClass)
   
    lReturn = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\QPOS\Settings", 0&, KEY_ALL_ACCESS, hwndSettings)
   
    lpcbName = 255
    lpName = Space$(lpcbName)
    lpcbData = 255
    lpData = Space$(lpcbData)
   
    lReturn = RegQueryValueEx(hwndSettings, "Order Prefix", 0&, REG_SZ, lpData, lpcbData)
   
    If lReturn <> ERROR_SUCCESS Then
        gAPIDisplayError lReturn, "GetOrderPrefix95"
    Else
        GetOrderPrefix95 = Left$(lpData, lpcbData - 1)
    End If
   
    lReturn = RegCloseKey(hwndSettings)
   
End Function



philw,

Are you sure that the code that you are using to write the registry data is putting it where you are expecting it to go?

Could you also post the code that you are using to write the data?

zsi
Avatar of philw

ASKER

I cannot read any data from the registry not just data I have writen.

There is an excellent code sample in the April issue of VBPJ that makes reading from and writing to the registry a breeze.  If you would like this sample, you can either download it from their web page, or I could send it to you.
Avatar of philw

ASKER

I would be greatfull if you would send it to me as a cannot find it vbpj's site
philw,
  Please send me your email address so that I may mail you the zip file.
Avatar of philw

ASKER

My E-Mail address is philw@gordian-pc.co.uk
Philw,
  Sorry it took me so long to get back, but it looks like they've
got you taken care of in the interim.  One suggestion... If you can't read anything at all out of the registry, then it's probable that your error is early on - most likely when you first try to open the key.  Check the return value of every registry operation.  This has two purposes, the first being that you will know exactly where your calls go bad, and the second being that you want to be extremely careful with your customers' registry's.  If you don't make sure that each and every registry call is successful, you could think you are writing to one key, when in fact you are writing to another, totally destroying their registry.  It's not the best way to get repeat business!
Good luck.  Let us know if you just can't get it...
ASKER CERTIFIED SOLUTION
Avatar of MikeABB
MikeABB

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial