CGI error

I am tryng to write CGI routines for the first time in VC++ .

There seems to be a problem with the write function. Is the following code correct ?

extern "C" _declspec(dllexport) void WriteCGI(CString stext)
{
      
      HANDLE hconsole;
      DWORD NumberOfBytesWritten;

      //      Get handle to std output device
      hconsole = GetStdHandle(STD_OUTPUT_HANDLE);

      //      Write to standard device
      WriteFile (hconsole,&stext,stext.GetLength(),&NumberOfBytesWritten,NULL);
}

The function produces the proper output when run locally on a MS-Dos console.
When running on the IIS, the function returns no response. The error is http 502 invalid gateway


Is it trying to write to a wrong port ?

Thanks and 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.

chensuCommented:
You need to output the following header first.

"Content-Type: text/html\n\n"

You also need to output the HTML tags, such as <HTML></HMTL>, <BODY></BODY>, ...

And, you don't have to use WriteFile. Using cout is much easier.
0
manxAuthor Commented:
The content headers are all outputed first; i.e

WriteCGI("Content-type: text/vnd.wap.wml\n\r");
WriteCGI("<?xml version= \"1.0\" ?>\n\r");
WriteCGI("<!DOCTYPE wml PUBLIC>\n\r");
WriteCGI("<wml>\n\r");
WriteCGI("<card id=""cardname"">\n\r");
WriteCGI("      <p>\n\r");
WriteCGI("WRITECGI successful\n\r");
WriteCGI("      </p>\n\r ");
WriteCGI("</card>\n\r");
WriteCGI("</wml>\n\r");

It still does not work.

The cout/WriteFile should not make a difference. But will try it out any how.
0
manxAuthor Commented:
Nope changing the WriteFile to a cout does not affect the outcome. The gateway error still occurs.

Regards

ManX
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

chensuCommented:
There must be two new lines after the Content-Type header.

WriteCGI("Content-type: text/vnd.wap.wml\r\n\r\n");

or

WriteCGI("Content-type: text/vnd.wap.wml\n\n");
0
manxAuthor Commented:
Well,

The problem still persists after adding the 2 \r\n chars at the end of the content type string.

Regards

ManX
0
chensuCommented:
Try the following simplest line to see if there is still an error message.

WriteCGI("Content-Type: text/html\n\n<html></html>");
0
manxAuthor Commented:
After changing the sample app to WriteCGI("Content-Type: text/html\n\n<html></html>");

It still does not work. When running the exe file off the IIs from the browser, the error message recieved is
"CGI Error
The specified CGI application misbehaved by not returning a complete set of HTML headers. The headers returned include :"

Thus it does not seem to be returning any thing at all. Would it be because it is writing to the wrong port or the file transfer mode has to be set to binary etc....

Regards

ManX
0
manxAuthor Commented:
After changing the sample app to WriteCGI("Content-Type: text/html\n\n<html></html>");

It still does not work. When running the exe file off the IIs from the browser, the error message recieved is
"CGI Error
The specified CGI application misbehaved by not returning a complete set of HTML headers. The headers returned include :"

Thus it does not seem to be returning any thing at all. Would it be because it is writing to the wrong port or the file transfer mode has to be set to binary etc....

Regards

ManX
0
manxAuthor Commented:
After changing the sample app to WriteCGI("Content-Type: text/html\n\n<html></html>");

It still does not work. When running the exe file off the IIs from the browser, the error message recieved is
"CGI Error
The specified CGI application misbehaved by not returning a complete set of HTML headers. The headers returned include :"

Thus it does not seem to be returning any thing at all. Would it be because it is writing to the wrong port or the file transfer mode has to be set to binary etc....

Regards

ManX
0
manxAuthor Commented:
Just another comment,

All the above code when run on the local machine during development. Seems to run just fine; i.e the sample console app outputs all the required strings to the MS DOS window.

Regards

ManX
0
manxAuthor Commented:
Just another comment,

All the above code when run on the local machine during development. Seems to run just fine; i.e the sample console app outputs all the required strings to the MS DOS window.

Regards

ManX
0
szetoaCommented:
I don't think your problem is with the code, but with the permission on your web server.  First you have to make sure you can execute a .exe program (use web manager to check if the directory housing your .exe has 'execute' access).  Then you have to make sure any library your program needs is also accessable (check permissions on those directories).  I sugguest you write a simple c program with a couple getenv() just to display back the following information:

PATH USERNAME

Hope this helps.
0
manxAuthor Commented:
Managed to solve the problem. Turns out the prob existed as the transfre mode was set to binary not ascii text.

Thanks one and all for all the comments/advice given

Regards and Happy Y2K

ManX
0
ianBCommented:
Hi,

I am answering this question so it can be saved as a PAQ. The user wishes to award the two experts 50 points each for the help provided

"However I would like to allocate 50pts to both chensu and szetoa. Both with good grades"

Each expert will find a question for them to answer in this topic area.

ian
Community Support @ Experts EXchange
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.