RegSetValueEx Error (Buffer)

I want to append (or write) a value
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
...(open)
...(query)

	if (wcslen(pszRegData) != 0)
	{
		const _TCHAR pszDelimiter[] = L",";
		dwLen+=(DWORD)wcslen(pszDelimiter)+1;

		if (wcscat_s(pszRegData, dwLen, pszDelimiter) != 0)
		{
			LOGERR(_T("wcscat_s failed, error ") << GetLastError());
			return ERROR_INSTALL_FAILURE;
		}

		dwLen+=(DWORD)wcslen(pszSearch);
	}
	else
	{
		dwLen+=(DWORD)wcslen(pszSearch)+1;
	}

	if (wcscat_s(pszRegData, dwLen, pszSearch) != 0)
	{
		LOGERR(_T("wcscat_s failed, error ") << GetLastError());
		return ERROR_INSTALL_FAILURE;
	}

	if (ERROR_SUCCESS != ::RegSetValueEx(hKey, pszValueName, 0L, REG_SZ, (LPBYTE)pszRegData, (wcslen(pszRegData)+1)*sizeof(TCHAR)))
	{
		RegCloseKey(hKey);


BEX application crash on RegSet...

I guess it's something about the trailing nulls from the wscat_s... Can pls somebody write working code
Last edited on
You haven't posted enough. I have no idea what value you're passing to RegSetValueEx.

The one obviously wrong thing is you're writing the null terminator into the registry.
I'm at msdn right now looking at this function and it says the third entry to RegSetValueEx MUST BE ZERO but you have it as 0L which isn't the same thing. To build on what kbw said passing a null terminator into the registry isn't needed unless the specific data type you are working with is NOT null terminated; which few of them aren't. I also think you're going to run into problems when passing that last argument, you do realize that there is a preset limit on the length of a registry entry in Windows right?

EDIT: Also what are the double colon "::" before you call the RegSetValueEx on line 28 for? That looks like something more in place in VB, are you sure you didn't copy that from the wrong source? I hate the new layout for MSDN to but you can set it up to only display in your desired language with just a few minutes of effort.
Last edited on
0L was OK.

When I had read the existing value from the registry key, I made the Buffer the size of it. That was the fault, the buffer was too small for adding stuff and RegSetValueEx made strange behaviour then
Topic archived. No new replies allowed.