Search code examples
c++web-servicescom

How to use a c++ application in web server?


I am using a C++ console application in windows. I want to use this application in my website so that input is taken from client side which then invokes this application to process it and output will be forward to the web server. I have heard about COM DLL but don't know how to create it for my application.


Solution

  • You should try creating a cgi script, depending on the needs of your application you should use FastCGI (which does not create an entire process context each time you call it).

    • CGI

    You should install an Apache Server and activate the cgi module(its activated by default commonly). Then you can develop a c++ program, put the executable inside the configured CGI folder, give the correct permissions. This CGI script should make some kind of inter-process communication (it could be through socket or shared memory, the first one is easier). I hope you know how a CGI script works in C/C++ + Apache, but its pretty straight forward, in summary you receive the environment inside stdin and put your answer to stdout.

    • FastCGI

    You can use apache, install the fastcgi module and create a thread (it could be inside your main loop too, but i dont recommend) inside your program and attach the apache server FastCGI module to your daemon.

    Last but not least, you should run your daemon as a service.

    PS : There are some framework options(like cppcms and wt), but since you already have the daemon written i thought it would be a pain in the ass to change everything (of course, it depends on a lot of things, like the complexity and size of your application).