Click here to Skip to main content
15,887,399 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
How can we parse
RegOpenKeyEx(HKEY_LOCAL_MACHINE,L"SYSTEM\\CurrentControlSet\\Enum\\BTHENUM\\{00001101-0000-1000-8000-00805f9b34fb}_LOCALMFG&000f\\9&3408FE52&0&646E6C00E02E_C00000000\\Device Parameters", 0, KEY_QUERY_VALUE, &hKey)  )


so that we can use it for each GUID (traversing available guid to DeviceParameters )

SYSTEM\\CurrentControlSet\\Enum\\BTHENUM\\[GUID1...x]\\[Somenumber]\\DeviceParameters


Currently i am able to do it for single hard coded GUID value but GUID may differ machine to machine so i want to make it dynamic GUID parsing.

LPCTSTR const lpValueName = L"PortName";
	  HKEY  hKey       = NULL; 
	  
   if(ERROR_SUCCESS != RegOpenKeyEx(HKEY_LOCAL_MACHINE,L"SYSTEM\\CurrentControlSet\\Enum\\BTHENUM\\{00001101-0000-1000-8000-00805f9b34fb}_LOCALMFG&000f\\9&3408FE52&0&646E6C00E02E_C00000000\\Device Parameters", 0, KEY_QUERY_VALUE, &hKey)  )
       return 1;
  

   DWORD dwDataType = 0;
   LPBYTE lpValue   = NULL;

   RegQueryValueEx(  hKey, 
                     lpValueName,
                     0,
                     &dwDataType,
                     lpValue,  // NULL
                     &dwSize); // will contain the data size
	

   // Alloc the buffer
   lpValue = (LPBYTE)malloc(dwSize);

   // Call twice RegQueryValueEx to get the value
   int lRet = RegQueryValueEx(hKey, 
                            lpValueName,
                            0,
                            &dwDataType,
                            lpValue,
                            &dwSize);
	RegCloseKey(hKey);



Thanks in advance :)
Posted

Have a look at the links with some examples of how to traverse the registry:
http://msdn.microsoft.com/en-us/library/df4afx57.aspx[^]

http://www.codeguru.com/cpp/w-p/system/registry/article.php/c5671[^]

Good luck!
 
Share this answer
 
Comments
01.mandar 18-Oct-11 8:22am    
second link was helpful
01.mandar 18-Oct-11 8:27am    
how can we detect heap corruption..? (possible due to malloc ,tried to free() but didn't worked)
what points i have to consider
Use RegEnumKeyEx[^], and any of the other enumeration functions to find the elements that you are interested in.
 
Share this answer
 
Comments
01.mandar 18-Oct-11 8:23am    
RegEnumKeyEx, RegQueryInfoKey worked for me Thanks
01.mandar 18-Oct-11 8:27am    
how can we detect heap corruption..? (possible due to malloc ,tried to free() but didn't worked)
what points i have to consider
Richard MacCutchan 18-Oct-11 8:45am    
You need to trace what you are doing with any dynamically allocated buffers. The debugger is the best tool to help you. When you say tried to free() but didn't work, what exactly do you mean?
01.mandar 18-Oct-11 9:42am    
oh! that was a typing mistake it was LpValueElement1 in place of LpValueElement2 :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900