Win CGI or Std CGI ?

I am currently developing an CGI application for Win NT in VC++.

The app can write correctly, however when it tries to get any enviroment strings it seems to hang and later times out.

An example of the enviroment string is       EnvBlock.strReqProtocol      = GetEnviroment("SERVER_PROTOCOL");

where the GetEnviroment function is defined as

char* GetEnviroment(CString EnvStr)
{
      char* sOut = "";
      
      //      Actually get the variable value
      GetEnvironmentVariable(EnvStr,sOut,GetEnvironmentVariable(EnvStr, NULL, 0));
      
      //      Return the enviroment variable to calling function
      return(sOut);
}

Is this correct ?

Regards

ManX
manxAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

manxAuthor Commented:
Just a comment on the error message:

A dialog box apperas on the IIS server saying that the app instr XXXX is trying to read/write to a illegal mem location XXX.

Regards

ManX
0
manxAuthor Commented:
Would there be any diference in the enviroment for GET and POST methods ?
0
manxAuthor Commented:
Would there be any diference in the enviroment for GET and POST methods ?
0
chensuCommented:
1. You are supposed to allocate the buffer when calling GetEnvironmentVariable.

2. When returning a pointer, the memory pointed to by the pointer must be valid out of the function scope.

char* GetEnviroment(CString EnvStr)
{
static char sOut[1024];

// Actually get the variable value
GetEnvironmentVariable(EnvStr,sOut,GetEnvironmentVariable(EnvStr, NULL, 0));

// Return the enviroment variable to calling function
return(sOut);
}

Using a static buffer is just one of the solutions. Using the new and delete operators may be better.

Since you are using CString, you may also do

CString GetEnviroment(CString EnvStr)
{
CString sOut;

DWORD size = GetEnvironmentVariable(EnvStr, NULL, 0);

// Actually get the variable value
GetEnvironmentVariable(EnvStr,sOut.GetBuffer(size),size);

sOut.ReleaseBuffer(-1);

// Return the enviroment variable to calling function
return(sOut);
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Scripting Languages

From novice to tech pro — start learning today.