CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2006
    Location
    Timisoara, Romania
    Posts
    433

    [RESOLVED] RegQueryValueEx problem

    hi!

    I experience a problem with RegQueryValueEx in Release version (in Debug version there is no problem).
    What I am trying to do is to get the path of APPDATA folder of Windows (USER->Volatile Environment->APPDATA).

    the code I wrote is this:
    Code:
    DWORD dwType;
    DWORD dwSize;
    WCHAR wstr[MAX_PATH];
    nResult = RegQueryValueEx(hKey, L"APPDATA", 0, &dwType, (byte*)wstr, &dwSize);
    if (nResult == ERROR_MORE_DATA)
    {
    	wsprintf(wstr, L"dwSize:%d maxpath:%d", dwSize, MAX_PATH);
    	MessageBox(0, wstr, L"more data", 0);
    }
    
    if (ERROR_SUCCESS != nResult)
    {
    	DisplayError(nResult);
    	return;
    }
    As you may guess, the problem is that it goes in ERROR_MORE_DATA section.

    The messagebox displays "dwSize:64 maxpath:260" - so what's the problem?
    and... I receive no string in wstr

    can anybody give me an advice, please?

  2. #2
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: RegQueryValueEx problem

    can anybody give me an advice, please?
    The one is: read documentation, always start with this.

    lpcbData [in, out, optional]

    A pointer to a variable that specifies the size of the buffer pointed to by the lpData parameter, in bytes. When the function returns, this variable contains the size of the data copied to lpData.
    Best regards,
    Igor

  3. #3
    Join Date
    Aug 2006
    Location
    Timisoara, Romania
    Posts
    433

    Re: RegQueryValueEx problem

    wow, that's awesome!
    I have read from there for many times but I still could have not gotten the idea
    Now I understand what the documentation said, thanks.

  4. #4
    Join Date
    Jul 2009
    Posts
    6

    Re: [RESOLVED] RegQueryValueEx problem

    Feoggou , u may try with BYTE array ,after that ,u can check ,because u cannot convert WCHAR to BYTE* ,there may size differ...

  5. #5
    Join Date
    Aug 2006
    Location
    Timisoara, Romania
    Posts
    433

    Re: [RESOLVED] RegQueryValueEx problem

    Quote Originally Posted by rajakumarrs
    Feoggou , u may try with BYTE array ,after that ,u can check ,because u cannot convert WCHAR to BYTE* ,there may size differ...
    I experienced no problem with that.

    I used
    Code:
    DWORD dwSize = MAX_PATH * 2;
    WCHAR wstr[MAX_PATH];
    nResult = RegQueryValueEx(hKey, L"APPDATA", 0, &dwType, (byte*)wstr, &dwSize);
    and it works.
    a WCHAR has 2 bytes, so it should be ok to convert from WCHAR* to byte* (and it seems that it is).

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