Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
MultiByteToWideChar を呼び出す Windows Phone ランタイム コンポーネント
#include "pch.h"
#include "WindowsPhoneRuntimeComponent1.h"
#define CP_SJIS 932
using namespace WindowsPhoneRuntimeComponent1;
using namespace Platform;
Platform::String^ WindowsPhoneRuntimeComponent::MultiByteToWideCharWP8(const Platform::Array<byte>^ buff)
{
LPCSTR pBuff = (LPCSTR)(buff->Data);
const int nSize = ::MultiByteToWideChar(CP_SJIS, 0, pBuff, -1, NULL, 0);
BYTE* buffUtf16 = new BYTE[nSize * 2 + 2];
::MultiByteToWideChar(CP_SJIS, 0, pBuff, -1, (LPWSTR)buffUtf16, nSize);
//return ref new Platform::String((LPWSTR)buffUtf16);
// ↑これではメモリリークしてしまいますね。
// ということで、修正↓ (2012/12/12)
Platform::String^ result = ref new Platform::String((LPWSTR)buffUtf16);
delete[] buffUtf16;
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment