The provided JSON data works the same as with SendWebMessage()
, and is used as the value that the JavaScript call to _sendWrapperExtensionMessageAsync()
resolves with.
Suggested architecture
It is recommended that as much of your plugin logic as possible is implemented in JavaScript. Only send messages to the wrapper extension to make specific API calls that aren't possible from JavaScript. This way it minimizes the amount of platform-specific C++ code necessary, and ensures as much logic as possible happens in the same place, rather than spread across two codebases. Also, JavaScript is an easier programming language to work with, as it has easier-to-use facilities for async code and avoids the need for manual memory management (while still providing excellent performance).
Strings on Windows
For historical reasons, Windows APIs called from C++ that use strings generally use "wide strings" with UTF-16 encoding. These are strings of "wide characters" which are 16-bit types on Windows. This uses the wchar_t
type for a character, and std::wstring
for the STL string equivalent (as well as types like LPCWSTR
for the C-style equivalent in Windows header files).
On the other hand, most modern software and recent C++ codebases use UTF-8 encoding. This uses the standard 8-bit char
type and std::string
in the STL (as well as types like char*
for the C-style equivalent).
Consistent with the modern style, the wrapper extension SDK uses UTF-8 encoding when dealing with strings. However this means strings must be converted when calling Windows APIs that use wide strings. The SDK provides the utility methods Utf8ToWide()
which converts a UTF-8 std::string
to a UTF-16 std::wstring
suitable for passing to Windows APIs. The c_str()
method of STL strings also provides a C-style string that Windows usually expects. The WideToUtf8()
method can then also convert a UTF-16 std::wstring
back to a UTF-8 std::string
, suitable for converting back wide strings returned by Windows APIs. The recommended approach is to use UTF-8 everywhere, and only convert to UTF-16 to call a Windows API that requires it; if the API call returns a UTF-16 string then it should immediately be converted back to UTF-8. This means as much code as possible only uses UTF-8 and UTF-16 is used minimally solely to interact with Windows APIs.
Platform-specific code
You can use the following preprocessor definitions to identify the platform being built and so incorporate platform-specific code. Note these definitions only identify the OS, not the architecture.
_WIN32
is defined by Visual Studio for Windows builds
__linux__
is defined by gcc for Linux builds
Additional examples
There are real-world examples of using the wrapper extension SDK to integrate SDKs on the Scirra GitHub account, including open-source plugins that integrate the Steamworks SDK and the Epic Games Online Services (EOS) SDK. These should help provide sample code that demonstrates how to build a useful wrapper extension.