| title | Creating a C++ notification addon for Electron |
|---|---|
| description | Learn how to create a C++ native addon that calls Windows App SDK notification APIs in your Electron app using the winapp CLI. |
| ms.date | 02/20/2026 |
| ms.topic | how-to |
This guide shows you how to create a C++ native addon that uses the Windows App SDK notification APIs in your Electron app. This is a great starting point for understanding native addons before diving into more complex scenarios.
- Completed the development environment setup
- Windows 11
Use the winapp CLI to generate a C++ addon template:
npx winapp node create-addon --template cpp --name nativeWindowsAddonThis creates a nativeWindowsAddon/ folder with:
addon.cc- Your C++ code that will call Windows APIsbinding.gyp- Build configuration for native compilation
The command also adds a build-addon script to your package.json.
Build the addon:
npm run build-addonOpen nativeWindowsAddon/addon.cc and update it to use the Windows App SDK notification APIs. The generated template includes the necessary Windows SDK and Windows App SDK headers.
Add includes for the notification API:
#include <winrt/Microsoft.Windows.AppNotifications.h>
#include <winrt/Microsoft.Windows.AppNotifications.Builder.h>Add a function that shows a Windows notification:
Napi::Value ShowNotification(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
try {
std::string title = info[0].As<Napi::String>().Utf8Value();
std::string message = info[1].As<Napi::String>().Utf8Value();
winrt::Microsoft::Windows::AppNotifications::Builder::AppNotificationBuilder builder;
builder.AddText(winrt::to_hstring(title));
builder.AddText(winrt::to_hstring(message));
auto notification = builder.BuildNotification();
winrt::Microsoft::Windows::AppNotifications::AppNotificationManager::Default().Show(notification);
return Napi::Boolean::New(env, true);
} catch (const winrt::hresult_error& e) {
Napi::Error::New(env, winrt::to_string(e.message())).ThrowAsJavaScriptException();
return env.Null();
}
}Register the function in the Init method:
exports.Set("showNotification", Napi::Function::New(env, ShowNotification));npm run build-addonOpen src/index.js and load the addon:
const addon = require('../nativeWindowsAddon/build/Release/nativeWindowsAddon.node');Add a test call:
addon.showNotification('Hello from Electron!', 'This notification uses the Windows App SDK.');Run the app:
npm startYou should see a Windows notification appear.
Whenever you modify appxmanifest.xml, run:
npx winapp node add-electron-debug-identity- Creating a Phi Silica addon - Use on-device AI APIs
- Creating a WinML addon - Run machine learning models
- Packaging for distribution - Create a signed MSIX package