Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

[C++] Chinese characters in SetEventStringUnicode (wanted English)

Community Beginner ,
May 24, 2021 May 24, 2021

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")`]:

jap.PNG

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.

TOPICS
SDK
592
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

Adobe Employee , May 24, 2021 May 24, 2021

Have a look at copyConvertStringLiteralIntoUTF16(), in SDK_File.cpp. It may do what you want.

Translate
Community Beginner , May 30, 2021 May 30, 2021

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
...
Translate
Adobe Employee ,
May 24, 2021 May 24, 2021

Have a look at copyConvertStringLiteralIntoUTF16(), in SDK_File.cpp. It may do what you want.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 30, 2021 May 30, 2021
LATEST

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;
}

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines