We help IT Professionals succeed at work.

Calling C++ functions from CGI

speedygonzalez used Ask the Experts™

After posting a question previously on how to talk to a C++ library class from a web client (view http://www.experts-exchange.com/Programming/Languages/CPP/Q_26278170.html) it was suggested that I should use CGI for doing so.

I have been reading up on CGI and how I should best do this. I noted there is even a capability called inline:c++ in which C++ code can be written within a perl CGI script.

I tried to install inline:c++ but I keep getting errors when I try to do so.

Is inline:C++ even the best option (if for example using a perl script).?

I'm very new to this to be honest & still quite unsure how I can call functions from a C++ class/library from CGI.  Any further suggestions or examples (samples) would be very much appreciated.

My web server is IIS & I wish to execute my Classic ASP website -> interacting with C++ libraries sitting on the webserver maching  (probably using CGI as suggested in http://www.experts-exchange.com/Programming/Languages/CPP/Q_26278170.html)

Thanks in advance!
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2012
Well, as in your other Q - you can call C++ CGI executables directly from your web server, no PERL layer is needed for that.
I dont think CGI was the right choice (after having read your earlier question). At best, it's one of the possible ways, but your description of problem wasn't enough to conclude that CGI would be the best option.
Some questions:
- You said its an application and/or library. Which is it? Is it a dll? IF its just calling a dll function then that is possible even in ASP.NET and classic ASP ( I mean call directly, with some limitations perhaps ).
- What does your application do? Can you modify it?
>> any examples out there where poeple have connected to backend C++ applications from a website?
I don't recall an example, but it's easy of think of a Java Applet connecting to some backend server. It all depends upon how your application is written
- If the application is an HTTP server (has an HTTP server), then you can just POST or ajax calls to it using javascript etc. Adding HTTP server support to a C++ application is easily accomplished by the use of toolkits like POCO for example. If i'm not forgetting boost also has such features.
- If its just a dll/lib, then on IIS, you can write HTTP filters/handler (dlls loaded by IIS that do special work, like the one that does url rewriting). Those can take the HTTP request and delegate to the lib.
- You can even build a simple surrogate HTTP Server that can take requests and delegate to the dll (this is same as the first option above).
- CGI is also possible, but more suited if your application is accustomed to read from stdin and write to stdout. (a console application)
Note that in all of the cases and solutions given so far, the baseline idea is the use of HTTP to talk to the backend, because thats the most common possible way.


Hi guys, thank you for your help. Both comments very much appreciated.
jkr, I had presumed I needed to use something like inline:c within perl but you are right c++ compiled to cgi does seem to work correctly as required.
Ambience, thank you, that is a very detailed and informative answer as well.

I'll give you both the points as both answers have helped!