Skip to main content
15-Moonstone
July 10, 2017
Question

C Function getenv() crashing in Windows10

  • July 10, 2017
  • 1 reply
  • 4724 views

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"));

 

1 reply

24-Ruby III
July 11, 2017

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

msteffke15-MoonstoneAuthor
15-Moonstone
July 12, 2017

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.  

  

24-Ruby III
July 12, 2017

Hi @TomasLoun,

 

please can you comment the problem ?