ClickOnce Deployment for Unmanaged Code (C++, VB6, etc)

ClickOnce is a great deployment model for many Windows applications built with the .NET Framework. Too bad it isn’t supported for C++, VB 6, or other technologies. Or is it…

Surprisingly, you can deploy your unmanaged apps with ClickOnce. You just need a tiny .NET app to get it started.

Here’s how it works:

  1. Take your existing C++ project.

  2. Add to the solution a .NET console application.

  3. Change the project settings on the console application to “Windows Application”.

  4. Write the following code for your Main method of your .NET launcher application:

      static void Main(string[] args) {  try { Process.Start( "TheRealApp.exe" ); } catch ( Exception x ) {  string msg = "Error launch application:\n\n" + x;  string cap = "Error Launching Application"; MessageBox.Show( msg, cap, MessageBoxButtons.OK, MessageBoxIcon.Error ); } } 
    
  5. Set the build path of your C++ app to be in the main folder for your .NET application.

  6. Add the C++ app and its libraries (if any) as existing items in the .NET app.

  7. Change the build action to “Always Copy” as shown here:

    Visual Studio file properties with Build Action set to Copy always Solution Explorer showing TheRealApp.exe added to the project
  8. Then you publish your .NET application and when it runs, TADA!, the C++ app is deployed, versioned, and kept up to date as well.

The C++ app running after ClickOnce deployment

If you want to try it yourself, you can run this sample application here:

Run Michael’s Useless C++ App via ClickOnce… [defunct link: http://michael-kennedy.s3.amazonaws.com/blog/more-downloads/ClickOnceCpp/ClickOnceCpp.application]

You can also download the source [defunct link: http://michael-kennedy.s3.amazonaws.com/blog/more-downloads/clickoncecppsource.zip].