CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Aug 2013
    Posts
    52

    Unhappy Release Version problem

    I wrote a program with configuration being written in the registry.
    My debug version is working fine. But release version is not reading from the registry for some items.
    So I enabled debugging in the release version. But in the release version when I press F10 it is skipping
    some lines! My code for reading from registry follows.

    Please help. I almost finished my code.

    template<typename T>
    void CEMapTasksT<T>::ReadValue(CRegKey& keyReg,LPCTSTR name,LPCTSTR strDef,CComBSTR& bsValue)
    {
    TCHAR value[VALUE_MAX_LEN] = {0};//When I press F10 here
    ULONG nChars;

    LONG retCode = keyReg.QueryStringValue(name,value,&nChars);
    if(retCode != ERROR_SUCCESS)
    {
    lstrcpy(value,strDef);//code jumps to here
    retCode = keyReg.SetStringValue(name,value);
    }
    if(retCode == ERROR_SUCCESS)
    bsValue = value;
    }

  2. #2
    Join Date
    Aug 2013
    Posts
    52

    Re: Release Version problem

    Using MessageBox I found the retCode. It is 0xEA. What does it mean?

  3. #3
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: Release Version problem

    1. Please, use Code tags!
    2. What is VALUE_MAX_LEN? What is its value?
    3. Read the documentation about CRegKey::QueryStringValue:
    Parameters
    pszValueName
    Pointer to a null-terminated string containing the name of the value to query.
    pszValue
    Pointer to a buffer that receives the string data.
    pnChars
    The size, in TCHARs, of the buffer pointed to by pszValue. When the method returns, pnChars contains the size, in TCHARs, of the string retrieved, including a terminating null character.
    Victor Nijegorodov

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: Release Version problem

    Quote Originally Posted by shjdr7 View Post
    Using MessageBox I found the retCode. It is 0xEA. What does it mean?
    From MSDN:
    Return Value
    If the method succeeds, ERROR_SUCCESS is returned. If the method fails to read a value, it returns a nonzero error code defined in WINERROR.H. If the data referenced is not of type REG_SZ, ERROR_INVALID_DATA is returned. If the method returns ERROR_MORE_DATA, pnChars equals zero, not the required buffer size in bytes.
    Victor Nijegorodov

  5. #5
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Release Version problem

    Quote Originally Posted by shjdr7 View Post
    So I enabled debugging in the release version. But in the release version when I press F10 it is skipping
    some lines!
    That is because you have optimizations turned on. Turn off the optimizations in release mode and rebuild your application if you want to debug a release build and have the source code match the actual instructions that are executed.

    Regards,

    Paul McKenzie

  6. #6
    Join Date
    Aug 2013
    Posts
    52

    Re: Release Version problem

    Thank you. The correct code was
    ULONG nChars = sizeof(value);
    Why it was working in debug version is surprising me.

  7. #7
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: Release Version problem

    Quote Originally Posted by shjdr7 View Post
    Thank you. The correct code was
    ULONG nChars = sizeof(value);
    No, it is wrong!
    Why don't you read the documentation?
    Again, from MSDN:
    pnChars
    The size, in TCHARs, of the buffer pointed to by pszValue. When the method returns, pnChars contains the size, in TCHARs, of the string retrieved, including a terminating null character.
    But sizeof returns the size in bytes!
    So the correct code would be
    Code:
    ULONG nChars = sizeof(value) / sizeof(value[0]);
    or just
    Code:
    ULONG nChars = VALUE_MAX_LEN;
    Victor Nijegorodov

  8. #8
    Join Date
    Jul 2005
    Location
    Netherlands
    Posts
    2,042

    Re: Release Version problem

    Quote Originally Posted by shjdr7 View Post
    Thank you. The correct code was
    ULONG nChars = sizeof(value);
    Why it was working in debug version is surprising me.
    You were passing a pointer to an uninitialized variable. In a debug build, the variable's value is initialized to 0, but in a release build the variable really remains uninitialized. It's value will be whatever happened to be last written to that particular piece of memory.
    Cheers, D Drmmr

    Please put [code][/code] tags around your code to preserve indentation and make it more readable.

    As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky

  9. #9
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: Release Version problem

    Quote Originally Posted by D_Drmmr View Post
    You were passing a pointer to an uninitialized variable. In a debug build, the variable's value is initialized to 0,
    Isn't it initialized to something like 0xcdcdcdcd ?
    Victor Nijegorodov

  10. #10
    Join Date
    Aug 2013
    Posts
    52

    Re: Release Version problem

    I agreed. My code was wrong again.The correct code was
    ULONG nChars = VALUE_MAX_LEN;
    Thank u, again

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