// AcHelper.cpp: implementation of the AcHelper class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "AcHelper.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

AcHelper::AcHelper()
{

}

AcHelper::~AcHelper()
{

}

BSTR AcHelper::AllocBString	(const char * c_string ,int len)
{
	if	(!len) return NULL;
BSTR		b_string = ::SysAllocStringLen(NULL ,len);
	if (b_string != NULL)
		MultiByteToWideChar	(CP_ACP ,0 ,c_string ,len ,b_string ,len);
	return b_string;
}

BSTR AcHelper::AllocBString	(const char * c_string)
{
int		a_len;
	if	(c_string)
		a_len = (int) strlen(c_string);
	else	a_len = 0;
BSTR		b_string = ::SysAllocStringLen(NULL ,a_len);
	if (b_string != NULL)
		MultiByteToWideChar	(CP_ACP ,0 ,c_string ,a_len ,b_string ,a_len);
	return b_string;
}

char * AcHelper::AllocCString (const BSTR b_string)
{
int		a_len;
	if	(b_string)
		a_len = ::SysStringLen(b_string)+1;
	else a_len = 1;
char * c_string = new char [a_len];
	if	(c_string) {
		if (!b_string) c_string[0] = 0;
		else WideCharToMultiByte(CP_ACP ,0 ,b_string ,a_len ,c_string ,a_len ,NULL ,NULL);
	}
	return c_string;
}