CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jun 2000
    Posts
    62

    Reading from the Registry in Win2K

    Hi

    I'm Using the Registry Example from http://www.allapi.net/api/api241.php
    It Works Great in Win98 But the Line that is Used to Remove the Unnecessary chr$(0)'s:

    RegQueryStringValue = Left$(strBuf, InStr(1, strBuf, Chr$(0)) - 1)



    Doesn't Work in Win2K and Because I Don't Have Win2K Installed on My PC I Can't Fix it.

    Does Anyone Have a Working Code for Win2K?

    Thanks in Advance,

    Danni.


  2. #2
    Join Date
    Jun 2000
    Posts
    62

    Re: Reading from the Registry in Win2K

    Can the Following Line Work ?

    RegQueryStringValue = Left(strBuf, lDataBufSize - 1)



    Does strBuf Always Have Only One Extra Char ?

    Danni.


  3. #3
    Join Date
    Jan 2000
    Location
    MO, USA
    Posts
    1,506

    Re: Reading from the Registry in Win2K

    i think all strings that are returned from API calls are null terminated (like in C). so i always just get rid of the last character and then trim the result to get a clean string result.

    hope this helps,

    john

    John Pirkey
    MCSD
    http://www.ShallowWaterSystems.com
    http://www.stlvbug.org
    John Pirkey
    MCSD (VB6)
    http://www.stlvbug.org

  4. #4
    Join Date
    Jun 2000
    Posts
    62

    Re: Reading from the Registry in Win2K

    The Problem is How to Get Rid of the Last Character in Win2K without Getting Runtime Errors.

    Danni.


  5. #5
    Join Date
    Jan 2000
    Location
    MO, USA
    Posts
    1,506

    Re: Reading from the Registry in Win2K

    The null character will always be the last character - so just hack off the last character:


    strBuff = Trim(Left(strBuff, len(strBuff) - 1))




    john

    John Pirkey
    MCSD
    http://www.ShallowWaterSystems.com
    http://www.stlvbug.org
    John Pirkey
    MCSD (VB6)
    http://www.stlvbug.org

  6. #6
    Join Date
    Jun 2000
    Posts
    62

    Re: Reading from the Registry in Win2K

    This is the Only Code that Works for Me (On Win2K):


    '
    '
    '

    If lResult = 0 then
    RegQueryStringValue = StripTerminator(strBuf)
    End If

    '
    '
    '

    Function StripTerminator(byval strBuf as string) as string
    Dim NullPos as Long
    NullPos = InStr(1, strBuf, vbNullChar)
    If NullPos > 0 then _
    StripTerminator = Left$(strBuf, NullPos - 1) else _
    StripTerminator = strBuf
    End Function




    Thanks for Your Answer!

    Danni.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured