Skracanie stringa

0

Witam. Mam problem ze skróceniem stringa, który sobie pobrałem z rejestru.

HKEY hkSoftware;
HKEY hkTest;
LONG result;
string buf;
DWORD dwBufSize = 255;
DWORD dwRegsz = REG_SZ;
int a;

result = RegOpenKeyEx( HKEY_CURRENT_USER, "SOFTWARE", 0, KEY_ALL_ACCESS, & hkSoftware );
if( result == ERROR_SUCCESS ) {
        result = RegOpenKeyEx( hkSoftware, "SAMP", 0, KEY_ALL_ACCESS, & hkTest );
        if( result == ERROR_SUCCESS ) {
                result = RegQueryValueEx(hkTest, "gta_sa_exe", NULL, & dwRegsz,( LPBYTE ) buf.c_str(), & dwBufSize );
                if( result == ERROR_SUCCESS ) {
                       sciezka=buf;
                       sciezka.resize(sciezka.size()- 10); //Tutaj wywala mi error podczas działania programu...
                       MessageBox(NULL,sciezka.c_str(),"TEST",MB_ICONINFORMATION);
                       RegCloseKey(hkTest);
                       RegCloseKey(hkSoftware);
                }
          }
} 

Nie mam zielonego pojęcia co robię źle. Byłbym wdzięczny, gdyby ktoś mi pomógł :)
http://i45.tinypic.com/1zbtrly.jpg

1
result = RegQueryValueEx(hkTest, "gta_sa_exe", NULL, & dwRegsz,( LPBYTE ) buf.c_str(), & dwBufSize );

To jest jakiś WTF. Nie możesz w ten sposób wpisać danych do stringa... Użyj tablicy znaków.

EDIT: z dokumentacji c_str:

The returned array points to an internal location with the required storage space for this sequence of characters plus its terminating null-character, but the values in this array should not be modified in the program and are only guaranteed to remain unchanged until the next call to a non-constant member function of the string object.

0

Zależy mi właśnie, aby to był string. Tylko nie wiem jak tam wpisać te dane do niego.

1
string str;
char *buf; // albo wchar_t jeśli unicode
result = RegQueryValueEx(blabla, buf, blabla);
str = buf;
0

Jakie to banalne... Zbyt "głębokiego" rozwiązania szukałem, dzięki za pomoc. Do zamknięcia.

1 użytkowników online, w tym zalogowanych: 0, gości: 1