Link to home
Start Free TrialLog in
Avatar of bhavana75
bhavana75

asked on

How to get the defined value for user environment variables?

Hi All,
      I would be facing the value in getting the defined value for user environment variables..
  I used ExpandEnvironmentStringsForUser(),which is a shell API...
Platform is .NET 2003(VC++.NET),Windows Xp...
  getting error like " error C2039: 'ExpandEnvironmentStringsForUser' : is not a member of 'operator``global namespace'''

I have included UserEnv.h file and also added UserEnv.lib file...

Need suggestion very badly
Thanks in Advance,Deepa.
Avatar of jkr
jkr
Flag of Germany image

Are you using 'C++.NET' (aka 'managed C++')? If so, see http://msdn.microsoft.com/library/en-us/dndotnet/html/win32map.asp ("Microsoft Win32 to Microsoft .NET Framework API Map")

'ExpandEnvironmentStringsForUser()' maps to:

Microsoft.Win32.Registry class
Microsoft.Win32.RegistryKey.OpenSubKey(name).GetValueNames, and then call GetValue for each name
Avatar of bhavana75
bhavana75

ASKER

Thanks for your response....I would need the win32 APIs only...Eventhough my platform is VC++.NET..Just explain me how to use  ExpandEnvironmentStringsForUser() function...
Thanks,Deepa.
Since ExpandEnvironmentStringsForUser is included in Windows XP and Windows 2000 Professional, you need to add precompiler constants before including of Userenv.h, as described here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winprog/winprog/using_the_windows_headers.asp

Try this:

#define _WIN32_WINNT 0x0500
#include <Userenv.h>
tried with what you said ...But there is no luck Alex.....
still getting the error as
error C3861: 'ExpandEnvironmentStringsForUser': identifier not found, even with argument-dependent lookup...

Thanks in Advance,deepa.
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
WINVER problem is usually result of working without SDK.
Hi Jkr,
    I have implemented the way u suggested..It started working...
Thanks ...
Does this function works only for windows versions which are higher than NT & later or for other windows versions also like win98,me,etc..
Thanks,Deepa.
Hi Alex,
>>WINVER problem is usually result of working without SDK...
  I didnt understand exactly what working without SDK...
Thanks,Deepa.
WINVER is defined in SDK headers to the latest Windows version. If there are some problems with WINVER, this usually means that SDK is not installed or it's headers are not used by VC++ compiler.
SDK can be downloaded from Microsoft WEB site:
http://www.microsoft.com/downloads/details.aspx?FamilyId=A55B6B43-E24F-4EA3-A93E-40C0EC4F68E5&displaylang=en

In the list of VC++ include directories (Tools - Options - Directories - Include files) SDK include directory should be listed on the first place, before VC++ include directories. The same for library directories.