Skip to content

Instantly share code, notes, and snippets.

@biac
Created December 8, 2012 08:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save biac/4239366 to your computer and use it in GitHub Desktop.
Save biac/4239366 to your computer and use it in GitHub Desktop.
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