Skip to main content
Visual C++ Samples 
Hotswap Sample: Replacing ATL Server Application DLLs at Run Time 

Download sample

Demonstrates how to replace ATL Server Web application DLLs at run time without losing requests.

When running this sample, use your favorite Web stress tool to verify that no requests are lost. The most that should happen is a small delay while the swap actually occurs.

Note that this mechanism only works for simple application DLLs. It relies on the fact that the DLL can be unloaded if no threads from the ATL Server thread pool are within a call to DispatchStencilCall. If your application DLL increments its reference count by registering a service with the ISAPI extension (through IServiceProvider), creates a secondary thread pool, or uses asynchronous processing, extra work will be required in CSwapExtension::StopRequests to negotiate the proper shutdown of the application DLL.

Additionally, this sample does not restrict who is allowed to request a swap. When using this mechanism, it is highly recommended that some form of role-based access check be performed.

Security noteSecurity Note

This sample code is provided to illustrate a concept and should not be used in applications or Web sites, as it may not illustrate the safest coding practices. Microsoft assumes no liability for incidental or consequential damages should the sample code be used for purposes other than as intended.


  • IIS

Building and Running the Sample

To build and run this sample

  1. Open the solution file, HotSwap.sln, in the Visual Studio development environment.

  2. Build the solution. This will also deploy the solution to the local Web server.

  3. Use a Web browser to view http://localhost/hotswap/hotswaptest.srf. You should see a simple greeting.

  4. Edit the code in OnHello in hotswaptest.h to change the greeting.

  5. Change the link settings for the HotswapTest project to output the DLL as and rebuild that project. This will also deploy the new DLL to the local Web server.

  6. Use a Web browser to view http://localhost/hotswap/hotswapadmin.srf.

  7. Enter the full paths of the original and new hotswaptest.dll files. For example, they might be:

    • Target: C:\Inetpub\wwwroot\hotswap\hotswaptest.dll

    • Source: C:\Inetpub\wwwroot\hotswap\

  8. Click the swap files button on the page.

  9. Use a Web browser to view http://localhost/hotswap/hotswaptest.srf. You should see the greeting modified in Step 4.


You will probably need to modify the security settings of the DLLs in the file system or of the virtual directory to enable copying to take place.


See Also