Снимок экрана Regedit http://i54.tinypic.com/3503vi8.jpg
Теперь этот код:
HKEY hKey;
LONG regOpenCriss = RegOpenKeyEx(HKEY_CURRENT_USER, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\\", 0, KEY_QUERY_VALUE, &hKey);
char mydata[2000] = {'\0'};
DWORD dwType = REG_SZ;
DWORD dataLength = sizeof(mydata);
LPVOID messagecaliss;
GetLastError();
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, GetLastError(), NULL,(LPTSTR) &messagecaliss, 0, NULL );
if (regOpenCriss == ERROR_SUCCESS) {
RegQueryValueEx(hKey, "Test2", 0, &dwType, (LPBYTE)&mydata, &dataLength); //change the key you want to read
printf("%s\n", mydata);
system("PAUSE");
RegCloseKey(hKey);
}
else
MessageBox(NULL,(LPCTSTR)messagecaliss,"ERROR",MB_OK|MB_ICONINFORMATION);
printf("%s\t\n", mydata);
std::string FullPath(mydata,dataLength-1);
printf("%s\n", FullPath);
std::string FileName = GetFileNameFromPath(mydata);
printf("%s\n", FileName);
system("PAUSE");
Функция GetFilenameFromPath определяется как:
std::string GetFileNameFromPath (std::string str) {
size_t found;
found=str.find_last_of("/\\");
return str.substr(found+1);}
Когда я вызываю RegQueryValueEx с "QKSMTPServer3 "в качестве второго параметра, вот вывод:
C:\Program Files (x86)\QK SMTP Server 3\QKSmtpServer3.exe
Press any key to continue . . .
C:\Program Files (x86)\QK SMTP Server 3\QKSmtpServer3.exe
C:\Program Files (x86)\QK SMTP Server 3\QKSmtpServer3.exe
QKSmtpServer3.exe
Press any key to continue . . .
Что я и хочу.Теперь, когда я вызываю RegQueryValueEx с «Test2», я получаю:
C:\Test.exe
Press any key to continue . . .
C:\Test.exe
, и программа вылетает.Есть идеи, почему ??
Большое спасибо