Skip to content

Latest commit

 

History

History
93 lines (69 loc) · 3.61 KB

File metadata and controls

93 lines (69 loc) · 3.61 KB

import InstallVpk from './content/_install-vpk.mdx'; import BuildRelease from './content/_build-release.mdx'; import Completion from './content/_completion.mdx';

Getting Started: C / C++

Get started with our cross-platform C / C++ library.

The Velopack C / C++ library is a pre-compiled dynamic library, which you can link into your application to enable auto-updates and installers. There is a C and a C++ API available in Velopack.h, so this library is suitable for C / C++ application as well as other programming languages which support calling C functions eg. p/invoke.

:::tip All the strings (eg. char* or std::string) are expected to be UTF-8 encoded. On Windows, you may need to convert wchar_t* and std::wstring to UTF-8 before passing it to the library. :::

Download the latest `velopack_libc_{version}.zip` from [GitHub Releases](https://github.com/velopack/velopack/releases) and include it into your project. Extract the contents of the zip file to a directory you can reference in your project. Add the `include` directory from the extracted content to your include path, and add the appropriate binary from `lib` to your linker options. You will find both a `lib` and `lib-static` directories in the extracted contents. Add `VelopackApp` to your entry point (eg. `main()` or `wmain()`) as early as possible, ideally the first statement to run: ```cpp #include "Velopack.h"
int wmain(int argc, wchar_t* argv[], wchar_t* envp[])
{
    // This should run as early as possible in the main method.
    // Velopack may exit / restart the app at this point. 
    // See VelopackApp class for more options/configuration.
    Velopack::VelopackApp::Build().Run();

    // ... your other startup code here
}
```
Velopack provides a simple way to check for updates and apply them. The following show how to implement a basic update check within your application.
You can also split up the various methods to allow your users to control when to check for updates, download them, or apply them.

The URL passed to `UpdateManager` points at wherever you host your updates (a web server, S3 bucket, GitHub releases, etc.).

```cpp
#include "Velopack.h"

static void update_app()
{
    Velopack::UpdateManager manager("https://the.place/you-host/updates");

    auto updInfo = manager.CheckForUpdates();
    if (!updInfo.has_value()) {
        return; // no updates available
    }

    // download the update, optionally providing progress callbacks
    manager.DownloadUpdates(updInfo.value());

    // prepare the Updater in a new process, and wait 60 seconds for this process to exit
    manager.WaitExitThenApplyUpdate(updInfo.value());
    exit(0); // exit the app to apply the update
}
```

Unlike the C# and Python SDKs, the C / C++ library has no single apply-and-restart helper, so you call `WaitExitThenApplyUpdate` (which prepares the updater and waits for this process to exit) and then exit the app yourself via `exit(0)`.
Compile your app to a program using your usual compiler (eg. msvc, cmake, gcc, etc) Make a note of the the output directory, as you will need it to package your app.