Copy link to clipboard
Copied
I've wrapped your log system:
int log_info(const char *message) {
if (strlen(message) == 0) return EXIT_FAILURE;
#ifdef PLUGIN_MODE
if (sErrorSuitePtr == NULL) return EXIT_FAILURE;
sErrorSuitePtr->SetEventStringUnicode(PrSDKErrorSuite3::kEventTypeInformational,
reinterpret_cast<prUTF16Char*>((wchar_t*)(PROJECT_NAME)),
reinterpret_cast<prUTF16Char*>((wchar_t*)(message)));
#else
puts(message);
#endif
return EXIT_SUCCESS;
}
The C style cast is because `const_cast` failed with this error
C++ a const_cast can only adjust type qualifiers; it cannot change the underlying type
Output [first alert is `log_info("info successfully")`]:
Should I be using `SetErrorString` or something? - I'd prefer to use the Unicode ones in case I want to output the filename at some stage.
Have a look at copyConvertStringLiteralIntoUTF16(), in SDK_File.cpp. It may do what you want.
I ended up using`mbstowcs_s` doing:
#define WIDEN2(x) L ## x
#define WIDEN(x) WIDEN2(x)
static const std::wstring PROJECT_NAME_W(WIDEN(PROJECT_NAME));
#ifdef PLUGIN_MODE
static prUTF16Char* PROJECT_NAME_UTF16 = const_cast<prUTF16Char *>(PROJECT_NAME_W.c_str());
#endif
prUTF16Char * to_wchar(const char* message) {
const size_t cSize = strlen(message);
wchar_t *w_str = new wchar_t[cSize];
size_t outSize;
mbstowcs_s(&outSize, w_str, cSize, message, cSize-1);
return w_str;
}
int
...
Copy link to clipboard
Copied
Have a look at copyConvertStringLiteralIntoUTF16(), in SDK_File.cpp. It may do what you want.
Copy link to clipboard
Copied
I ended up using`mbstowcs_s` doing:
#define WIDEN2(x) L ## x
#define WIDEN(x) WIDEN2(x)
static const std::wstring PROJECT_NAME_W(WIDEN(PROJECT_NAME));
#ifdef PLUGIN_MODE
static prUTF16Char* PROJECT_NAME_UTF16 = const_cast<prUTF16Char *>(PROJECT_NAME_W.c_str());
#endif
prUTF16Char * to_wchar(const char* message) {
const size_t cSize = strlen(message);
wchar_t *w_str = new wchar_t[cSize];
size_t outSize;
mbstowcs_s(&outSize, w_str, cSize, message, cSize-1);
return w_str;
}
int log_info(const char *message) {
if (strlen(message) == 0) return EXIT_FAILURE;
#ifdef PLUGIN_MODE
if (sErrorSuitePtr == NULL) return EXIT_FAILURE;
fputs(message, stderr);
prUTF16Char *w_msg = to_wchar(message);
sErrorSuitePtr->SetEventStringUnicode(PrSDKErrorSuite3::kEventTypeInformational,
w_msg,
PROJECT_NAME_UTF16
);
free(w_msg);
#else
puts(message);
#endif
return EXIT_SUCCESS;
}
Find more inspiration, events, and resources on the new Adobe Community
Explore Now