Create and load modules on Windows

Aug 30, 2007 13:10 GMT  ·  By

The main advantage of Apache is that you can use many Unix modules on Windows platform with no change or changing just a little bit. Other modules depend on aspects of the Unix architecture which are not present in Windows, and will not work.

You can add the modules in Apache using two methods. The first is to compile the module directly into the server. Unfortunately, this can be done only in Unix. In Windows you can't do that, so you must add the source code of the module to the ApacheCore project file, and its symbols must be added to the oswin32modules.c file.

The second method is to create a DLL, compiling the source code of the module. Then you will load the module using the LoadModule directive. The main advantage is that you can distribute your module with Apache distribution and the user won't recompile the Apache sources.

To create a DLL you have to make a small change to the module's source code: you must export the module record from the DLL. In your module's record definition add the AP_MODULE_DECLARE_DATA. This is defined in the Apache header files. So, if your module has:

module softpedia_module;

Replace the above with:

module AP_MODULE_DECLARE_DATA softpedia_module;

This will only be activated on Windows. You can use it unchanged with Unix if you need it.

After that, create a DLL containing your module. To do so, link this against the libhttpd.lib export library. This is created after you compile the libhttpd.dll shared library that is located in your server root's modules directory. It is best to grab an existing module .dsp file from the tree to assure the build environment is configured correctly, or alternately compare the compiler and link options to your .dsp.

Place the DLL in the modules directory of your server root, and use the LoadModule directive to load it.

LoadModule softpedia_module modules/mod_softpedia.so;