Example #1
0
IDropZone * CreateDropZone(const CString & url, const TpDropZone * data)
{
    CDropZone * zone = CreateDropZoneRaw(url, CW2T(data->Name, CP_UTF8), CW2T(data->Path, CP_UTF8));
    ATLASSERT(zone);
    zone->Update(data);
    return zone;
}
Example #2
0
IDropZone * CreateDropZone(const CString & url, const ServiceDetail * data)
{
    CDropZone * zone = CreateDropZoneRaw(url, CW2T(data->Name, CP_UTF8), CW2T(_T(""), CP_UTF8));
    ATLASSERT(zone);
    zone->Update(data);
    return zone;
}
Example #3
0
CString PropVariantToString(const PROPVARIANT& propVar)
{
	USES_CONVERSION;
	CString sPropValue;
	variant_t varPropValue;
   CStdString val;
	if (SUCCEEDED(VariantChangeType(&varPropValue, (VARIANTARG*)&propVar, VARIANT_LOCALBOOL, VT_BSTR)))
		sPropValue = varPropValue.bstrVal;
	else
	{
		//VT_BLOB and VT_LPSTR are uncommon co-ercions
		switch(propVar.vt)
		{
		case VT_BLOB:
			sPropValue.Format(_T("%s"), CW2T((LPCWSTR)propVar.blob.pBlobData).operator LPWSTR());
			break;
		case VT_LPSTR:
         val = MultiByteSupport::ACPToWide(propVar.pszVal);
         sPropValue = val;
			break;
		case VT_LPWSTR:
			sPropValue.Format(_T("%s"), CW2T(propVar.pwszVal).operator LPWSTR());
      	break;
		case VT_FILETIME:
			sPropValue = FiletimeAsString(propVar.filetime);
			break;
		}
	}
	return sPropValue;
}
Example #4
0
	void Update(const LogicalCluster * c)
	{
		m_Name = CW2T(c->Name, CP_UTF8);
		if(c->Queue)
		{
			m_Queue = CW2T(c->Queue, CP_UTF8);
		}
		Refresh();
	}
Example #5
0
 void Update(const ServiceDetail * c)
 {
     m_Name = CW2T(c->Name, CP_UTF8);
     m_Description = CW2T(c->Description, CP_UTF8);
     //m_Path = CW2T(c->Path, CP_UTF8);
     m_Build = CW2T( c->Build, CP_UTF8);
     m_machine = new CMachine();
     m_machine->Update(c->Machines._Machine);
     Refresh();
 }
Example #6
0
	void Update(const TpLogicalCluster * c)
	{
		m_Name = CW2T(c->Name, CP_UTF8);
#if _COMMS_VER < 55100
#else
		if(c->Queue)
		{
			m_Queue = CW2T(c->Queue, CP_UTF8);
		}
#endif
		Refresh();
	}
Example #7
0
void CGroupPrice::UnsubscribeGroup(const CComVariant& params)
{
	if(V_VT(&params) == VT_ERROR)
	{
		EgLib::CEgLibTraceManager::Trace(LogInfo, __FUNCTION__, _T("[%s]\t Checking Subscription Group"), m_strUserName.c_str()); 
		UnsubscribeAll();
	}
	else
	{

		_QuoteUpdateParams Params(params);

		EgLib::CEgLibTraceManager::Trace(LogInfo, __FUNCTION__, _T("[%s]\t Symbol: %s, Exchange: %s, Type: %d"), m_strUserName.c_str(), 
			Params->Symbol?CW2T(Params->Symbol):_T(""), 
			Params->Exchange?CW2T(Params->Exchange):_T(""), 
			Params->Type);


		if(V_VT(&m_vtRequest) != VT_ERROR)
		{
			_QuoteUpdateParams param2(m_vtRequest);
			_bstr_t bsSymbol1(Params->Symbol) ;
			_bstr_t bsSymbol2(param2->Symbol) ;
			if(bsSymbol1 == bsSymbol2 && Params->Type == param2->Type)
			{
				_CancelOptions();
			}
		}		
		_SetDbKey(Params);
		char szSymbol[MAX_LENGTH + 1];
		ZeroMemory(szSymbol,sizeof(szSymbol));
		if(CUtilities::KeyToString(&m_dbaKey.dbaKey, szSymbol, MAX_LENGTH))
		{
			CAutoLock lk(m_csGroupSubscript);
			grouptickermap::iterator itrGroup = m_mapGroupSubscript.find(szSymbol);
			if(itrGroup != m_mapGroupSubscript.end())
			{
				for(tickerset::iterator iter = itrGroup->second.begin(); iter !=  itrGroup->second.end(); iter++)
				{
					DBA_KEYS dbaKey;
					ZeroMemory(&dbaKey, sizeof(DBA_KEYS));
					DeleteSubscription(*iter);
					(*iter)->GetRawKey(&dbaKey.dbaKey);
					DecInterest(&dbaKey);		
				}
				m_mapGroupSubscript.erase(itrGroup);
			}
		}
	}
	m_vtRequest.Clear();
}
Example #8
0
    void Update(const TpDropZone * c)
    {
        m_Name = CW2T(c->Name, CP_UTF8);
        m_Description = CW2T(c->Description, CP_UTF8);
        m_Path = CW2T(c->Path, CP_UTF8);
        m_Build = CW2T( c->Build, CP_UTF8);
        m_machine = new CMachine();
#if _COMMS_VER < 60000 
        m_machine->Update(c->TpMachines);
#else
        m_machine->Update(c->TpMachines._TpMachine);
#endif
        Refresh();
    }
Example #9
0
/*-----------------------------------------------------------------------------
-----------------------------------------------------------------------------*/
int	CWsHook::GetAddrInfoW(PCWSTR pNodeName, PCWSTR pServiceName, const ADDRINFOW * pHints, PADDRINFOW * ppResult)
{
	int ret = WSAEINVAL;
	bool overrideDNS = false;

	void * context = NULL;
	CString name = CW2T(pNodeName);
	CAtlArray<DWORD> addresses;
	if( dlg && pNodeName )
		overrideDNS = dlg->DnsLookupStart( name, context, addresses );

	if( _GetAddrInfoW && !overrideDNS )
		ret = _GetAddrInfoW(CT2W((LPCWSTR)name), pServiceName, pHints, ppResult);
	else if( overrideDNS ) {
		if( addresses.IsEmpty() )
			ret = EAI_NONAME;
		else {
			// build the response structure with the addresses we looked up
			ret = 0;
			DWORD count = addresses.GetCount();

			ADDRINFOW_ADDR * result = (ADDRINFOW_ADDR *)malloc(sizeof(ADDRINFOW_ADDR) * count);
			for (DWORD i = 0; i < count; i++) {
				memset( &result[i], 0, sizeof(ADDRINFOW_ADDR) );
				result->info.ai_family = AF_INET;
				result->info.ai_addrlen = sizeof(struct sockaddr_in);
				result->info.ai_addr = (struct sockaddr *)&(result->addr);
				result->addr.sin_family = AF_INET;
				result->addr.sin_addr.S_un.S_addr = addresses[i];
				if( i < count - 1 )
					result->info.ai_next = (PADDRINFOW)&result[i+1];
			}
			addrInfo.AddTail(result);

			*ppResult = (PADDRINFOW)result;
		}
	}

	if (!ret && dlg) {
		PADDRINFOW addr = *ppResult;
		while (addr) {
      if (addr->ai_canonname)
        dlg->DnsLookupAlias(name, addr->ai_canonname);

      if (context && 
          addr->ai_addrlen >= sizeof(struct sockaddr_in) &&
          addr->ai_family == AF_INET ) {
				struct sockaddr_in * ipName = (struct sockaddr_in *)addr->ai_addr;
				dlg->DnsLookupAddress(context, ipName->sin_addr);
			}

			addr = addr->ai_next;
		}
    
    if (context)
		  dlg->DnsLookupDone(context);
	}

	return ret;
}
void UploadVideoImage(LPVOID lpParam)
{
	UploadVideoImageInfo* pUploadInfo = (UploadVideoImageInfo*)lpParam;

	string PackageDataSegment;
	PackageDataSegment.append("site=");
	PackageDataSegment.append(Encoding::Convert(pUploadInfo->strSite, CP_ACP));
	PackageDataSegment.append("&videoid=");
	PackageDataSegment.append(Encoding::Convert(pUploadInfo->strVideoId, CP_ACP));
	PackageDataSegment.append("&xml=%3C%3Fxml%20version%3D%221.0%22%3F%3E%0D%0A%3CFile%20xmlns%3Adt%3D%22urn%3Aschemas-microsoft-com%3Adatatypes%22%3E%3CName%3E");
	PackageDataSegment.append(Encoding::Convert(pUploadInfo->GetFileName(), CP_ACP));
	PackageDataSegment.append("%3C/Name%3E%3CData%20dt%3Adt%3D%22bin.hex%22%3E");
	PackageDataSegment.append(pUploadInfo->GetFileData());
	PackageDataSegment.append("%3C/Data%3E%3C/File%3E");

	vector<BYTE> vPostData(PackageDataSegment.length());
	memcpy(&vPostData.at(0), PackageDataSegment.c_str(), PackageDataSegment.length());

	vector<BYTE> vResponseData;
	WebClient::Download(TEXT("http://wizard2.webdev.com/cgi-bin/article/uploadimages4video"), vResponseData, vPostData);
	vResponseData.push_back(0);

	Encoding encode;
	TSTLSTRING strRetValue = CW2T(encode.Convert((const char*)&vResponseData.at(0), CP_ACP).c_str());

	delete pUploadInfo;
}
 CString CHTMLayoutCtrl::GetAttr(HELEMENT he, LPCSTR attrName)
 {
   htmlayout::dom::element el = he;
   USES_CONVERSION;
   CString s = CW2T(el.get_attribute(attrName));
   return s;
 }
void WordSchemaSoftDiscoverStrategy::ExtractNoteData(const WrdNote& note, TextTypeEnums textType)
{
	LOG_WS_FUNCTION_SCOPE();
	WrdText text;
	ChUINT4 count = note.getNoteTextLength();
	text.setTextType(textType);
	text.getTextReference().setMinimumCapacity(2 * count);
	text.getTextReference().setStartCP(note.getStartCPOfNoteText());
	text.getTextReference().setCharacterCount(count);
	m_pReader->read(text);

	USES_CONVERSION;
	std::tstring sBuffer;
	if(2 == text.getTextReference().getCharacterSize())
	{
		const wchar_t* wchars = (const wchar_t*)text.getText().getBuffer();
		sBuffer = std::tstring( CW2T( wchars ) );
	}
	else
	{
		const char* chars = (const char*)text.getText().getBuffer();
		sBuffer = std::tstring( CA2T( chars ) );
	}
	if(sBuffer.length() > 0) // OnFootnote called in same scope as CW2T to avoid auto destruction of szBuffer
		m_pVisitor->OnFootnote(sBuffer);
}
Example #13
0
void MonitorSink::ExportCookies(LPCWSTR szResponseHeaders)
{
    static const WCHAR SET_COOKIE_HEAD [] = L"\r\nSet-Cookie:";

    std::vector<UserMessage::SetFirefoxCookieParams> vCookieParams;
    LPWSTR p = (LPWSTR)szResponseHeaders;
    LPWSTR lpCookies = NULL;
    size_t nCookieLen = 0;
    while (p = Utils::HTTP::ExtractFieldValue(p, SET_COOKIE_HEAD, &lpCookies, & nCookieLen))
    {
        if (lpCookies)
        {
            CString strURL = GetBindURL();
            CString strCookie((LPCTSTR)CW2T(lpCookies));
            Utils::HTTP::FreeFieldValue(lpCookies);
            lpCookies = NULL;

            UserMessage::SetFirefoxCookieParams cookieParam;
            cookieParam.strURL = strURL;
            cookieParam.strCookie = strCookie;
            vCookieParams.push_back(cookieParam);
            TRACE(_T("[ExportCookies] URL: %s  Cookie: %s\n"), strURL, strCookie);
            nCookieLen = 0;
        }
    }
    if (vCookieParams.size())
        CIEHostWindow::SetFirefoxCookie(std::move(vCookieParams), m_pIEHostWindow);
}
Example #14
0
/**
 * Get named GUID for debug log.
 * Attempt to translate it through standard Registry lookup, or our
 * custom Registry repository of interface, GUID, Co-class names.
 */
LPCWSTR DbgGetIID(REFIID riid)
{
   static CComAutoCriticalSection s_lock;
   CComCritSecLock<CComCriticalSection> lock(s_lock);
   static CSimpleMap<GUID, CComBSTR> s_Cache;
   LPCWSTR pwstrResult = s_Cache.Lookup(riid);
   if( pwstrResult != NULL ) return pwstrResult;
   TCHAR szName[80] = { 0 };
   OLECHAR wszGUID[50] = { 0 };
   ::StringFromGUID2(riid, wszGUID, lengthof(wszGUID));
   // Attempt to find it in the interfaces section
   CRegKey key;
   DWORD dwType = 0;
   DWORD dwCount = sizeof(szName) - sizeof(TCHAR);
   key.Open(HKEY_CLASSES_ROOT, _T("Interface"), KEY_READ);
   if( szName[0] == '\0' && key.Open(key, wszGUID, KEY_READ) == NOERROR ) {
      ::RegQueryValueEx(key.m_hKey, NULL, NULL, &dwType, (LPBYTE) szName, &dwCount);
   }
   // Attempt to find it in the CLSID section
   key.Open(HKEY_CLASSES_ROOT, _T("CLSID"), KEY_READ);
   if( szName[0] == '\0' && key.Open(key, wszGUID, KEY_READ) == NOERROR ) {
      ::RegQueryValueEx(key.m_hKey, NULL, NULL, &dwType, (LPBYTE) szName, &dwCount);
   }
   // Attempt to find it in our Named GUIDs section
   key.Open(HKEY_CLASSES_ROOT, _T("Named GUIDs"), KEY_READ);
   if( szName[0] == '\0' && key.Open(key, wszGUID, KEY_READ) == NOERROR ) {
      ::RegQueryValueEx(key.m_hKey, NULL, NULL, &dwType, (LPBYTE) szName, &dwCount);
   }
   if( szName[0] == '\0' ) wcscpy_s(szName, lengthof(szName), CW2T(wszGUID));
   s_Cache.Add(riid, CComBSTR(szName));
   return s_Cache.Lookup(riid);
}
Example #15
0
CString MonitorSink::GetBindURL() const
{
    USES_CONVERSION_EX;

    CString strURL;
    WCHAR* pURL = NULL;
    ULONG cEl = 1;
    try
    {
        if (SUCCEEDED(m_spInternetBindInfo->GetBindString(BINDSTRING_URL, &pURL, cEl, &cEl)))
        {
            strURL = (LPCTSTR)CW2T(pURL);
        }
    }
    catch(...)
    {
    }

    if (pURL)
    {
        CoTaskMemFree(pURL);
    }

    return strURL;
}
Example #16
0
// 获取Plugin所在页面的URL
CString CPlugin::GetHostURL() const
{
  CString url;

  BOOL bOK = FALSE;
  NPObject* pWindow = NULL;
  NPVariant vLocation;
  VOID_TO_NPVARIANT(vLocation);
  NPVariant vHref;
  VOID_TO_NPVARIANT(vHref);

  try 
  {

    if (( NPN_GetValue( m_pNPInstance, NPNVWindowNPObject, &pWindow) != NPERR_NO_ERROR ) || !pWindow )
    {
      throw(CString(_T("Cannot get window")));
    }

    if ((!NPN_GetProperty( m_pNPInstance, pWindow, NPN_GetStringIdentifier ("location"), &vLocation)) || !NPVARIANT_IS_OBJECT (vLocation))
    {
      throw(CString(_T("Cannot get window.location")));
    }

    if ((!NPN_GetProperty( m_pNPInstance, NPVARIANT_TO_OBJECT(vLocation), NPN_GetStringIdentifier ("href"), &vHref)) || !NPVARIANT_IS_STRING(vHref))
    {
      throw(CString(_T("Cannot get window.location.href")));
    }

    // 转换window.location.href的编码
    int buffer_size = vHref.value.stringValue.UTF8Length + 1;
    char* szUnescaped = new char[buffer_size];
    DWORD dwSize = buffer_size;
    if (SUCCEEDED(UrlUnescapeA(const_cast<LPSTR>(vHref.value.stringValue.UTF8Characters), szUnescaped, &dwSize, 0)))
    {
      WCHAR* szURL = new WCHAR[dwSize + 1];
      if (MultiByteToWideChar(CP_UTF8, 0, szUnescaped, -1, szURL, dwSize + 1) > 0)
      {
        url = CW2T(szURL);
      }
      delete[] szURL;
    }
    delete[] szUnescaped;

  }
  catch (CString strMessage)
  {
    TRACE(_T("[CPlugin::GetHostURL Exception] %s"), strMessage);
  }

  if (!NPVARIANT_IS_VOID(vHref))	NPN_ReleaseVariantValue(&vHref);
  if (!NPVARIANT_IS_VOID(vLocation))	NPN_ReleaseVariantValue(&vLocation);
  if (pWindow != NULL) NPN_ReleaseObject(pWindow);

  return url;
}
CString NPStringToCString(NPString npstr)
{
	int nWide = MultiByteToWideChar(CP_UTF8, 0, npstr.UTF8Characters, npstr.UTF8Length + 1, NULL, 0);
	if (nWide == 0)
		return CString();
	CStringW wstr;
	MultiByteToWideChar(CP_UTF8, 0, npstr.UTF8Characters, npstr.UTF8Length + 1, wstr.GetBuffer(nWide), nWide);
	wstr.ReleaseBuffer();
	return CString(CW2T(wstr));
}
Example #18
0
	const TCHAR * GetHtml(std::_tstring & html)
	{
		clib::recursive_mutex::scoped_lock proc(m_mutex);
		CComPtr<IHTMLElement> element;
		m_doc3->get_documentElement(&element);
		CComBSTR bstr_html;
		element->get_innerHTML(&bstr_html);
		html = CW2T(bstr_html);
		return html.c_str();
	}
Example #19
0
 void Update(const LogicalFileUpload * c)
 {
     clib::recursive_mutex::scoped_lock proc(m_mutex);
     bool changed = false;
     if (m_source.Compare(CW2T(c->Source, CP_UTF8)) != 0 || 
         m_destination.Compare(CW2T(c->Destination, CP_UTF8)) != 0 || 
         m_type != c->Type)
     {
         changed = true;
     }
     m_type = c->Type;
     m_source = CW2T(c->Source, CP_UTF8);
     m_destination = CW2T(c->Destination, CP_UTF8);
     if (changed)
     {
         proc.unlock();
         Refresh();
     }
 }
Example #20
0
    void Update(const ECLResult * c)
    {
        clib::recursive_mutex::scoped_lock proc(m_mutex);
#if _COMMS_VER < 700000
        m_name = CW2T(c->Name, CP_UTF8);
        m_sequence = c->Sequence;
        m_value = CW2T(c->Value, CP_UTF8);
        m_link = CW2T(c->Link, CP_UTF8);
        IsSupplied = c->IsSupplied;
        m_total = c->Total;
#else
        m_name = CW2T(c->ResultName, CP_UTF8);
        m_sequence = c->SequenceNumber;
        //m_value = CW2T(c->Value, CP_UTF8);
        //m_link = CW2T(c->Link, CP_UTF8);
        m_total = c->TotalRowCount;
#endif
        m_fileName = CW2T(c->FileName, CP_UTF8);
    }
void DeleteVideoToServer(LPVOID lpParam)
{
	TCHAR* pKeyBuffer = (TCHAR*)lpParam;
	TSTLSTRING strKey = TSTLSTRING(pKeyBuffer);
	delete [] pKeyBuffer;

	VideoInfo item = VideoDataManager::GetInstance().GetVideoInfo(strKey);

	string PackageDataSegment("VideoID=");
	PackageDataSegment.append(CT2A(item.VideoID.c_str()));

	vector<BYTE> vPostData(PackageDataSegment.length());
	memcpy(&vPostData.at(0), PackageDataSegment.c_str(), PackageDataSegment.length());

	try
	{
		vector<BYTE> vResponseData;
		WebClient::Download(VideoConfig::GetInstance().GetVideoProxyDeleteVideoUrl(), vResponseData, vPostData);
		vResponseData.push_back(0);

		Encoding encode;
		TSTLSTRING strRetValue = CW2T(encode.Convert((const char*)&vResponseData.at(0), CP_UTF8).c_str());
		TSTLSTRING::size_type pos = strRetValue.find(TEXT(":"));
		if(pos == TSTLSTRING::npos)
		{
			TSTLSTRING ErrMsg(TEXT("·þÎñÆ÷·µ»ØÒì³££¡£¨"));
			ErrMsg.append(strRetValue);
			ErrMsg.append(TEXT("£©"));
			VideoDataManager::GetInstance().ErrorDeleteVideoAndResume(strKey, ErrMsg);
			throw Exception(ErrMsg);
		}
		if(TEXT("OK") == strRetValue.substr(0, pos))
		{
			TSTLSTRING strMsg(item.VideoName);
			CTipsDlg::ShowTips(strMsg, false);
			VideoDataManager::GetInstance().LocalDeleteVideo(strKey);
		}
		else
		{
			TSTLSTRING ErrMsg(TEXT("ɾ³ýÊÓƵʧ°Ü£¡£¨"));
			ErrMsg.append(strRetValue.substr(pos + 1));
			ErrMsg.append(TEXT("£©"));
			VideoDataManager::GetInstance().ErrorDeleteVideoAndResume(strKey, ErrMsg);
			throw Exception(ErrMsg);
		}
	}
	catch(Exception& error)
	{
		VideoDataManager::GetInstance().VideoFail(strKey, error.GetMessage());
		MessageBox(NULL, error.GetMessage().c_str(), TEXT("´íÎó"), MB_OK|MB_ICONERROR);
	}

}
Example #22
0
	void Update(const TpCluster * c)
	{
		m_Name = CW2T(c->Name, CP_UTF8);
		m_Type = CW2T(c->Type, CP_UTF8);
		m_Directory = CW2T(c->Directory, CP_UTF8);
		m_Desc = CW2T(c->Desc, CP_UTF8);
		m_Prefix = CW2T(c->Prefix, CP_UTF8);
		m_Path = CW2T(c->Path, CP_UTF8);
		m_DataModel = CW2T(c->DataModel, CP_UTF8);
		Refresh();
	}
STDMETHODIMP CHyperFeedStructureProviderEx::RequestStock(StockParams *Params)
{
	try
	{
		CRequestBasePtr pRequest = CRequestBasePtr((CRequestBase*)new CStockRequest(Params));
		EgStd::CEgTracingClass::TraceStatic(enlogInfo, __FUNCTION__ , CW2T(Params->Stock));
		AddRequest(pRequest);
	}
	catch (_com_error &err)
	{
		return EgLib::utils::ComError2ErrInfo (err,this);
	}
	return S_OK;
}
STDMETHODIMP CHyperFeedStructureProviderEx::RequestOptions(OptionParams *Params)
{
	try
	{ 
		CRequestBasePtr pRequest = CRequestBasePtr((CRequestBase*)new COptionRequest(Params));
		EgLib::CEgLibTraceManager::Trace(LogInfo, __FUNCTION__ , CW2T(Params->UnderlyingSymbol));

		AddRequest(pRequest);
	}
	catch (_com_error &err)
	{
		return EgLib::utils::ComError2ErrInfo (err, this);
	}
	return S_OK;
}
Example #25
0
	CWebPage(IHTMLDocument * doc) : m_classifyThreads(THREAD_COUNT), m_resolveThreads(THREAD_COUNT)
	{
		m_doc = doc;
		m_doc2 = doc;
		m_doc3 = doc;

		CComBSTR bstr_id;
		m_doc3->get_uniqueID(&bstr_id);
		m_id = CW2T(bstr_id, CP_UTF8);
		//boost::algorithm::to_lower(m_id);
		//boost::algorithm::trim(m_id);
		m_classified = false;
		m_resolved = false;
		m_classifyThreads.MonitorEvents(boost::ref(*this));
		m_resolveThreads.MonitorEvents(boost::ref(*this));
	}
Example #26
0
void SZYamlDocument::_DecodeText(LPCSTR lpszSrc, CString &strTextOut)
{
    int nBOMType;

    for (nBOMType = 0; nBOMType < nBOMFlagCount - 1; nBOMType ++)
    {
        if (0 == memcmp(BOMFlags[nBOMType].pszBOM, lpszSrc, BOMFlags[nBOMType].nBOMSize))
            break;
    }

    lpszSrc += BOMFlags[nBOMType].nBOMSize;

    if (BOMFlags[nBOMType].bIsMutibyte)
        strTextOut = CA2T(lpszSrc, BOMFlags[nBOMType].uMultiByteCodePage);
    else
        strTextOut = CW2T((LPCWSTR)lpszSrc, BOMFlags[nBOMType].uMultiByteCodePage);
}
Example #27
0
bool CUnicodeFile::Read(std::_tstring & data)
{
	std::string rawData;
	std::wstring rawWideData;

	ULONGLONG size, pos;
	if (m_file.GetSize(size) == S_OK && m_file.GetPosition(pos) == S_OK)
	{
		size -= pos;
		DWORD bytesRead;
		if(m_encoding==ENCODING_UTF_16)
		{
			rawWideData.resize(size/sizeof(wchar_t));
			m_file.Read((LPVOID)rawWideData.c_str(), size, bytesRead);
			ATLASSERT(bytesRead == size);
		}
		else
		{
			rawData.resize(static_cast<std::_tstring::size_type>(size));
			for(int i = 0; i < size; i += BLOCKSIZE)
			{
				unsigned int readSize = rawData.length() - i;
				if (readSize > BLOCKSIZE)
					readSize = BLOCKSIZE;
				m_file.Read(const_cast<char *>(rawData.c_str()) + i, readSize, bytesRead);
				ATLASSERT(bytesRead == readSize);
			}
		}
		switch(m_encoding)
		{
		case ENCODING_UTF_16:
			data = CW2T(rawWideData.c_str());
			break;
		case ENCODING_UTF_8:
			data = CA2T(rawData.c_str(), CP_UTF8);
			break;
		case ENCODING_ANSI:
		default:
			data = CA2T(rawData.c_str());
			break;
		}
		return true;
	}
	return false;
}
Example #28
0
/**
 * Saves a rendering of the current site by its host container as a PNG file.
 * This implementation is derived from IECapt.
 *
 * @param outputFile  the file to save the PNG output as
 * @link http://iecapt.sourceforge.net/
 */
STDMETHODIMP CCoSnapsie::saveSnapshot(
    BSTR outputFile,
    BSTR frameId,
    LONG drawableScrollWidth,
    LONG drawableScrollHeight,
    LONG drawableClientWidth,
    LONG drawableClientHeight,
    LONG drawableClientLeft,
    LONG drawableClientTop,
    LONG frameBCRLeft,
    LONG frameBCRTop)
{
    HRESULT hr;
    HWND hwndBrowser;

    CComPtr<IOleClientSite>     spClientSite;
    CComQIPtr<IServiceProvider> spISP;
    CComPtr<IWebBrowser2>       spBrowser;
    CComPtr<IDispatch>          spDispatch; 
    CComQIPtr<IHTMLDocument2>   spDocument;
    CComPtr<IHTMLWindow2>       spScrollableWindow;
    CComQIPtr<IViewObject2>     spViewObject;
    CComPtr<IHTMLStyle>         spStyle;
    CComQIPtr<IHTMLElement2>    spScrollableElement;

    CComVariant documentHeight;
    CComVariant documentWidth;
    CComVariant viewportHeight;
    CComVariant viewportWidth;

    GetSite(IID_IUnknown, (void**)&spClientSite);

    if (spClientSite == NULL)
    {
        Error(L"There is no site.");
        return E_FAIL;
    }

    spISP = spClientSite;
    if (spISP == NULL)
    {
        Error(L"Unable to convert client site to service provider.");
        return E_FAIL;
    }

    // from http://support.microsoft.com/kb/257717
    hr = spISP->QueryService(IID_IWebBrowserApp, IID_IWebBrowser2, (void **)&spBrowser);

    if (FAILED(hr)) {
        // if we can't query the client site for IWebBrowser2, we're probably
        // in an HTA. Obtain the IHTMLWindow2 interface pointer by directly
        // querying the client site's service provider.
        // http://groups.google.com/group/microsoft.public.vc.language/browse_thread/thread/f8987a31d47cccfe/884cb8f13423039e
        CComPtr<IHTMLWindow2> spWindow;
        hr = spISP->QueryService(IID_IHTMLWindow2, &spWindow);
        if (FAILED(hr)) {
            Error("Failed to obtain IHTMLWindow2 from service provider");
            return E_FAIL;
        }

        hr = spWindow->get_document(&spDocument);
        if (FAILED(hr)) {
            Error("Failed to obtain IHTMLDocument2 from window");
            return E_FAIL;
        }

        CComQIPtr<IOleWindow> spOleWindow = spDocument;
        if (spOleWindow == NULL) {
            Error("Failed to obtain IOleWindow from document");
            return E_FAIL;
        }

        hr = spOleWindow->GetWindow(&hwndBrowser);
        if (FAILED(hr)) {
            Error("Failed to obtain HWND from OLE window");
            return E_FAIL;
        }

        hwndBrowser = GetAncestor(hwndBrowser, GA_ROOTOWNER);
    }
    else {
        hr = spBrowser->get_HWND((long*)&hwndBrowser);
        if (FAILED(hr)) {
            Error("Failed to get HWND for browser (is this a frame?)");
            return E_FAIL;
        }

        ie = GetAncestor(hwndBrowser, GA_ROOTOWNER);

        CComPtr<IDispatch> spDispatch;
        hr = spBrowser->get_Document(&spDispatch);
        if (FAILED(hr))
            return E_FAIL;

        spDocument = spDispatch;
        if (spDocument == NULL)
            return E_FAIL;


        IServiceProvider* pServiceProvider = NULL;
        if (SUCCEEDED(spBrowser->QueryInterface(
                            IID_IServiceProvider, 
                            (void**)&pServiceProvider)))
        {
            IOleWindow* pWindow = NULL;
            if (SUCCEEDED(pServiceProvider->QueryService(
                            SID_SShellBrowser,
                            IID_IOleWindow,
                            (void**)&pWindow)))
            {

                if (SUCCEEDED(pWindow->GetWindow(&hwndBrowser)))
                {
                    hwndBrowser = FindWindowEx(hwndBrowser, NULL, _T("Shell DocObject View"), NULL);
                    if (hwndBrowser)
                    {
                        hwndBrowser = FindWindowEx(hwndBrowser, NULL, _T("Internet Explorer_Server"), NULL);
                    }
                }

                pWindow->Release();
            }
         
            pServiceProvider->Release();
        } 
    }

    // Nobody else seems to know how to get IViewObject2?!
    // http://starkravingfinkle.org/blog/2004/09/
    spViewObject = spDocument;
    if (spViewObject == NULL)
    {
        Error(L"Unable to convert document to view object.");
        return E_FAIL;
    }

    CComQIPtr<IHTMLDocument5> spDocument5;
    spDocument->QueryInterface(IID_IHTMLDocument5, (void**)&spDocument5);
    if (spDocument5 == NULL)
    {
        Error(L"Snapsie requires IE6 or greater.");
        return E_FAIL;
    }

    CComBSTR compatMode;
    spDocument5->get_compatMode(&compatMode);

    // In non-standards-compliant mode, the BODY element represents the canvas.
    if (compatMode == L"BackCompat")
    {
        CComPtr<IHTMLElement> spBody;
        spDocument->get_body(&spBody);
        if (NULL == spBody)
        {
            return E_FAIL;
        }

        spBody->getAttribute(CComBSTR("scrollHeight"), 0, &documentHeight);
        spBody->getAttribute(CComBSTR("scrollWidth"), 0, &documentWidth);
        spBody->getAttribute(CComBSTR("clientHeight"), 0, &viewportHeight);
        spBody->getAttribute(CComBSTR("clientWidth"), 0, &viewportWidth);
    }

    // In standards-compliant mode, the HTML element represents the canvas.
    else
    {
        CComQIPtr<IHTMLDocument3> spDocument3;
        spDocument->QueryInterface(IID_IHTMLDocument3, (void**)&spDocument3);
        if (NULL == spDocument3)
        {
            Error(L"Unable to get IHTMLDocument3 handle from document.");
            return E_FAIL;
        }

        // The root node should be the HTML element.
        CComPtr<IHTMLElement> spRootNode;
        spDocument3->get_documentElement(&spRootNode);
        if (NULL == spRootNode)
        {
            Error(L"Could not retrieve root node.");
            return E_FAIL;
        }

        CComPtr<IHTMLHtmlElement> spHtml;
        spRootNode->QueryInterface(IID_IHTMLHtmlElement, (void**)&spHtml);
        if (NULL == spHtml)
        {
            Error(L"Root node is not the HTML element.");
            return E_FAIL;
        }

        spRootNode->getAttribute(CComBSTR("scrollHeight"), 0, &documentHeight);
        spRootNode->getAttribute(CComBSTR("scrollWidth"), 0, &documentWidth);
        spRootNode->getAttribute(CComBSTR("clientHeight"), 0, &viewportHeight);
        spRootNode->getAttribute(CComBSTR("clientWidth"), 0, &viewportWidth);
    }


    // Figure out how large to make the window.  It's not sufficient to just use the dimensions of the scrolled
    // viewport because the browser chrome occupies space that must be accounted for as well.
    RECT ieWindowRect;
    GetWindowRect(ie, &ieWindowRect);
    int ieWindowWidth = ieWindowRect.right - ieWindowRect.left;
    int ieWindowHeight = ieWindowRect.bottom - ieWindowRect.top;

    RECT contentClientRect;
    GetClientRect(hwndBrowser, &contentClientRect);
    int contentClientWidth = contentClientRect.right - contentClientRect.left;
    int contentClientHeight = contentClientRect.bottom - contentClientRect.top;

    int chromeWidth = ieWindowWidth - contentClientWidth;
    int chromeHeight = 2 * (ieWindowHeight - contentClientHeight);

    int imageHeight = documentHeight.intVal;
    int imageWidth = documentWidth.intVal;

    maxWidth = imageWidth + chromeWidth;
    maxHeight = imageHeight + chromeHeight;

    long originalHeight, originalWidth;
    spBrowser->get_Height(&originalHeight);
    spBrowser->get_Width(&originalWidth);


    // The resize message is being ignored if the window appears to be maximized.  There's likely a
    // way to bypass that.  My ghetto way is to unmaximize the window, then move on with setting
    // the window to the dimensions we really want.  This is okay because we revert back to the
    // original dimensions afterward.
    BOOL isMaximized = IsZoomed(ie);
    if (isMaximized)
    {
        ShowWindow(ie, SW_SHOWNORMAL);
    }

    // Get the path to this DLL so we can load it up with LoadLibrary.
    TCHAR dllPath[_MAX_PATH];
    GetModuleFileName((HINSTANCE) &__ImageBase, dllPath, _MAX_PATH);

    // Get the path to the Windows hook we use to allow resizing the window greater than the virtual screen resolution.
    HINSTANCE hinstDLL = LoadLibrary(dllPath);
    HOOKPROC hkprcSysMsg = (HOOKPROC)GetProcAddress(hinstDLL, "CallWndProc");
    if (hkprcSysMsg == NULL)
        PrintError(L"GetProcAddress");

    // Install the Windows hook.
    nextHook = SetWindowsHookEx(WH_CALLWNDPROC, hkprcSysMsg, hinstDLL, 0);
    if (nextHook == 0)
        PrintError(L"SetWindowsHookEx");

    spBrowser->put_Height(maxHeight);
    spBrowser->put_Width(maxWidth);


    // Capture the window's canvas to a DIB.
    CImage image;
    image.Create(imageWidth, imageHeight, 24);
    CImageDC imageDC(image);
    
    hr = PrintWindow(hwndBrowser, imageDC, PW_CLIENTONLY);
    if (FAILED(hr))
    {
        Error(L"PrintWindow");
    }

    // I'm not sure if PrintWindow captures alpha blending or not.  OleDraw does, but I was having
    // issues with sizing the browser correctly between quirks and standards modes to capture everything we need.
    //
    //RECT rcBounds = { 0, 0, imageWidth, imageHeight };
    //hr = OleDraw(spViewObject, DVASPECT_DOCPRINT, imageDC, &rcBounds);
    //if (FAILED(hr))
    //{
    //    Error(L"OleDraw");
    //}

    UnhookWindowsHookEx(nextHook);

    // Restore the browser to the original dimensions.
    if (isMaximized)
    {
        ShowWindow(ie, SW_MAXIMIZE);
    }
    else
    {
        spBrowser->put_Height(originalHeight);
        spBrowser->put_Width(originalWidth);
    }

    hr = image.Save(CW2T(outputFile));
    if (FAILED(hr))
    {
        PrintError(L"Failed saving image.");
        return E_FAIL;
    }

    return hr;
}
void CTTSApp::MainHandleSynthEvent()
/////////////////////////////////////////////////////////////////
//
// Handles the WM_TTSAPPCUSTOMEVENT application defined message and all
// of it's appropriate SAPI5 events.
//
{

    CSpEvent        event;  // helper class in sphelper.h for events that releases any 
                            // allocated memory in it's destructor - SAFER than SPEVENT
    SPVOICESTATUS   Stat;
    WPARAM          nStart;
    LPARAM          nEnd;
    int             i = 0;
    HRESULT         hr = S_OK;

    while( event.GetFrom(m_cpVoice) == S_OK )
    {
        switch( event.eEventId )
        {
            case SPEI_START_INPUT_STREAM:
                if( IsDlgButtonChecked( m_hWnd, IDC_EVENTS ) )
                {
                    TTSAppStatusMessage( m_hWnd, _T("StartStream event\r\n") );
                }
                break; 

            case SPEI_END_INPUT_STREAM:
                // Set global boolean stop to TRUE when finished speaking
                m_bStop = TRUE; 
                // Highlight entire text
                nStart = 0;
                nEnd = SendDlgItemMessage( m_hWnd, IDE_EDITBOX, WM_GETTEXTLENGTH, 0, 0 );
                SendDlgItemMessage( m_hWnd, IDE_EDITBOX, EM_SETSEL, nStart, nEnd );
                // Mouth closed
                g_iBmp = 0;
                InvalidateRect( m_hChildWnd, NULL, FALSE );
                if( IsDlgButtonChecked( m_hWnd, IDC_EVENTS ) )
                {
                    TTSAppStatusMessage( m_hWnd, _T("EndStream event\r\n") );
                }
                break;     
                
            case SPEI_VOICE_CHANGE:
                if( IsDlgButtonChecked( m_hWnd, IDC_EVENTS ) )
                {
                    TTSAppStatusMessage( m_hWnd, _T("Voicechange event\r\n") );
                }
                break;

            case SPEI_TTS_BOOKMARK:
                if( IsDlgButtonChecked( m_hWnd, IDC_EVENTS ) )
                {
                    // Get the string associated with the bookmark
                    // and add the null terminator.
                    TCHAR szBuff2[MAX_PATH] = _T("Bookmark event: ");

                    size_t cEventString = wcslen( event.String() ) + 1;
                    WCHAR *pwszEventString = new WCHAR[ cEventString ];
                    if ( pwszEventString )
                    {
                        wcscpy_s( pwszEventString, cEventString, event.String() );
                        _tcscat_s( szBuff2, _countof(szBuff2), CW2T(pwszEventString) );
                        delete[] pwszEventString;
                    }

                    _tcscat_s( szBuff2, _countof(szBuff2), _T("\r\n") );
                    TTSAppStatusMessage( m_hWnd, szBuff2 );
                }
                break;

            case SPEI_WORD_BOUNDARY:
                hr = m_cpVoice->GetStatus( &Stat, NULL );
                if( FAILED( hr ) )
                {
                    TTSAppStatusMessage( m_hWnd, _T("Voice GetStatus error\r\n") );
                }

                // Highlight word
                nStart = (LPARAM)( Stat.ulInputWordPos / sizeof(char) );
                nEnd = nStart + Stat.ulInputWordLen;
                SendDlgItemMessage( m_hWnd, IDE_EDITBOX, EM_SETSEL, nStart, nEnd );
                if( IsDlgButtonChecked( m_hWnd, IDC_EVENTS ) )
                {
                    
                    TTSAppStatusMessage( m_hWnd, _T("Wordboundary event\r\n") );
                }
                break;

            case SPEI_PHONEME:
                if( IsDlgButtonChecked( m_hWnd, IDC_EVENTS ) )
                {
                    TTSAppStatusMessage( m_hWnd, _T("Phoneme event\r\n") );
                }
                break;

            case SPEI_VISEME:
                // Get the current mouth viseme position and map it to one of the 
                // 7 mouth bitmaps. 
                g_iBmp = g_aMapVisemeToImage[event.Viseme()]; // current viseme

                InvalidateRect( m_hChildWnd, NULL, FALSE );
                if( IsDlgButtonChecked( m_hWnd, IDC_EVENTS ) )
                {
                    TTSAppStatusMessage( m_hWnd, _T("Viseme event\r\n") );
                }
                break;

            case SPEI_SENTENCE_BOUNDARY:
                if( IsDlgButtonChecked( m_hWnd, IDC_EVENTS ) )
                {
                    TTSAppStatusMessage( m_hWnd, _T("Sentence event\r\n") );
                }
                break;

            case SPEI_TTS_AUDIO_LEVEL:
                if( IsDlgButtonChecked( m_hWnd, IDC_EVENTS ) )
                {
                    WCHAR wszBuff[MAX_PATH];
                    swprintf_s(wszBuff, _countof(wszBuff), L"Audio level: %d\r\n", (ULONG)event.wParam);
                    TTSAppStatusMessage( m_hWnd, CW2T(wszBuff) );
                }
                break;

            case SPEI_TTS_PRIVATE:
                if( IsDlgButtonChecked( m_hWnd, IDC_EVENTS ) )
                {
                    TTSAppStatusMessage( m_hWnd, _T("Private engine event\r\n") );
                }
                break;

            default:
                TTSAppStatusMessage( m_hWnd, _T("Unknown message\r\n") );
                break;
        }
    }
}
void CreateVideoToServerWithoutArticle(LPVOID lpParam)
{
	wchar_t* pVideoKey = (wchar_t*)lpParam;
	TSTLSTRING strKey = TSTLSTRING(CW2T(pVideoKey));
	delete [] pVideoKey;

	VideoInfo item = VideoDataManager::GetInstance().GetVideoInfo(strKey);
	try
	{
		TSTLSTRING FileMD5 = FileHash::MD5(item.VideoFilePath);
		DWORD dwFileSize = FileHash::GetFileSize(item.VideoFilePath);

		string PackageDataSegment;
		PackageDataSegment.append("Name=");
		PackageDataSegment.append(Encoding::UrlEncoding(Encoding::Convert(item.VideoName, CP_UTF8)));
		PackageDataSegment.append("&SourceId=");
		PackageDataSegment.append(Encoding::UrlEncoding(Encoding::Convert(item.VideoSource, CP_UTF8)));
		PackageDataSegment.append("&Author=");
		PackageDataSegment.append(Encoding::UrlEncoding(Encoding::Convert(item.VideoAuthor, CP_UTF8)));
		PackageDataSegment.append("&Channel=");
		PackageDataSegment.append(Encoding::UrlEncoding(Encoding::Convert(item.VideoChannel, CP_UTF8)));
		PackageDataSegment.append("&Creator=");
		PackageDataSegment.append(Encoding::UrlEncoding(Encoding::Convert(item.VideoCreator, CP_UTF8)));
		PackageDataSegment.append("&CatalogId=");
		PackageDataSegment.append(Encoding::UrlEncoding(Encoding::Convert(item.VideoCatalog, CP_UTF8)));
		PackageDataSegment.append("&Content=");
		PackageDataSegment.append(Encoding::UrlEncoding(Encoding::Convert(item.VideoContent, CP_UTF8)));
		PackageDataSegment.append("&Keyword=");
		PackageDataSegment.append(Encoding::UrlEncoding(Encoding::Convert(item.VideoKeyword, CP_UTF8)));
		PackageDataSegment.append("&MD5=");
		PackageDataSegment.append(Encoding::UrlEncoding(Encoding::Convert(FileMD5, CP_UTF8)));
		PackageDataSegment.append("&VideoSize=");
		PackageDataSegment.append(Encoding::UrlEncoding(boost::lexical_cast<std::string, DWORD>(dwFileSize)));

		vector<BYTE> vPostData(PackageDataSegment.length());
		memcpy(&vPostData.at(0), PackageDataSegment.c_str(), PackageDataSegment.length());

		vector<BYTE> vResponseData;
		WebClient::Download(VideoConfig::GetInstance().GetVideoProxyCreateVideoInfoUrl(), vResponseData, vPostData);
		vResponseData.push_back(0);

		Encoding encode;
		TSTLSTRING strRetValue = CW2T(encode.Convert((const char*)&vResponseData.at(0), CP_UTF8).c_str());
		TSTLSTRING::size_type pos = strRetValue.find(TEXT(":"));
		if(pos == TSTLSTRING::npos)
		{
			TSTLSTRING ErrMsg(TEXT("·þÎñÆ÷·µ»ØÒì³££¡£¨"));
			ErrMsg.append(strRetValue);
			ErrMsg.append(TEXT("£©"));
			throw Exception(ErrMsg);
		}
		if(TEXT("OK") == strRetValue.substr(0, pos))
		{
			TSTLSTRING strVideoId;
			TSTLSTRING::size_type posId = strRetValue.find(TEXT("-"));
			if(posId == TSTLSTRING::npos)
			{
				VideoDataManager::GetInstance().LocalDeleteVideo(strKey);
				MessageBox(NULL, TEXT("¸ÃÊÓƵÒѾ­ÉÏ´«£¡"), TEXT("Ìáʾ"), MB_OK|MB_ICONINFORMATION);
			}
			else
			{
				strVideoId = strRetValue.substr(posId + 1);

				CVideoInfoDataManager& dataMgr = VideoDataManager::GetInstance();
				dataMgr.SetVideoId(strKey, strRetValue.substr(pos + 1));

				try
				{
					QQPlay play;
					vector<TSTLSTRING> vVideoPic = play.GetPictures(item.VideoFilePath);

					for(vector<TSTLSTRING>::iterator iter=vVideoPic.begin();
						iter!=vVideoPic.end();
						++iter)
					{
						UploadVideoImageInfo* pUploadInfo = new UploadVideoImageInfo();
						pUploadInfo->strfile = *iter;
						pUploadInfo->strSite = item.VideoChannel;
						pUploadInfo->strVideoId = strVideoId;

						UploadImageThread::GetInstance().SendMessage(WM_UPLOADVIDEOIMG, pUploadInfo);
					}

				}
				catch(Exception& error)
				{
					MessageBox(NULL, error.GetMessage().c_str(), TEXT("´íÎó"), MB_OK|MB_ICONERROR);
				}
			}
		}
		else
		{
			TSTLSTRING ErrMsg(TEXT("Ìí¼ÓÊÓƵʧ°Ü£¡£¨"));
			ErrMsg.append(strRetValue.substr(pos + 1));
			ErrMsg.append(TEXT("£©"));
			throw Exception(ErrMsg);
		}
	}
	catch(Exception& error)
	{
		VideoDataManager::GetInstance().VideoFail(strKey, error.GetMessage());
		MessageBox(NULL, error.GetMessage().c_str(), TEXT("´íÎó"), MB_OK|MB_ICONERROR);
	}
}