|
-
February 26th, 2010, 01:41 PM
#1
A question regarding RegSetValueEx
Here is the definition of RegSetValueEx,
LONG WINAPI RegSetValueEx(
__in HKEY hKey,
__in_opt LPCTSTR lpValueName,
__reserved DWORD Reserved,
__in DWORD dwType,
__in_opt const BYTE *lpData,
__in DWORD cbData
);
According to MSDN, If the data is of type REG_SZ, REG_EXPAND_SZ, or REG_MULTI_SZ, cbData must include the size of the terminating null character or characters. But I tried to specify the cbData without considering terminating null character, it still works. It means, for example, if lpData points to _T("dullboy"), I specify cbData as 14, it still works as I specify cbData as 16. Would anybody here explain why? Thanks for your inputs.
-
February 26th, 2010, 01:48 PM
#2
Re: A question regarding RegSetValueEx
Maybe you got lucky and the memory after the end of the char buffer was zero'd?
Maybe the api checks for a terminating null at length - 1 and writes one out if it doesn't find one (or appends two nulls for multi-sz).
-
February 27th, 2010, 11:53 AM
#3
Re: A question regarding RegSetValueEx
A function detects the end of a string either by using the null terminator or by using a parameter for the lenght of the string. It only uses one of the two methods. So, if there is a parameter for the string lenght, the null terminator is ignored. Present or absent, it doesn't matter, the function will only take the declared lenght, regardless of whats's after that.
-
February 27th, 2010, 03:14 PM
#4
Re: A question regarding RegSetValueEx
Are you sure your application is using Unicode? If not, then either 14 or 16 is more than enough.
Be sure to rate those who help!
-------------------------------------------------------------
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
-
February 28th, 2010, 10:04 PM
#5
Re: A question regarding RegSetValueEx
 Originally Posted by dullboy
Here is the definition of RegSetValueEx,
LONG WINAPI RegSetValueEx(
__in HKEY hKey,
__in_opt LPCTSTR lpValueName,
__reserved DWORD Reserved,
__in DWORD dwType,
__in_opt const BYTE *lpData,
__in DWORD cbData
);
According to MSDN, If the data is of type REG_SZ, REG_EXPAND_SZ, or REG_MULTI_SZ, cbData must include the size of the terminating null character or characters. But I tried to specify the cbData without considering terminating null character, it still works. It means, for example, if lpData points to _T("dullboy"), I specify cbData as 14, it still works as I specify cbData as 16. Would anybody here explain why? Thanks for your inputs.
Windows registry strings are natively stored as UTF-16.
If your project is compiled as Unicode, then I would definitely follow the guidelines.
This is what I do:
DWORD cbData = (_tcslen(str)+1) * sizeof(TCHAR);
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
|