Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

CreateProcess: Environment block

Posted on 1999-06-29
5
Medium Priority
?
1,165 Views
Last Modified: 2008-03-06
Hi,
somehow I can not set the env variables correctly.
I am looking for some help with the null terminate block
thingy.
currently I am trying:

char *env[2];
env[0]="MYTMP=c:\\"
env[1]=0;

but this fails.
how is this block structure designed ?

thanks,
markus
0
Comment
Question by:boyracer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 2

Expert Comment

by:cpopin
ID: 1198737
Don't modify the env[] variable directly; use getenv() and putenv() instead.  The env[] variable is an array of char pointers ending in a NULL pointer.
0
 

Expert Comment

by:corodent
ID: 1198738
Are you using this in conjunction with the CreateProcess Win32 API call?

If so, the format of the block is a null-terminated list of null-terminated strings of the form "name=value".

ie:
char env[1024] ;
char *p = env ;

strcpy( p, "a=b" ) ;
p += strlen( "a=b" ) + 1 ;
strcpy( p, "b=c" ) ;
p += strlen( "b=c" ) + 1 ;
*p = '\0' ;

0
 

Author Comment

by:boyracer
ID: 1198739
I would like to give the points to corodent, since he
was proposing the correct answer, ok?
0
 

Accepted Solution

by:
corodent earned 200 total points
ID: 1198740
See my previous comment about the format.
0
 

Author Comment

by:boyracer
ID: 1198741
That was the trick
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question