Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

getenv() in FDK

Guest
Jun 15, 2009 Jun 15, 2009

Hello,

I am looking for how to get environment variables in FDK. I understand that in C has function: getenv( "PATH" ); however, I could not find the similar fuction in FDK. Any suggestion or comment, I would appreciate it.

Thank you,

Thai Nguyen

1.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 18, 2010 Feb 18, 2010

Hi,

I'm looking for the same answer.

If I include a call to "genenv" Visual Studio 9 complains :

" error C2065: 'error' : undeclared identifier"

I've tried including <stdlib.h> and <cstdlib> but to no avail.

Am I missing a linker library?

Thanks,

Anupam

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Feb 18, 2010 Feb 18, 2010

Hi,

You haven't specified which version of Visual C++ you are using. For older versions, I've used this successfully:

#define DONT_REDEFINE

#include "stdlib.h"

StringT ws_getEnvVar(UCharT *var)

{
  UCharT *value;
  StringT returnStr;

  value = getenv(var);
 
  returnStr = F_StrCopyString(value);
  return returnStr;
}

In VC++ 9.0, it warns that getenv() may be obsolete and unsafe, so I use this now:

#define DONT_REDEFINE

#include "stdlib.h"

StringT ws_getEnvVar(UCharT *var)
{
  UCharT *value;
  StringT returnStr;

  errno_t err;

  err = _dupenv_s(&value, NULL, var);
  
  if(!err)
    returnStr = F_StrCopyString(value);
  else
    returnStr = F_StrCopyString("");

  free(value);

  return returnStr;

}

I'm not smart enough to fully understand the long-term consequencies of preventing the redefinition of types, so I have a single C file in my projects that handles all standard C activities and uses the DONT_REDEFINE inclusion. Note that you must have this line before #include fdetypes.h, as in:

#define DONT_REDEFINE
#include "fapi.h"
#include "fdetypes.h"

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Feb 18, 2010 Feb 18, 2010

There must be some keystroke that automatically clicks the Post button and that is quite annoying indeed. Anyway, I think that's about it.

Russ

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 02, 2010 Mar 02, 2010
LATEST

Thanks. That worked.

The magic of the #define DONT_REDEFINE made it work.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines