Exemple #1
0
//---------------------------------------------------------------------
// [概要]
//   VBの日付を"yyyy/mm/dd" "hh:nn:ss"二つの文字列で返す。
// [引数]
//   vbDate	日付型(Date型)の日付
// [戻り値]
//   0:		正常終了
//   -1:	異常終了(変換失敗)
// [機能説明]
//   文字列型(String)を書き換える例
//   VBでの定義
//   Declare Function VbDate2String2(ByVal vbDate As Date,
//     ByVal strYMD As String, ByVal strHMS As String) As Long
//---------------------------------------------------------------------
__declspec(dllexport) long __stdcall VbDate2String2(DATE vbDate, BSTR* ymd, BSTR* hms)
{
	UDATE udate;
	u_long dwFlags = 0;

	memset(&udate, 0, sizeof(udate));

	// VBの日付型(Date)をUDATE構造体に変換する
	HRESULT hres = VarUdateFromDate(vbDate, dwFlags, &udate);
	if (hres != S_OK) {
		return -1;
	}

	// SysReSysAllocString(temp);でいけそうな気がするが、
	// SysAllocString, SysAllocStringLen, SysReAllocString, SysReAllocStringLen
	// 上記4つの関数は、VBに制御がわたったとき、正常に処理できない。
	// おそらく、文字コードの自動変換(Unicode->Ascii->Unicode)の関係でよろしくないと
	// 思われり。唯一正常に動くSysAllocStringByteLenを使用するため、
	// SysFreeString()してからSysAllocStringByteLen()で再確保する

	char temp[64];
	int len = wsprintf(temp, "%04d/%02d/%02d",
		udate.st.wYear, udate.st.wMonth, udate.st.wDay);
	SysFreeString(*ymd);
	*ymd = SysAllocStringByteLen(temp, len);

	len = wsprintf(temp, "%02d:%02d:%02d",
		udate.st.wHour, udate.st.wMinute, udate.st.wSecond);
	SysFreeString(*hms);
	*hms = SysAllocStringByteLen(temp, len);

	return 0;
}
STDMETHODIMP CClassCommon::get_PublicKeySIGN(BSTR* pVal)
{
	// TODO: 在此添加实现代码

	long pb64_len = modp_b64_encode_len(SM2_BYTES_LEN * 2);

	char * pb64_data = (char *)malloc(pb64_len);

	pb64_len = modp_b64_encode(pb64_data, (char *)m_szPublicKeySIGN,SM2_BYTES_LEN * 2);

	::FILE_LOG_STRING(file_log_name, "get_PublicKeySIGN");
	::FILE_LOG_STRING(file_log_name, "modp_b64_encode");
	::FILE_LOG_NUMBER(file_log_name, pb64_len);
	::FILE_LOG_STRING(file_log_name, pb64_data);

	//long lLen = MultiByteToWideChar(CP_ACP,0,(LPCSTR)pb64_data,pb64_len,(LPWSTR)pVal,pb64_len * 2);
	BSTR wc_data = SysAllocStringByteLen(NULL, pb64_len * 2); 

	MultiByteToWideChar(CP_ACP,0,(LPCSTR)pb64_data,pb64_len,(LPWSTR)wc_data,pb64_len);

	*pVal = wc_data; // 设置返回值指针。注:不释放内存 

	free(pb64_data);

	return S_OK;
}
/* ======================================================================== */
HRESULT ConvertBStrToAnsiStr(BSTR bstrIn, LPSTR * lpszOut)
{
    DWORD dwSize;

    if (lpszOut == NULL) return E_INVALIDARG;
    if (bstrIn == NULL) {
        *lpszOut = NULL;
        return NOERROR;
    }

    /* Get the number of characters needed to convert bStrIn */
    dwSize = WideCharToMultiByte(CP_ACP, 0, bstrIn, -1, NULL, 0, NULL, NULL);
    if (dwSize == 0) return HRESULT_FROM_WIN32( GetLastError() );

    /* Allocate memory of the required length */
    *lpszOut = (LPSTR) SysAllocStringByteLen(NULL, dwSize - 1);
    if (*lpszOut == NULL) return E_OUTOFMEMORY;

    /* Convert bstrIn into the memory we allocated */
    if ( !WideCharToMultiByte(CP_ACP, 0, bstrIn, -1, *lpszOut, dwSize, NULL, NULL) )
    {
        SysFreeString((BSTR) *lpszOut);
        return HRESULT_FROM_WIN32( GetLastError() );
    }

    return NOERROR;
}
Exemple #4
0
CMarkdown::HSTR CMarkdown::GetTagText()
{
	const char *p = first, *q = first;
	if (q < ahead && (p = ++q) < ahead && (*q != '!' || ++q < ahead))
	{
		if (*q == '-' || *q == '[')
		{
			++q;
		}
		else
		{
			unsigned quoting = 0;
			while (q < ahead && (quoting || (*q != '[' && *q != '<' && *q != '>' && *q != '/')))
			{
				switch (*q)
				{
				case '"':
					if (!(quoting & 1))
						quoting ^= 2;
					break;
				case '\'': 
					if (!(quoting & 2))
						quoting ^= 1;
					break;
				}
				++q;
			}
		}
	}
	return (HSTR)SysAllocStringByteLen(p, q - p);
}
Exemple #5
0
BSTR TP_SysAllocStringByteLen(LPCSTR psz, size_t len)
{
#ifdef WINDOWS    
    return SysAllocStringByteLen(psz, (UINT)len);
#else
    BSTR bstr;
    ULONG cbTotal = 0;

    if (FAILED(CbSysStringSize(len, TRUE, &cbTotal)))
        return NULL;

    bstr = (BSTR)TP_CoTaskMemAlloc(cbTotal);

    if (bstr != NULL) {
#if defined(_WIN64)
      *(DWORD *)((char *)bstr + sizeof (DWORD)) = (DWORD)len;
#else
      *(DWORD *)bstr = (DWORD)len;
#endif

      bstr = (WCHAR*) ((char*) bstr + sizeof(DWORD_PTR));

      if (psz != NULL) {
            memcpy(bstr, psz, len);
      }

      // NULL-terminate with both a narrow and wide zero.
      *((char *)bstr + len) = '\0';
      *(WCHAR *)((char *)bstr + ((len + 1) & ~1)) = 0;
    }

    return bstr;
#endif    
}
Exemple #6
0
BOOL
ceConvertWszToBstr(
    OUT BSTR *pbstr,
    IN WCHAR const *pwc,
    IN LONG cb)
{
    BOOL fOk = FALSE;
    BSTR bstr;

    ceFreeBstr(pbstr);
    do
    {
	bstr = NULL;
	if (NULL != pwc)
	{
	    if (-1 == cb)
	    {
		cb = wcslen(pwc) * sizeof(WCHAR);
	    }
	    bstr = SysAllocStringByteLen((char const *) pwc, cb);
	    if (NULL == bstr)
	    {
		break;
	    }
	}
	*pbstr = bstr;
	fOk = TRUE;
    } while (FALSE);
    return(fOk);
}
	CComBSTR BSTRFromUTF8(const std::string& utf8)
	{
		if (utf8.empty())
			return CComBSTR();

		// Fail if an invalid input character is encountered
		const DWORD conversionFlags = MB_ERR_INVALID_CHARS;

		const int utf16Length = ::MultiByteToWideChar(CP_UTF8, conversionFlags, utf8.data(), utf8.length(), NULL, 0);
		if (utf16Length == 0)
		{
			DWORD error = ::GetLastError();

			throw udm_exception(
				(error == ERROR_NO_UNICODE_TRANSLATION) ? 
					"Invalid UTF-8 sequence found in input string." :
					"Can't get length of UTF-16 string (MultiByteToWideChar failed).");
		}

		BSTR utf16 = SysAllocStringByteLen(NULL, utf16Length*2);
		if (utf16 == NULL)
			throw std::bad_alloc();

		if (!::MultiByteToWideChar(CP_UTF8, 0, utf8.data(), utf8.length(), utf16, utf16Length))
		{
			DWORD error = ::GetLastError();
			SysFreeString(utf16);
			throw udm_exception("Can't convert string from UTF-8 to UTF-16 (MultiByteToWideChar failed).");
		}

		CComBSTR ret;
		ret.m_str = utf16;
		return ret;
	}
Exemple #8
0
STDMETHODIMP CID3Field::get_Binary(BSTR *pVal)
{
	// TODO: Add your implementation code here
	if (pVal == NULL)
		return E_POINTER;
	try
	{
		*pVal = NULL;
		const uchar *pData = m_Field->GetRawBinary();
		if (pData == NULL)
			return E_FAIL;
		ID3_Frame *pFrame = ((CID3Frame*)m_FrameParent)->GetID3Frame();		
		if (pFrame->GetID() == ID3FID_PICTURE)
		{
			*pVal = _bstr_t((LPCTSTR)pData).copy();			
		}
		else
		{
			*pVal = SysAllocStringByteLen((const char *)pData,m_Field->Size());
		}
	}
	catch (...)
	{
		return Error(IDS_UNEXPECTED_ERROR, IID_IID3ComField, E_UNEXPECTED);
	}
	return S_OK;
}
Exemple #9
0
STDMETHODIMP CXMLHttpRequest::get_responseText(BSTR *pVal)
{
	ATLTRACE(_T("CXMLHttpRequest::get_responseText\n"));

	if (NULL == pVal)
		return E_POINTER;

	*pVal = NULL;

	// check if there is a send active 
	if (NULL != m_hThread) {
		DWORD exitCode = 0;
		BOOL rc = ::GetExitCodeThread(m_hThread, &exitCode);
		if (!rc || STILL_ACTIVE == exitCode) 
			return E_PENDING;
		
		::CloseHandle(m_hThread);
		m_hThread = NULL;
	}

	if (NULL == m_pResponseBody)
		return S_OK;

	TCHAR *psz = new TCHAR[m_lResponseBodyLength+1];
	ZeroMemory(psz,m_lResponseBodyLength+1);
	CopyMemory(psz,m_pResponseBody,m_lResponseBodyLength);
  	
	*pVal =  SysAllocStringByteLen(psz,m_lResponseBodyLength); 
	delete [] psz;
 
	return S_OK;
}
Exemple #10
0
//---------------------------------------------------------------------
// [概要]
//   VBの日付を"yyyy/mm/dd hh:nn:ss"文字列で返す
// [引数]
//   vbDate	日付型(Date型)の日付
// [戻り値]
//   文字列型(String型)に変換した日付
// [機能説明]
//   文字列型(String)を戻す関数の例
//   VBでの定義
//     Declare Function VbDate2String(ByVal vbDate As Date) As String
//---------------------------------------------------------------------
__declspec(dllexport) BSTR __stdcall VbDate2String(DATE vbDate)
{
	UDATE udate;
	u_long dwFlags = 0;

	memset(&udate, 0, sizeof(udate));

	// VBの日付型(Date)をUDATE構造体に変換する
	HRESULT hres = VarUdateFromDate(vbDate, dwFlags, &udate);
	if (hres != S_OK) {
		return NULL;
	}

	char temp[64];
	int len = wsprintf(temp, "%04d/%02d/%02d %02d:%02d:%02d",
		udate.st.wYear, udate.st.wMonth, udate.st.wDay,
		udate.st.wHour, udate.st.wMinute, udate.st.wSecond);

	// return SysAllocString(temp);でいけそうな気がするが、
	// SysAllocString, SysAllocStringLen, SysReAllocString, SysReAllocStringLen
	// 上記4つの関数は、VBに制御がわたったとき、正常に処理できない。
	// おそらく、文字コードの自動変換(Unicode->Ascii->Unicode)の関係でよろしくないと
	// 思われり。唯一正常に動くSysAllocStringByteLenを使用。

	return SysAllocStringByteLen(temp, len);
}
Exemple #11
0
// this function creates a BSTR but it actually has an ANSI string inside
BSTR AFXAPI AfxBSTR2ABSTR(BSTR bstrW)
{
	int nLen = SysStringLen(bstrW); //not including NULL
	int nBytes = WideCharToMultiByte(CP_ACP, 0, bstrW, nLen,
		NULL, NULL, NULL, NULL); //number of bytes not including NULL
	BSTR bstrA = SysAllocStringByteLen(NULL, nBytes); // allocates nBytes
	VERIFY(WideCharToMultiByte(CP_ACP, 0, bstrW, nLen, (LPSTR)bstrA, nBytes, NULL,
		NULL) == nBytes);
	return bstrA;
}
Exemple #12
0
void CUUEngine::NewStep()
{

	BSTR wrk = SysAllocStringByteLen("", 0);			// Create an empty system string
	BOOL cflag = FALSE;

	Fire_Progress(UUACT_NEWSTEP, wrk, 0, 0, 0, 0, &cflag);

	SysFreeString(wrk);

}
Exemple #13
0
static inline BSTR QStringToBSTR(const QString &str)
{
    BSTR bstrVal;

    int wlen = str.length()+1;
    bstrVal = SysAllocStringByteLen(0, wlen*2);
    memcpy(bstrVal, str.unicode(), sizeof(QChar)*(wlen));
    bstrVal[wlen] = 0;

    return bstrVal;
}
Exemple #14
0
CMarkdown::HSTR CMarkdown::_HSTR::Convert(const Converter &converter)
{
	HSTR H = this;
	size_t s = SysStringByteLen(B);
	if (size_t d = converter.Convert(A, s, 0, 0))
	{
		H = (HSTR)SysAllocStringByteLen(0, d);
		converter.Convert(A, s, H->A, d);
		SysFreeString(B);
	}
	return H;
}
Exemple #15
0
ErrStringCopy(BSTR bstrSrc, BSTR FAR * pbstrOut)
{
    BSTR bstrNew;

    if((bstrNew = SysAllocStringByteLen((char FAR *)bstrSrc,
					SysStringByteLen(bstrSrc))) == NULL)
      return RESULT(E_OUTOFMEMORY);

    *pbstrOut = bstrNew;

    return NOERROR;
}
Exemple #16
0
static HRESULT WINAPI httprequest_get_responseText(IXMLHTTPRequest *iface, BSTR *body)
{
    httprequest *This = impl_from_IXMLHTTPRequest( iface );
    HGLOBAL hglobal;
    HRESULT hr;

    TRACE("(%p)->(%p)\n", This, body);

    if (!body) return E_INVALIDARG;
    if (This->state != READYSTATE_COMPLETE) return E_FAIL;

    hr = GetHGlobalFromStream(This->bsc->stream, &hglobal);
    if (hr == S_OK)
    {
        xmlChar *ptr = GlobalLock(hglobal);
        DWORD size = GlobalSize(hglobal);
        xmlCharEncoding encoding = XML_CHAR_ENCODING_UTF8;

        /* try to determine data encoding */
        if (size >= 4)
        {
            encoding = xmlDetectCharEncoding(ptr, 4);
            TRACE("detected encoding: %s\n", debugstr_a(xmlGetCharEncodingName(encoding)));
            if ( encoding != XML_CHAR_ENCODING_UTF8 &&
                 encoding != XML_CHAR_ENCODING_UTF16LE &&
                 encoding != XML_CHAR_ENCODING_NONE )
            {
                FIXME("unsupported encoding: %s\n", debugstr_a(xmlGetCharEncodingName(encoding)));
                GlobalUnlock(hglobal);
                return E_FAIL;
            }
        }

        /* without BOM assume UTF-8 */
        if (encoding == XML_CHAR_ENCODING_UTF8 ||
            encoding == XML_CHAR_ENCODING_NONE )
        {
            DWORD length = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)ptr, size, NULL, 0);

            *body = SysAllocStringLen(NULL, length);
            if (*body)
                MultiByteToWideChar( CP_UTF8, 0, (LPCSTR)ptr, size, *body, length);
        }
        else
            *body = SysAllocStringByteLen((LPCSTR)ptr, size);

        if (!*body) hr = E_OUTOFMEMORY;
        GlobalUnlock(hglobal);
    }

    return hr;
}
Exemple #17
0
CMarkdown::HSTR CMarkdown::_HSTR::Octets(UINT codepage)
{
	HSTR H = this;
	if (codepage != 1200) // 1200 means 'no conversion'
	{
		int w = SysStringLen(B);
		int a = WideCharToMultiByte(codepage, 0, W, w, 0, 0, 0, 0);
		H = (HSTR)SysAllocStringByteLen(0, a);
		WideCharToMultiByte(codepage, 0, W, w, H->A, a, 0, 0);
		SysFreeString(B);
	}
	return H;
}
Exemple #18
0
CMarkdown::HSTR CMarkdown::GetOuterText()
{
	Scan();
	const char *q = upper;
	if (q > first)
	{
		while (q[-1] != '>' && q <= ahead)
		{
			++q;
		}
	}
	return (HSTR)SysAllocStringByteLen(lower, q - first);
}
Exemple #19
0
DWORD CbBSTR::SetCharString(char *str)
{
	Release();
	//if (str[0] == 0) return NULL;
	int	i;
	int	len = strlen(str);
	m_bstr = SysAllocStringByteLen(NULL,(len)*2); if (m_bstr == NULL) return SetError_Add_W32_code_msg(true,ERR_API,GetLastError(),"CbBSTR::SetCharString ... SysAllocStringByteLen ");
	m_bstr_size = len;
	i = MultiByteToWideChar(CP_ACP,0,str,len,m_bstr,len);
	if (i == len) return ERR_OK;
	Release();
	return SetError_Add_W32_code_msg(true,ERR_API,GetLastError(),"CbBSTR::SetCharString ... MultiByteToWideChar ");
}
Exemple #20
0
HRESULT VariantCopy(VARIANTARG *dest, VARIANTARG *src)
{
  HRESULT res = ::VariantClear(dest);
  if (res != S_OK)
    return res;
  if (src->vt == VT_BSTR)
  {
    dest->bstrVal = SysAllocStringByteLen((LPCSTR)src->bstrVal, 
        SysStringByteLen(src->bstrVal));
    if (dest->bstrVal == 0)
      return E_OUTOFMEMORY;
    dest->vt = VT_BSTR;
  }
  else
    *dest = *src;
  return S_OK;
}
Exemple #21
0
BSTR primQueryPathOfRegTypeLib ( GUID* rguid
			       , unsigned short maj
			       , unsigned short min
			       )
{
  BSTR bs;
  HRESULT hr;
  bs = SysAllocStringByteLen (NULL, 255);
  
  hr = QueryPathOfRegTypeLib ( rguid, maj, min, GetUserDefaultLCID(), &bs);
  
  if (FAILED(hr)) {
     SysFreeString(bs);
     return NULL;
  }
  return bs;
}
Exemple #22
0
/************************************************************************
 *		BstrFromVector (OLEAUT32.@)
 *
 * Create a BSTR from a SafeArray.
 *
 * PARAMS
 *  psa   [I] Source array
 *  pbstr [O] Destination for output BSTR
 *
 * RETURNS
 *  Success: S_OK. pbstr contains the arrays data.
 *  Failure: An HRESULT error code indicating the error.
 *
 * NOTES
 *  psa must be a 1 dimensional array of a 1 byte type.
 *
 * NOTES
 * See SafeArray.
 */
HRESULT WINAPI BstrFromVector(SAFEARRAY *psa, BSTR *pbstr)
{
  TRACE("(%p,%p)\n", psa, pbstr);

  if (!pbstr)
    return E_INVALIDARG;

  *pbstr = NULL;

  if (!psa || psa->cbElements != 1 || psa->cDims != 1)
    return E_INVALIDARG;

  *pbstr = SysAllocStringByteLen(psa->pvData, psa->rgsabound[0].cElements);
  if (!*pbstr)
    return E_OUTOFMEMORY;
  return S_OK;
}
Exemple #23
0
HRESULT BstrStream::ReadBstr(BSTR *bstr)
{
    *bstr = SysAllocStringByteLen(NULL, avail());
    UINT nlen = SysStringByteLen(*bstr);

    ULONG read = 0, pos = 0, cb = nlen;
    HRESULT hr;

    LPBYTE pbuf = (LPBYTE)*bstr;
    for ( ; pos < nlen; cb -= read, pos += read) {
        hr = Read(&pbuf[pos], cb, &read);
        if (FAILED(hr)) {
            SysFreeString(*bstr);
            return hr;
        }
        if (read == 0) break;
    }

    return S_OK;
}
Exemple #24
0
CMarkdown::HSTR CMarkdown::GetTagName()
{
	const char *p = first;
	const char *q = first;
	unsigned char c;
	if (q < ahead && (p = ++q) < ahead)
	{
		if (*q == '!' && (*++q == '-' || *q == '['))
		{
			++q;
		}
		else
		{
			while (q < ahead && !isspace(c = *q) && c != '[' && c != '>' && c != '"' && c != '\'' && c != '=' && c != '/')
			{
				++q;
			}
		}
	}
	return (HSTR)SysAllocStringByteLen(p, q - p);
}
Exemple #25
0
HRESULT ConvertBStrToAnsiStr(BSTR bstrIn, LPSTR * lpszOut)
{
	DWORD dwSize;

	if (lpszOut == NULL) return E_INVALIDARG;
	if (bstrIn == NULL) { *lpszOut = NULL; return NOERROR; }

	dwSize = WideCharToMultiByte(CP_ACP, 0, bstrIn, -1, NULL, 0, NULL, NULL);
	if (dwSize == 0) return HRESULT_FROM_WIN32( GetLastError() );

	*lpszOut = (LPSTR) SysAllocStringByteLen(NULL, dwSize - 1);
	if (*lpszOut == NULL) return E_OUTOFMEMORY;

	if ( !WideCharToMultiByte(CP_ACP, 0, bstrIn, -1, *lpszOut, dwSize, NULL, NULL) )
	{
		SysFreeString((BSTR) *lpszOut);
		return HRESULT_FROM_WIN32( GetLastError() );
	}

	return NOERROR;
}
Exemple #26
0
unsigned char * WINAPI BSTR_UserUnmarshal(unsigned long *pFlags, unsigned char *Buffer, BSTR *pstr)
{
    bstr_wire_t *header;
    TRACE("(%lx,%p,%p) => %p\n", *pFlags, Buffer, pstr, *pstr);

    ALIGN_POINTER(Buffer, 3);
    header = (bstr_wire_t*)Buffer;
    if(header->len != header->len2)
        FIXME("len %08lx != len2 %08lx\n", header->len, header->len2);
    
    if(*pstr)
    {
        SysFreeString(*pstr);
        *pstr = NULL;
    }

    if(header->byte_len != 0xffffffff)
        *pstr = SysAllocStringByteLen((char*)(header + 1), header->byte_len);

    if (*pstr) TRACE("string=%s\n", debugstr_w(*pstr));
    return Buffer + sizeof(*header) + sizeof(OLECHAR) * header->len;
}
Exemple #27
0
DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_TxGetText(ITextServices *iface, BSTR *pbstrText)
{
   ITextServicesImpl *This = impl_from_ITextServices(iface);
   int length;

   length = ME_GetTextLength(This->editor);
   if (length)
   {
      ME_Cursor start;
      BSTR bstr;
      bstr = SysAllocStringByteLen(NULL, length * sizeof(WCHAR));
      if (bstr == NULL)
         return E_OUTOFMEMORY;

      ME_CursorFromCharOfs(This->editor, 0, &start);
      ME_GetTextW(This->editor, bstr, length, &start, INT_MAX, FALSE, FALSE);
      *pbstrText = bstr;
   } else {
      *pbstrText = NULL;
   }

   return S_OK;
}
Exemple #28
0
// this function creates a BSTR but it actually has an ANSI string inside
BSTR AFXAPI AfxBSTR2ABSTR(BSTR bstrW)
{
#pragma warning(push)
#pragma warning(disable:4068)
#pragma prefast(push)
#pragma prefast(disable:325, "We want to duplicate NULL semantics on the way out of this function")
	if (bstrW == NULL)
		return NULL;
#pragma prefast(pop)
#pragma warning(pop)

	int nLen = SysStringLen(bstrW); //not including NULL
	int nBytes = WideCharToMultiByte(CP_ACP, 0, bstrW, nLen,
		NULL, NULL, NULL, NULL); //number of bytes not including NULL
	BSTR bstrA = SysAllocStringByteLen(NULL, nBytes); // allocates nBytes
	if(!bstrA)
	{
		AfxThrowMemoryException();
	}
	VERIFY(WideCharToMultiByte(CP_ACP, 0, bstrW, nLen, (LPSTR)bstrA, nBytes, NULL,
		NULL) == nBytes);
	return bstrA;
}
Exemple #29
0
CMarkdown::HSTR CMarkdown::GetInnerText()
{
	Scan();
	const char *p = first;
	const char *q = upper;
	char bracket = '>';
	if (p < upper && ++p < upper && *p == '!' && ++p < upper)
	{
		bracket = *p;
		if (bracket != '-')
		{
			bracket = '[';
		}
	}
	p = lower;
	unsigned quoting = 0;
	while (p < upper && (quoting || *p != bracket))
	{
		switch (*p)
		{
		case '"':
			if (!(quoting & 1))
				quoting ^= 2;
			break;
		case '\'': 
			if (!(quoting & 2))
				quoting ^= 1;
			break;
		}
		++p;
	}
	if (p < q && p < --q && p < --q)
	{
		++p;
	}
	return (HSTR)SysAllocStringByteLen(p, q - p);
}
STDMETHODIMP CClassCommon::get_sm2keys(BSTR* pVal)
{
	// TODO: 在此添加实现代码
	long keys_len;
	char * keys_value = NULL;

	long pb64_len;
	char * pb64_data = NULL;

	keys_len = sizeof(OPST_PCI_ECCrefPublicKey) + sizeof(OPST_PCI_ECCrefPrivateKey);
	keys_value = (char *)malloc(keys_len);

	memcpy(keys_value,&m_stPublicKey, sizeof(OPST_PCI_ECCrefPublicKey));
	memcpy(keys_value + sizeof(OPST_PCI_ECCrefPublicKey),&m_stPrivateKey, sizeof(OPST_PCI_ECCrefPrivateKey));

	pb64_len = modp_b64_encode_len(keys_len);
	pb64_data = (char *)malloc(pb64_len);

	pb64_len = modp_b64_encode(pb64_data, (char *)keys_value,keys_len);

	::FILE_LOG_STRING(file_log_name, "modp_b64_encode");
	::FILE_LOG_NUMBER(file_log_name, pb64_len);
	::FILE_LOG_STRING(file_log_name, pb64_data);

	//long lLen = MultiByteToWideChar(CP_ACP,0,(LPCSTR)pb64_data,pb64_len,(LPWSTR)pVal,pb64_len * 2);
	BSTR wc_data = SysAllocStringByteLen(NULL, pb64_len * 2); 

	MultiByteToWideChar(CP_ACP,0,(LPCSTR)pb64_data,pb64_len,(LPWSTR)wc_data,pb64_len);

	*pVal = wc_data; // 设置返回值指针。注:不释放内存 

	free(keys_value);
	free(pb64_data);

	return S_OK;
}