Skip to main content
15-Moonstone
Jul 10, 2017 6:26 PM UTC
Question

C Function getenv() crashing in Windows10

I.T.  updated one of my Engineers to Windows 10.  He is our first one using Creo 3.0 m120 on the Windows 10 platform.   One of my Toolkit Applications crashes on initialization.  The apps work fine on the Win7 platform.   I have Narrowed it down to the getenv() function.     I checked on another program and sure enough the function where that is used crashes too.  It does not crash on the call, but on the next line.    I am compiling with VS 2012 (approved for Creo 3).

The getenv() is pretty critical to me as my apps run in different sites and different countries.

Has anyone else seen this, or can someone else verify this? 

FILE *fp; /* test output */

char myvar[80];

char myvar2[16];

char *value;

 

SiteCode = 1;

fp = fopen ("c:\\temp\\subs.txt", "w");

/*================================================================*/

/*       Set global variables for exports  */

 

      value = getenv("MFG_SITE");

      strcpy(myvar2, value);     /******************** Will crash here */

      if (strstr(myvar2, "MTP") != NULL)

                                  SiteCode = 1;

      if (strstr(myvar2, "CRV") != NULL)

                                  SiteCode = 2;

      if (strstr(myvar2, "BGV") != NULL) 

                                  SiteCode = 3;

 

I also have crashes when trying to use the return value directly. 

  fprintf (fp, "Plat code is: %s  \n" , getenv("MFG_SITE"));

 

7 replies

24-Ruby III
Jul 11, 2017 5:28 AM UTC

Hi,

 

I was just curious, therefore I asked Google > getenv() function windows 10

 

One resulting link is https://stackoverflow.com/questions/631664/accessing-environment-variables-in-c - maybe it gives you some idea how to solve the problem.

 

MH

Translate
msteffke15-MoonstoneAuthor
15-Moonstone
Jul 12, 2017 12:43 PM UTC

Thanks Martin.  From What I can tell so far it seems that Windows10 doesn't appreciate app compiled in VS2012 which is the required compiler for Creo 3.0.   That function seems to be a source of contention, but I am just reading the vars.   That being said I have a colleague who says getenv  it works for them in a Creo3 app running on Win10..  I made a freestanding (console app) and it wont run in windows 10 either.  I am using VS studio express.  I compile via command line using MAK files.  

  

Translate
24-Ruby III
Jul 12, 2017 12:47 PM UTC

Hi @TomasLoun,

 

please can you comment the problem ?

Translate