je le code suivant, qui obtient une valeur de retour d'une fonction char*
char * valeur est corrompu lors de l'affectation
cDestDrive = ReadFromRegistry(HKEY_CURRENT_USER,NDSPATH,szDestPathRoot);
Je suis capable de lire la valeur à l'intérieur cDestDrive
jusqu'au moment où je lui attribuer. Le moment où je suis lui attribuer:
CString strServerAddress = cDestDrive;
se change la valeur de cDestDrive (corrompu) et je ne suis pas en mesure d'obtenir la valeur CString strServerAddres
toute idée pourquoi cela se produit.
Edit: code pour lire à partir du Registre
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 "";
}
Quel est le code de ReadFromRegistry? –
Cela devrait fonctionner, donc c'est ailleurs - s'il vous plaît montrer le bloc de code réel. – egrunin
@egrunin @Dark Falcon Mise à jour du code en question – Simsons