Home > OS > [question] how to use a nested path to access two different paths, specific please see detailed desc
[question] how to use a nested path to access two different paths, specific please see detailed desc
Time:10-04
Dear Daniel, my side when doing the project meet a problem:
A software to compatible with different systems of the two systems registry path is different, but the code requires a logical path to said, such as:
A system, the registry path:/SOFTWARE/WcndFn/Ulter B system, the registry path:/SOFTWARE/Ulter
Actually a, b system registry path have sent level folder, a system level more WcndFn folder, but the code requires to a logical path to access these two different paths, are using the Windows API function RegOpenKeyEx, function is as follows:
LONG RegOpenKeyEx ( Hkeys hkeys,//the name of the need to open the primary key of the LPCTSTR lpSubKey,//need to open the child key the name of the DWORD ulOptions,//reserve, to 0 REGSAM samDesired,//security access tag, that is, permission PHKEY phkResult//to get a handle to the open key )
Originally program only needs to be run on a system, so the second RegOpenKeyEx parameters only need to "//SOFTWARE//WcndFn//Ulter" is ok, but now requires compatible program b system, not the original this way, the b on the system could not find the corresponding registry path, because the code is an absolute path, can only access the same path and a system registry,
Now thinking of the original "//SOFTWARE//WcndFn//Ulter" the string into a logical representation of the path, and then to RegOpenKeyEx, this can be found on a system/SOFTWARE/WcndFn/Ulter, and on b system/SOFTWARE/Ulter can be found,
How to construct the string ah, or how to construct such a path, can be compatible with both cases? Asked not to let in a way to distinguish the system into different path, can only use a logic path or a relative path, Program is written in C/C + +, cannot use regular expressions, the system is of two kinds of different Windows system, Give everyone a great god to a reasonable solution ~ ~ ~, on the Internet can't find a reasonable solution, T_T, ~ ~ thank you Daniel
CodePudding user response:
The variables in directly, Prepare a set of global variables, two sets of values, the program runs, judge system version first, according to the different versions, one set of values