#include "stdafx.h"
#include "PublicObj.h"


CPublicObj::CPublicObj()
{
}


CPublicObj::~CPublicObj()
{
}
void CPublicObj::Unicode2Ansi(std::wstring _in, std::string& _out)
{
	int nAnsiLen = WideCharToMultiByte(CP_ACP,
		0,
		_in.c_str(),
		-1,
		NULL,
		0,
		NULL,
		NULL);

	char *pAnsi = new char[nAnsiLen + 1];
	memset((void*)pAnsi, 0, (nAnsiLen + 1) * sizeof(char));

	::WideCharToMultiByte(CP_ACP,
		0,
		_in.c_str(),
		-1,
		pAnsi,
		nAnsiLen,
		NULL,
		NULL);
	_out = pAnsi;
	delete[]pAnsi;
}
void CPublicObj::Ansi2Unicode(std::string _in, std::wstring& _out)
{
	//获取转换所需的接收缓冲区大小
	int  nUnicodeLen = ::MultiByteToWideChar(CP_ACP,
		0,
		_in.c_str(),
		-1,
		NULL,
		0);
	//分配指定大小的内存
	wchar_t* pUnicode = new wchar_t[nUnicodeLen + 1];
	memset((void*)pUnicode, 0, (nUnicodeLen + 1) * sizeof(wchar_t));

	//转换
	::MultiByteToWideChar(CP_ACP,
		0,
		_in.c_str(),
		-1,
		(LPWSTR)pUnicode,
		nUnicodeLen);

	 
	_out = (wchar_t*)pUnicode;
	delete[]pUnicode;

}