C++CLIとNotes C APIの間でのマルチバイト文字の変換

Converting Multiple Byte Characters between C++/CLI and Notes C API

To manipulate the multiple byte characters like Japanese, Korean, Chinese with Notes C API, you will need to convert Native characters Code to LMBCS.

As per C++/CLI supports UNICODE as default, I recommend to use UNICODE for manipulating the String values on C++/CLI.

Translate from UNICODE (managed code) to LMBCS

Here I wrote how to convert UNICODE characters to LMBCS so that C API functions can understand them.

Step1. First of all, Marshal String to UNICODE String Pointer from Managed code. Marshal::StringToHGlobalUni() function  allocates the string data to global memory, so you will need to release the data after all.

String^ idfile = gcnew String(“ほげほげ.id”);
// Convert String to UNICODE String Pointer ( memo:StringToCoTaskMemAuto )
System::IntPtr ptrIdfile = System::Runtime::InteropServices::Marshal::StringToHGlobalUni( idfile );

Step2. Translate string from UNICODE to LMBCS format with OS_TRANSLATE_UNICODE_TO_LMBCS as 1st parameter of OSTranslate.

WORD    idfile_len = 2*(wcslen(static_cast<const wchar_t*>(ptrIdfile.ToPointer())));
char    idfile_lmbcs[MAXBUFFER+1];
OSTranslate(OS_TRANSLATE_UNICODE_TO_LMBCS, (char*)ptrIdfile.ToPointer(), idfile_len, idfile_lmbcs, MAXBUFFER );

Now you can pass LMBCS characters which is contained in idfile_lmbcs to Notes C API functions.

After using the string, don’t forget to free the pointer which is allocated by Marshal::StringToHGlobalUni().

System::Runtime::InteropServices::Marshal::FreeHGlobal( ptrIdfile );


› Translate from LMBCS to UNICODE (managed code)

For example, To get the multiple byte characters from notes documents, you also need to translate string from LMBCS to UNICODE. Below is the steps.

Step1. Get the value as Char format.

char item_value[MAXTEXTBUFFER+1];
// for example, calling NSFItemConvertValueToText() to get the Text from item value.
text_len = NSFItemConvertValueToText( item_type,
value_block,
item_len,
item_value,
buffer_len,
0);

Step2. Translate text string from LMBCS to UNICODE. In this case you need to use OS_TRANSLATE_LMBCS_TO_UNICODE as 1st parameter of OSTranslate().

char    item_value_lmbcs[MAXTEXTBUFFER+1];
OSTranslate(OS_TRANSLATE_LMBCS_TO_UNICODE, item_value, text_len, item_value_lmbcs, MAXTEXTBUFFER );

Step3.Get string as managed code by converting with following code.

String^ itemValue = System::Runtime::InteropServices::Marshal::PtrToStringUni( (IntPtr)item_value_lmbcs );

Tagged with: , , , ,

Blackberry Enterprise Server on Domino 8.0.2 stops delivering emails to handheld all of a sudden

Symptom : Users are not receiving emails to their blackberry handheld. After a reboot of the whole server including the OS, everything works as normal. After several hours have passed or sometimes days, users complained that they stopped receiving emails to their handheld again.

Rebooting the server every time a users complains was not the best solution and this has puzzled us for some time because all systems were working OK. Domino was running without any problem and test messages to user’s handheld from the Blackberry manager were successful. So we turned to blackberry support and they helped us right away. After sending Domino log as well as BES log, the support person came back in an email stating that this is a known issue (SDR201970) and a fix has already been posted in Maintenance Release 1.

The CPU spikes at about 99% when BES receives an email that contains rich text for certain mime types. If you have to wait for after hours or weekend to apply the MR, there is an option to disable “Rich Content” and “Inline Images” temporarily so to prevent the BES server from crashing. I believe this can be found in the BlackBerry Manager, under Server Properties, in the Messaging options.

Below is a sample of the log entry for Blackberry Enterprise Server :

[20148] (04/17 10:59:06.468):{0x1568} Thread: *** No Response *** Thread Id=0x1634, Handle=0x598, WaitCount=1, Last Activity: Received NEW MAIL for user John Doe/YOUR-DOMAIN

[20148] (04/17 11:09:08.562):{0x1568} Thread: *** No Response *** Thread Id=0x1634, Handle=0x598, WaitCount=2, Last Activity: Received NEW MAIL for user John Doe/YOUR-DOMAIN

[20148] (04/17 11:19:09.109):{0x1568} Thread: *** No Response *** Thread Id=0x1634, Handle=0x598, WaitCount=3, Last Activity: Received NEW MAIL for user John Doe/YOUR-DOMAIN

[20148] (04/17 11:29:09.390):{0x1568} Thread: *** No Response *** Thread Id=0x1634, Handle=0x598, WaitCount=4, Last Activity: Received NEW MAIL for user John Doe/YOUR-DOMAIN

[20148] (04/17 11:39:09.687):{0x1568} Thread: *** No Response *** Thread Id=0x1634, Handle=0x598, WaitCount=5, Last Activity: Received NEW MAIL for user John Doe/YOUR-DOMAIN

[20148] (04/17 11:49:09.968):{0x1568} Thread: *** No Response *** Thread Id=0x1624, Handle=0x55C, WaitCount=1, Last Activity: Received NEW MAIL for user John Doe/YOUR-DOMAIN

[20148] (04/17 11:49:09.968):{0x1568} Thread: *** No Response *** Thread Id=0x1634, Handle=0x598, WaitCount=6, Last Activity: Received NEW MAIL for user John Doe/YOUR-DOMAIN

YOUR_SERVER_MAGT_01_20090417_0001.txt(3855): [20149] (04/17 10:59:06.343):{0x1568} Thread 1634, utilization=99.7786%, failed health check 1 times

YOUR_SERVER_MAGT_01_20090417_0001.txt(4204): [20149] (04/17 11:09:08.562):{0x1568} Thread 1634, utilization=99.7866%, failed health check 2 times

YOUR_SERVER_MAGT_01_20090417_0001.txt(4339): [20149] (04/17 11:19:09.109):{0x1568} Thread 1634, utilization=99.5200%, failed health check 3 times

YOUR_SERVER_MAGT_01_20090417_0001.txt(4810): [20149] (04/17 11:29:09.390):{0x1568} Thread 1634, utilization=99.4300%, failed health check 4 times

Tagged with: , , , , ,
Top