過程中被損壞,我有以下的代碼,它從一個函數得到一個返回值char*
的char *值被分配
cDestDrive = ReadFromRegistry(HKEY_CURRENT_USER,NDSPATH,szDestPathRoot);
我能夠讀取裏面cDestDrive
可貴,我分配給它的時間。我分配給它的那一刻:
CString strServerAddress = cDestDrive;
cDestDrive的價值得到改變(損壞),我不能夠獲得價值CString strServerAddres
爲什麼發生這種情況的任何想法。
編輯: 代碼以從註冊表
char* CNDSShellExtender::ReadFromRegistry(HKEY hKey,LPCTSTR lpNDS,LPSTR lpRegKey)
{
HKEY hRegKey=NULL;
if(hKey==NULL || lpNDS==""||lpNDS==NULL||lpRegKey==""||lpRegKey==NULL)
MessageBox(NULL,"Reading from Registry Failed!Invalid Path",
_T("Network Drive Solution"),
MB_ICONERROR);
LONG lOpenRes=RegOpenKey(hKey,lpNDS,&hRegKey);
if (lOpenRes!=ERROR_SUCCESS ||lpNDS==NULL)
MessageBox (NULL, "Can not Find Any Server to Connect",
_T("NDSShellExtension"),
MB_ICONERROR);
if(lOpenRes==ERROR_SUCCESS && lpNDS!=NULL)
{
TCHAR tSZValue[MAX_PATH] = {0};
DWORD dwBufSize=MAX_PATH;
LONG lCloseOut;
LPBYTE lpStorage = reinterpret_cast<LPBYTE>(tSZValue);
char* cpRegKeyVal=tSZValue;
if (ERROR_SUCCESS == RegQueryValueEx(hRegKey,lpRegKey , 0, 0, (BYTE*)tSZValue, &dwBufSize))
{
lCloseOut= RegCloseKey(hRegKey);
if (lCloseOut != ERROR_SUCCESS)
MessageBox (NULL, "Registry Not Closed",
_T("NDSShellExtension"),
MB_ICONERROR);
return cpRegKeyVal;
}
else
{
lCloseOut= RegCloseKey(hRegKey);
if (lCloseOut != ERROR_SUCCESS)
MessageBox (NULL, "Registry Not Closed",
_T("NDSShellExtension"),
MB_ICONERROR);
return "";
}
}
return "";
}
ReadFromRegistry的代碼是什麼? – 2010-10-27 14:28:54
這應該起作用,所以它在別的地方 - 請顯示實際的代碼塊。 – egrunin 2010-10-27 14:29:52
@egrunin @Dark Falcon更新了有問題的代碼 – Simsons 2010-10-27 14:30:57