﻿<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Computer Architechs International Corporation &#187; LMBCS</title>
	<atom:link href="http://www.caicorp.com/archives/tag/lmbcs/feed" rel="self" type="application/rss+xml" />
	<link>http://www.caicorp.com</link>
	<description>Premier IT Administrators and Developers of Los Angeles, Orange County and Beyond</description>
	<lastBuildDate>Fri, 03 Feb 2012 00:33:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Converting Multiple Byte Characters between C++/CLI and Notes C API</title>
		<link>http://www.caicorp.com/archives/328</link>
		<comments>http://www.caicorp.com/archives/328#comments</comments>
		<pubDate>Tue, 05 May 2009 17:48:35 +0000</pubDate>
		<dc:creator>ktatsuki</dc:creator>
				<category><![CDATA[Lotus Notes]]></category>
		<category><![CDATA[Notes C API]]></category>
		<category><![CDATA[C++/CLI]]></category>
		<category><![CDATA[CJK]]></category>
		<category><![CDATA[LMBCS]]></category>

		<guid isPermaLink="false">http://www.caicorp.com/?p=328</guid>
		<description><![CDATA[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 [...] [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.caicorp.com%2Farchives%2F328"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.caicorp.com%2Farchives%2F328&amp;source=caicorp&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>To manipulate the multiple byte characters like Japanese, Korean, Chinese with Notes C API, you will need to convert Native characters Code to LMBCS.</p>
<p>As per C++/CLI supports UNICODE as default, I recommend to use UNICODE for manipulating the String values on C++/CLI.</p>
<p>› <strong>Translate from UNICODE (managed code) to LMBCS</strong></p>
<p>Here I wrote how to convert UNICODE characters to LMBCS so that C API functions can understand them.</p>
<p>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.</p>
<blockquote><p>String^ idfile = gcnew String(&#8220;ほげほげ.id&#8221;);<br />
// Convert String to UNICODE String Pointer ( memo:StringToCoTaskMemAuto )<br />
System::IntPtr ptrIdfile = System::Runtime::InteropServices::Marshal::StringToHGlobalUni( idfile );</p></blockquote>
<p>Step2. Translate string from UNICODE to LMBCS format with <strong>OS_TRANSLATE_UNICODE_TO_LMBCS </strong>as 1st parameter of OSTranslate.</p>
<blockquote><p>WORD    idfile_len = 2*(wcslen(static_cast&lt;const wchar_t*&gt;(ptrIdfile.ToPointer())));<br />
char    idfile_lmbcs[MAXBUFFER+1];<br />
OSTranslate(OS_TRANSLATE_UNICODE_TO_LMBCS, (char*)ptrIdfile.ToPointer(), idfile_len, idfile_lmbcs, MAXBUFFER );</p></blockquote>
<p>Now you can pass LMBCS characters which is contained in idfile_lmbcs to Notes C API functions.</p>
<p>After using the string, don&#8217;t forget to free the pointer which is allocated by Marshal::StringToHGlobalUni().</p>
<blockquote><p>System::Runtime::InteropServices::Marshal::FreeHGlobal( ptrIdfile );</p></blockquote>
<hr /><strong>› Translate from LMBCS to UNICODE (managed code) </strong></p>
<p>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.</p>
<p>Step1. Get the value as Char format.</p>
<blockquote><p>char item_value[MAXTEXTBUFFER+1];<br />
// for example, calling NSFItemConvertValueToText() to get the Text from item value.<br />
text_len = NSFItemConvertValueToText( item_type,<br />
value_block,<br />
item_len,<br />
item_value,<br />
buffer_len,<br />
0);</p></blockquote>
<p>Step2. Translate text string from LMBCS to UNICODE. In this case you need to use <strong>OS_TRANSLATE_LMBCS_TO_UNICODE</strong> as 1st parameter of OSTranslate().</p>
<blockquote><p>char    item_value_lmbcs[MAXTEXTBUFFER+1];<br />
OSTranslate(OS_TRANSLATE_LMBCS_TO_UNICODE, item_value, text_len, item_value_lmbcs, MAXTEXTBUFFER );</p></blockquote>
<p>Step3.Get string as managed code by converting with following code.</p>
<blockquote><p>String^ itemValue = System::Runtime::InteropServices::Marshal::PtrToStringUni( (IntPtr)item_value_lmbcs );</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.caicorp.com/archives/328/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

