-
September 10th, 2013, 03:24 AM
#1
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;
}
-
September 10th, 2013, 04:05 AM
#2
Re: Release Version problem
Using MessageBox I found the retCode. It is 0xEA. What does it mean?
-
September 10th, 2013, 04:10 AM
#3
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
-
September 10th, 2013, 04:14 AM
#4
Re: Release Version problem
Originally Posted by shjdr7
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
-
September 10th, 2013, 04:20 AM
#5
Re: Release Version problem
Originally Posted by shjdr7
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
-
September 10th, 2013, 04:46 AM
#6
Re: Release Version problem
Thank you. The correct code was
ULONG nChars = sizeof(value);
Why it was working in debug version is surprising me.
-
September 10th, 2013, 04:54 AM
#7
Re: Release Version problem
Originally Posted by shjdr7
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
-
September 10th, 2013, 05:49 AM
#8
Re: Release Version problem
Originally Posted by shjdr7
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
-
September 10th, 2013, 05:53 AM
#9
Re: Release Version problem
Originally Posted by D_Drmmr
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
-
September 10th, 2013, 10:16 AM
#10
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|