winapi - How to read multi line multi string registry entry in Visual C++? -


I'm using Visual Studio 2008 I'm working in VC ++ MFC application
I know how to read multi-line string values ​​registry.Here type REG_MULTI_SZ indicates a sequence of null-terminated strings, ends with an empty string (\ 0).
By now I'm only able to read the first line. Let me know how I can read more than one string at a time.
thanks Enter image details here

I tried to do something like this < / P>

  HKEY hKey; CString RegPath = _T ("Software \\ ... \\ ... \\"); // path if (ERROR_SUCCESS == :: RegOpenKeyEx (HKEY_LOCAL_MACHINE, RegPath, 0, KEY_READ | KEY_ENUMERATE_SUB_KEYS | KEY_QUERY_VALUE | KEY_WOW64_64KEY, & amp; HKEY)) {DWORD nBytes, dwType = REG_MULTI_SZ; CString version; If (ERROR_SUCCESS == :: RegQueryValueEx (HKEY, _T ( "Options"), void, & amp; dwType, 0, & amp; nBytes)) {ASSERT (REG_MULTI_SZ == dwType); LPTIRR buffer = version Getbuffer (NBEIT / Size (TCHAR)); Verify (ERROR_SUCCESS == :: RegQueryValueEx (HKEY, _T ("options"), zero, 0, (LPBYTE buffer, & amp; nBytes)); AfxMessageBox (buffer); // display only the first line version ReleaseBuffer (); } :: Regloseke (HK); }  

Let's say that your multi-string two strings "Atal Bihari" and "CD" Consists of.

The layout in memory is like this:

  + -------- + | 'A' | & Lt; - Buffer // First String + -------- + | 'B' | + -------- + | 0 | // Terminator of the first string + -------- + | 'C' | // second string + -------- + | 'D' | + -------- + | 0 | // Terminator of the second string + -------- + | 0 | // Terminator + multi-string + -------- +  

Therefore AfxMessageBox (buffer) only shows the first string

< p> you multi-code CString should not be read in the CString nULL only related to terminated string multi code TCHAR in buffer Should read and then parse that buffer to remove individual strings.

Actually:

  ASSERT (REG_MULTI_SZ == dwType); LPTIT buffer = new TCHAR [nbits / psychophag (TCHAR)]; Verify (ERROR_SUCCESS == :: Valuax of RegUe (Hke, _T ("option"), zero, 0, (LPBYT buffer, and nbits); CStringArray strings; CONST TCHAR * P = buffer; while (* p) // string not at the end (Strings.ad (P); // array p + = _tcslen (p) + Add string 1; // Next string searches} delete [] buffer; // display all strings (debug and Dispshn For the purpose (for int i = 0; i & lt; strings; gatecount (); i ++) {AF Message box (strings [i]);} // Now the string array contains all the strings  

Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -