This MSDN article should demonstrate how to remove a registry key that has subkeys, but the code has flaws.
The line that says
StringCchCopy (lpEnd, MAX_PATH*2, szName);
throws an exception that is associated with an attempt to copy outside the lpEnd buffer. I tried to fix the solution by replacing this line with the following
size_t subKeyLen = lstrlen(lpSubKey);
size_t bufLen = subKeyLen + lstrlen(szName)+1;
LPTSTR buf = new WCHAR[bufLen];
StringCchCopy(buf,bufLen,lpSubKey);
StringCchCopy(buf+subKeyLen,lstrlen(szName)+1,szName);
buf[bufLen-1]='\0';
I cannot go through the code because the target platform and the dev platform are different, but from the log I entered into the code, it looks like it just hangs, but does not throw an exception.
It is frustrating that MSDN articles are wrong ... you think they will be checked.
Any ideas on how to fix this?
Thank.
source
share