Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Visual C++ getenv

199 views
Skip to first unread message

Lamont Norman

unread,
Aug 19, 2002, 3:28:52 PM8/19/02
to
I have a getenv call that only returns -1 and I don't understand why.
I can get the TMP, path, windir and other variable values defined by
the system and installs but not variables that I have created. I am
using Windows 2000 and have set the environment variable using the
registry (regedt32 and regedit) and the My Computer -> Properties ->
Advanced -> Environment Variables page. I have declared the variable
as a system variable and as a user variable. I have also rebooted the
machine after adding the declarations. I am the administrator for the
development machine. I have run out of ideas. Any suggestions would
be helpfull!

Thank you.
Lamont Norman
Idea Integration
Lamont...@Idea.com

Igor Tandetnik

unread,
Aug 19, 2002, 3:42:19 PM8/19/02
to
Does the variable show when you type "set" on the command line? If yes,
show the code that calls getenv
--
With best wishes,
Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken

"Lamont Norman" <Lamont...@Idea.Com> wrote in message
news:498d2970.02081...@posting.google.com...

Lamont Norman

unread,
Aug 20, 2002, 10:36:16 AM8/20/02
to
Here is some of the code...

// SelectWinDerived.cpp: implementation of the CSelectWinDerived
class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "DataWindow.h"
#include "SelectWinDerived.h"
#include <stdlib.h>
#include <windows.h>

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

.
.
.

void
CSelectWinDerived::pdmTopicCreate(CDialog* parent) // IDEA Widget
widget, XtPointer, XtPointer)
/*
Description:
Create logic for the pull down menu on topics, used to define
the items which will be in this menu.
Args:
Standard.
Returns:
nothing.
*/
{
char sSql[MAXPATHLEN]; // SQL Statement
int nStatus = 0; // Generic status indicator.
RWCString sErrorMessage; // Error message method return
int user_type; // user type from support table
int nLoop; // loop variable

CDataWindowDlg* Parent = (CDataWindowDlg*) parent;
//
// Update the topics option menu.
//
TRACE0( pdmTopicCreate begin );

//
// Get the list of "subtopics" for this "topic"
//
//int r = putenv("USER_TYPE=1");
CString ut = getenv("USER_TYPE");
user_type = 1;//atoi(getenv("USER_TYPE"));


I can use putenv to set USER_TYPE and retrieve it successfully.
However, the settings I have made via Windows 2000 are not read.


"Igor Tandetnik" <itand...@whenu.com> wrote in message news:<uySOoh7RCHA.1496@tkmsftngp11>...

Igor Tandetnik

unread,
Aug 20, 2002, 11:12:48 AM8/20/02
to
What's the output of SET command on the command line on your system?

--
With best wishes,
Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken

"Lamont Norman" <Lamont...@idea.Com> wrote in message
news:45b2c550.02082...@posting.google.com...

Lamont Norman

unread,
Aug 21, 2002, 10:17:57 AM8/21/02
to
The output of the SET command is below. The variable of interest is
the USER_TYPE=1.

ALLUSERSPROFILE=C:\Documents and Settings\All Users.WINNT
APPDATA=C:\Documents and Settings\lnorman.IDEA\Application Data
APRESSTMPDIR=C:\DOCUME~1\LNORMA~1.IDE\LOCALS~1\Temp
ARCHOME=C:\arcgis\arcexe81
ARCHOME_USER=C:\arcgis\arcexe81
ARCINFOFONTNAME=Courier New
ARCINFOFONTSIZE=8
ATHOME=C:\arcgis\arcexe81\arctools
CommonProgramFiles=C:\Program Files\Common Files
COMPUTERNAME=CO034WS2KPROD17
ComSpec=C:\WINNT\system32\cmd.exe
HOMEDRIVE=Z:
HOMEPATH=\
HOMESHARE=\\co007dc2kprod01\users\lnorman
include=C:\Program Files\Microsoft Visual
Studio\VC98\atl\include;C:\Program Files\Microsoft Visual
Studio\VC98\mfc\include;C:\Program Files\Microsoft Visual
Studio\VC98\include
lib=C:\Program Files\Microsoft Visual Studio\VC98\mfc\lib;C:\Program
Files\Microsoft Visual Studio\VC98\lib
LOGONSERVER=\\CO007DC2KPROD02
MSDevDir=C:\Program Files\Microsoft Visual Studio\Common\MSDev98
NUMBER_OF_PROCESSORS=1
OS=Windows_NT
Os2LibPath=C:\WINNT\system32\os2\dll;
Path=C:\oracle\ora81\bin;C:\Program
Files\Oracle\jre\1.1.7\bin;C:\WINNT\system32;C:\WINNT;C:\WINNT\System32\Wbem;C:\Program
Files\Microsoft SQL Server\80\Tools\BINN;C:\ArcGIS\ArcSDE\sqlexe\bin;C:\arcgis\arcexe81\bin;C:\Program
Files\Microsoft Visual Studio\Common\Tools\WinNT;C:\Program
Files\Microsoft Visual Studio\Common\MSDev98\Bin;C:\Program
Files\Microsoft Visual Studio\Common\Tools;C:\Program Files\Microsoft
Visual Studio\VC98\bin
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
PROCESSOR_ARCHITECTURE=x86
PROCESSOR_IDENTIFIER=x86 Family 6 Model 8 Stepping 3, GenuineIntel
PROCESSOR_LEVEL=6
PROCESSOR_REVISION=0803
ProgramFiles=C:\Program Files
PROMPT=$P$G
SDEHOME=C:\ArcGIS\ArcSDE\sqlexe\
SystemDrive=C:
SystemRoot=C:\WINNT
TEMP=C:\DOCUME~1\LNORMA~1.IDE\LOCALS~1\Temp
TMP=C:\DOCUME~1\LNORMA~1.IDE\LOCALS~1\Temp
USERDNSDOMAIN=idea.com
USERDOMAIN=IDEA
USERNAME=lnorman
USERPROFILE=C:\Documents and Settings\lnorman.IDEA
USER_TYPE=1 <=========================================== This looks
correct!!!!
WF_RESOURCES=C:\oracle\ora81\WF\RES\WFUS.RES
windir=C:\WINNT


"Igor Tandetnik" <itand...@whenu.com> wrote in message news:<uxY9owFSCHA.4328@tkmsftngp09>...

Igor Tandetnik

unread,
Aug 21, 2002, 11:11:36 AM8/21/02
to
This program works just fine for me:

#include <stdlib.h>
#include <stdio.h>

int main()
{
printf("USER_TYPE=%s\n", getenv("USER_TYPE"));
return 0;
}

I have just added USER_TYPE variable via Control Panel | System |
Advanced | Environment Variables | User Variables for... I had to
restart Visual Studio for it to notice the new setting, after which the
program started working happily.

Try also this program:

#include <stdlib.h>
#include <stdio.h>

int main()
{
for (char** p = _environ; *p; ++p)
{
printf("%s\n", *p);
}
return 0;
}

It prints all environment variables it knows about.


--
With best wishes,
Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken

"Lamont Norman" <Lamont...@Idea.com> wrote in message
news:498da190.02082...@posting.google.com...

0 new messages