?
Solved

Win CGI or Std CGI ?

Posted on 1999-12-28
4
Medium Priority
?
474 Views
Last Modified: 2013-12-25
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
0
Comment
Question by:manx
  • 3
4 Comments
 

Author Comment

by:manx
ID: 2311988
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
 

Author Comment

by:manx
ID: 2311991
Would there be any diference in the enviroment for GET and POST methods ?
0
 

Author Comment

by:manx
ID: 2311996
Would there be any diference in the enviroment for GET and POST methods ?
0
 
LVL 23

Accepted Solution

by:
chensu earned 150 total points
ID: 2315391
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

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Question has a verified solution.

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

This tutorial will discuss fancy secure registration forms, with AJAX technology support. In this article I assume you already know HTML and some JS. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you mig…
Recently I have been answering a lot of questions like this in IT forums that I frequent. The question posed is usually something along the lines of "We have software X installed and need to uninstall it for reason Y" or some other variant of the sa…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

601 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