HRESULT CFGManagerBDA::CreateKSFilter(IBaseFilter** ppBF, CLSID KSCategory, CStringW& DisplayName) { HRESULT hr = VFW_E_NOT_FOUND; BeginEnumSysDev (KSCategory, pMoniker) { CComPtr<IPropertyBag> pPB; CComVariant var; LPOLESTR strName = NULL; if (SUCCEEDED (pMoniker->BindToStorage(0, 0, IID_IPropertyBag, (void**)&pPB)) && SUCCEEDED (pMoniker->GetDisplayName(NULL, NULL, &strName)) && SUCCEEDED (pPB->Read(CComBSTR(_T("FriendlyName")), &var, NULL)) ) { CStringW Name = CStringW(strName); if (Name != DisplayName) { continue; } hr = pMoniker->BindToObject(NULL, NULL, IID_IBaseFilter, (void**)ppBF); if (SUCCEEDED (hr)) { hr = AddFilter (*ppBF, CStringW(var.bstrVal)); } break; } if (strName) { CoTaskMemFree(strName); } }
CStringW CComboBoxEx::GetItemTextW(int nItem) const { if (IsUnicodeSystem()) { COMBOBOXEXITEMW ce; WCHAR szBuffer[2000]; ce.iItem=nItem; ce.cchTextMax=2000; ce.pszText=szBuffer; ce.mask=CBEIF_TEXT; if (::SendMessageW(CCommonCtrl::m_hWnd,CBEM_GETITEMW,0,(LPARAM)&ce)) return CStringW(szBuffer); } else { COMBOBOXEXITEM ce; char szBuffer[2000]; ce.iItem=nItem; ce.cchTextMax=2000; ce.pszText=szBuffer; ce.mask=CBEIF_TEXT; if (::SendMessageA(CCommonCtrl::m_hWnd,CBEM_GETITEMA,0,(LPARAM)&ce)) return CStringW(szBuffer); } return CStringW(); }
void CFormData::AddFile(LPCTSTR __szField, LPCTSTR __szFilename, LPCTSTR __szMime) { CFormItem *attr = NULL; CStringW sMime = __szMime; // Se o mime for null, vamos tentar determinar... if(__szMime == NULL) { CStringW s1 = __szFilename; int pos = 0; if((pos = s1.ReverseFind('.')) > 0) s1 = s1.Right(s1.GetLength()-pos-1); sMime = GetMime(s1); } // Verificar se ja foi incluido... if(!m_items.Lookup(CStringW(__szField).MakeLower(), attr)) attr = new CFormItem(__szField, __szFilename, sMime); else { // Se sim, vamos atualizar o item... attr->m_value = __szFilename; attr->m_mime = sMime; } m_items.SetAt(CStringW(__szField).MakeLower(), attr); }
void CWAVFile::SetProperties(IBaseFilter* pBF) { if (m_info.GetCount() > 0) { if (CComQIPtr<IDSMPropertyBag> pPB = pBF) { POSITION pos = m_info.GetStartPosition(); while (pos) { DWORD fcc; CStringA value; m_info.GetNextAssoc(pos, fcc, value); switch (fcc) { case FCC('INAM'): pPB->SetProperty(L"TITL", CStringW(value)); break; case FCC('IART'): pPB->SetProperty(L"AUTH", CStringW(value)); break; case FCC('ICOP'): pPB->SetProperty(L"CPYR", CStringW(value)); break; case FCC('ISBJ'): pPB->SetProperty(L"DESC", CStringW(value)); break; } } } } }
CStringW CFileDataIO::ReadStringUTF8() { UINT uRawSize = ReadUInt16(); const UINT uMaxShortRawSize = SHORT_RAW_ED2K_UTF8_STR; if (uRawSize <= uMaxShortRawSize) { char acRaw[uMaxShortRawSize]; Read(acRaw, uRawSize); WCHAR awc[uMaxShortRawSize]; int iChars = ByteStreamToWideChar(acRaw, uRawSize, awc, ARRSIZE(awc)); if (iChars >= 0) return CStringW(awc, iChars); return CStringW(acRaw, uRawSize); // use local codepage } else { Array<char> acRaw(uRawSize); Read(acRaw, uRawSize); Array<WCHAR> awc(uRawSize); int iChars = ByteStreamToWideChar(acRaw, uRawSize, awc, uRawSize); if (iChars >= 0) return CStringW(awc, iChars); return CStringW(acRaw, uRawSize); // use local codepage; } }
CStringW ReadMemoryStringW( size_t address, SIZE_T max ) { auto buffer = std::make_unique<wchar_t[ ]>( max + 1 ); SIZE_T bytesRead; if ( ReadMemory( (PVOID) address, buffer.get( ), max * sizeof( wchar_t ), &bytesRead ) != 0 ) { bytesRead /= sizeof( wchar_t ); for ( int i = 0; i < bytesRead; i++ ) { if ( !( iswprint( buffer[ i ] ) ) && buffer[ i ] != '\0' ) buffer[ i ] = '.'; } buffer[ bytesRead ] = '\0'; return CStringW( buffer.get( ) ); } else { #ifdef _DEBUG PrintOut( _T( "[ReadMemoryString]: Failed to read memory, GetLastError() = %s" ), Utils::GetLastErrorString( ).GetString( ) ); #endif return CStringW( L".." ); } }
void CConvertDlg::AddFile(CString fn) { CString protocol; int i = fn.Find(_T("://")); if(i > 0) { CString url = fn.Mid(i); CPath path(fn.Left(i)); path.StripPath(); protocol = (LPCTSTR)path; fn = (LPCTSTR)path + url; } CComPtr<IBaseFilter> pBF; if(FAILED(m_pGB->AddSourceFilter(CStringW(fn), CStringW(fn), &pBF))) return; int nConnected = 0; BeginEnumPins(pBF, pEP, pPin) if(S_OK == m_pGB->ConnectFilter(pPin, m_pMux)) nConnected++; EndEnumPins; if(!nConnected) { MessageBeep((UINT)-1); DeleteFilter(pBF); return; } if(m_tree.GetCount() == 0) { if(CComQIPtr<IDSMPropertyBag> pPB = m_pMux) pPB->DelAllProperties(); CString ext(_T(".dsm")); if(!protocol.IsEmpty()) { m_fn = protocol + ext; } else { CPath p(fn); if(ext.CompareNoCase(p.GetExtension()) == 0) ext = _T(" (remuxed)") + ext; p.RemoveExtension(); m_fn = (LPCTSTR)p + ext; } UpdateData(FALSE); } CTreeItemFile* t = DNew CTreeItemFile(fn, pBF, m_tree, NULL); AddFilter(*t, pBF); m_tree.Expand(*t, TVE_EXPAND); m_tree.EnsureVisible(*t); }
bool CmbFileFind::IsDots() { if (m_foundInfo != 0) { return (((CStringW)(m_foundInfo->cFileName)).CompareNoCase(CStringW(".")) == 0 || ((CStringW)(m_foundInfo->cFileName)).CompareNoCase(CStringW("..")) == 0); } return false; }
char*CMt5Client::UnicodeToUTF_8First(CString str) { //mid 将UNICODE的CString转换为utf8字符串返回,在此处使用的是堆内存分配,所以,接受者在使用完结果后需要手动释放内存,以防溢出 int u8Len = WideCharToMultiByte(CP_UTF8, NULL, CStringW(str), str.GetLength(), NULL, 0, NULL, NULL); char* szU8 = new char[u8Len + 1]; WideCharToMultiByte(CP_UTF8, NULL, CStringW(str), str.GetLength(), szU8, u8Len, NULL, NULL); szU8[u8Len] = '\0'; return szU8; }
void CFormData::AddItem(LPCTSTR __szField, LPCTSTR __szValue) { CFormItem *attr = NULL; // Verifica se ja foi inserido... if(!m_items.Lookup(CStringW(__szField).MakeLower(), attr)) attr = new CFormItem(__szField, __szValue); else attr->m_value = __szValue; // Atualiza... m_items.SetAt(CStringW(__szField).MakeLower(), attr); }
void Skein::Import(const char* path) { Node* node = m_inst.root; bool added = false; CStdioFile recFile; if (recFile.Open(path,CFile::modeRead|CFile::typeText)) { CString recLine; while (recFile.ReadString(recLine)) { recLine.Trim(); if (recLine.GetLength() > 0) { CStringW recLineW = EscapeLine(CStringW(recLine),UsePrintable); Node* newNode = node->Find(recLineW); if (newNode == NULL) { newNode = new Node(recLineW,L"",L"",L"",false); node->Add(newNode); added = true; } node = newNode; } } if (added) { m_layout = false; NotifyChange(TreeChanged); NotifyEdit(true); } } }
bool getPropertyValue(CComPtr<IDispatchEx> object, DISPID dispId, VARIANT& result) { // Invoke the property get to get the property's value. // DISPPARAMS params; memset(¶ms, 0, sizeof(DISPPARAMS)); VariantInit(&result); BSTR memberName = NULL; if (SUCCEEDED(object->GetMemberName(dispId, &memberName))) { // BEGIN HARDCODE - Accessing the "filters" property (for example, from Google Maps) // causes crashes access violations deep in MSHTML. // bool skip = CStringW(memberName).Compare(L"filters") == 0; SysFreeString(memberName); if (skip) return false; // END HARDCODE } if (SUCCEEDED(object->Invoke(dispId, IID_NULL, LOCALE_SYSTEM_DEFAULT, DISPATCH_PROPERTYGET, ¶ms, &result, NULL, NULL))) { return true; } else { return false; } }
LRESULT COleIPFrameWnd::OnSetMessageString(WPARAM wParam, LPARAM lParam) { if (m_lpFrame != NULL) { LPCTSTR lpsz = NULL; CString strMessage; // set the message bar text if (lParam != NULL) { ASSERT(wParam == 0); // can't have both an ID and a string lpsz = (LPCTSTR)lParam; // set an explicit string } else if (wParam != 0) { // get message associated with the ID indicated by wParam GetMessageString((UINT)wParam, strMessage); lpsz = strMessage; } // notify container of new status text if (lpsz == NULL) lpsz = _T(""); m_lpFrame->SetStatusText(CStringW(lpsz).GetString()); } UINT nIDLast = m_nIDLastMessage; m_nIDLastMessage = (UINT)wParam; // new ID (or 0) m_nIDTracking = (UINT)wParam; // so F1 on toolbar buttons work return nIDLast; }
FontWrapper* FontCache::Create(HDC hDC, const LOGFONT& lf) { CStringW key; key.Format(L"%s,%d,%d,%d", CStringW(lf.lfFaceName), lf.lfHeight, lf.lfWeight, ((lf.lfItalic&1)<<2) | ((lf.lfUnderline&1)<<1) | ((lf.lfStrikeOut&1)<<0)); FontWrapper* pFW = NULL; if(m_key2obj.Lookup(key, pFW)) { return pFW; } HFONT hFont = CreateFontIndirect(&lf); if(!hFont) { ASSERT(0); return NULL; } pFW = DNew FontWrapper(hDC, hFont, key); Add(key, pFW, false); return pFW; }
CStringW InformApp::GetProfileString(LPCSTR section, LPCWSTR entry, LPCWSTR defaultValue) { if (theOS.IsWindows9X()) { CString entryA(entry), defaultValueA(defaultValue); return CStringW(CWinApp::GetProfileString(section,entryA,defaultValueA)); } if (m_pszRegistryKey == NULL) return defaultValue; HKEY secKey = GetSectionKey(section); if (secKey == NULL) return defaultValue; CStringW value; DWORD type, count; LONG result = ::RegQueryValueExW(secKey,entry,NULL,&type,NULL,&count); if (result == ERROR_SUCCESS) { result = ::RegQueryValueExW(secKey,entry,NULL,&type, (LPBYTE)value.GetBuffer(count/sizeof(WCHAR)),&count); value.ReleaseBuffer(); } ::RegCloseKey(secKey); if (result == ERROR_SUCCESS) return value; return defaultValue; }
static CStringW GetText(CComPtr<IXMLDOMNode> pNode) { CComBSTR bstr; pNode->get_text(&bstr); return CStringW(bstr); }
STDMETHODIMP CFilterMapper2::RegisterFilter(REFCLSID clsidFilter, LPCWSTR Name, IMoniker** ppMoniker, const CLSID* pclsidCategory, const OLECHAR* szInstance, const REGFILTER2* prf2) { if(!m_path.IsEmpty()) { if(FilterOverride* f = new FilterOverride) { f->fDisabled = false; f->type = FilterOverride::EXTERNAL; f->path = m_path; f->name = CStringW(Name); f->clsid = clsidFilter; f->iLoadType = FilterOverride::MERIT; f->dwMerit = prf2->dwMerit; if(prf2->dwVersion == 1) { for(ULONG i = 0; i < prf2->cPins; i++) { const REGFILTERPINS& rgPin = prf2->rgPins[i]; if(rgPin.bOutput) continue; for(UINT i = 0; i < rgPin.nMediaTypes; i++) { if(!rgPin.lpMediaType[i].clsMajorType || !rgPin.lpMediaType[i].clsMinorType) break; f->guids.AddTail(*rgPin.lpMediaType[i].clsMajorType); f->guids.AddTail(*rgPin.lpMediaType[i].clsMinorType); } } } else if(prf2->dwVersion == 2) { for(ULONG i = 0; i < prf2->cPins2; i++) { const REGFILTERPINS2& rgPin = prf2->rgPins2[i]; if(rgPin.dwFlags®_PINFLAG_B_OUTPUT) continue; for(UINT i = 0; i < rgPin.nMediaTypes; i++) { if(!rgPin.lpMediaType[i].clsMajorType || !rgPin.lpMediaType[i].clsMinorType) break; f->guids.AddTail(*rgPin.lpMediaType[i].clsMajorType); f->guids.AddTail(*rgPin.lpMediaType[i].clsMinorType); } } } f->backup.AddTailList(&f->guids); m_filters.AddTail(f); } return S_OK; } else if(CComQIPtr<IFilterMapper2> pFM2 = m_pFM2) { return pFM2->RegisterFilter(clsidFilter, Name, ppMoniker, pclsidCategory, szInstance, prf2); } return E_NOTIMPL; }
BOOL WINAPI DetourCreateDirectoryExW(LPCWSTR lpTemplateDirectory, LPCWSTR lpNewDirectory, LPSECURITY_ATTRIBUTES lpSecurityAttributes) { if (lpNewDirectory == NULL) return NativeCreateDirectoryExW(lpTemplateDirectory, lpNewDirectory, lpSecurityAttributes); CStringW strNewDirectory = CHistoryManager::GetInstance()->Redirect(CStringW(lpNewDirectory)); return NativeCreateDirectoryExW(lpTemplateDirectory, strNewDirectory, lpSecurityAttributes); }
DWORD WINAPI DetourSetNamedSecurityInfoW(LPWSTR pObjectName, SE_OBJECT_TYPE ObjectType, SECURITY_INFORMATION SecurityInfo, PSID psidOwner, PSID psidGroup, PACL pDacl, PACL pSacl) { if (pObjectName == NULL) return NativeSetNamedSecurityInfoW(pObjectName, ObjectType, SecurityInfo, psidOwner, psidGroup, pDacl, pSacl); CStringW strObjectName = CHistoryManager::GetInstance()->Redirect(CStringW(pObjectName)); return NativeSetNamedSecurityInfoW((LPWSTR)(LPCWSTR)strObjectName, ObjectType, SecurityInfo, psidOwner, psidGroup, pDacl, pSacl); }
DWORD WINAPI DetourSearchPathW(LPCWSTR lpPath, LPCWSTR lpFileName, LPCWSTR lpExtension, DWORD nBufferLength, LPWSTR lpBuffer, LPWSTR* lpFilePart) { if (lpPath == NULL) return NativeSearchPathW(lpPath, lpFileName, lpExtension, nBufferLength, lpBuffer, lpFilePart); CStringW strPath = CHistoryManager::GetInstance()->Redirect(CStringW(lpPath)); return NativeSearchPathW(strPath, lpFileName, lpExtension, nBufferLength, lpBuffer, lpFilePart); }
BOOL WINAPI DetourPathFileExistsW(LPCWSTR pszPath) { if (pszPath == NULL) return NativePathFileExistsW(pszPath); CStringW strPath = CHistoryManager::GetInstance()->Redirect(CStringW(pszPath)); return NativePathFileExistsW(strPath); }
BOOL WINAPI DetourGetFileAttributesExW(LPCWSTR lpFileName, GET_FILEEX_INFO_LEVELS fInfoLevelId, LPVOID lpFileInformation) { if (lpFileName == NULL) return NativeGetFileAttributesExW(lpFileName, fInfoLevelId, lpFileInformation); CStringW strFileName = CHistoryManager::GetInstance()->Redirect(CStringW(lpFileName)); return NativeGetFileAttributesExW(strFileName, fInfoLevelId, lpFileInformation); }
BOOL WINAPI DetourDeleteFileW(LPCWSTR lpFileName) { if (lpFileName == NULL) return NativeDeleteFileW(lpFileName); CStringW strFileName = CHistoryManager::GetInstance()->Redirect(CStringW(lpFileName)); return NativeDeleteFileW(strFileName); }
BOOL WINAPI DetourCreateDirectoryW(LPCWSTR lpPathName, LPSECURITY_ATTRIBUTES lpSecurityAttributes) { if (lpPathName == NULL) return NativeCreateDirectoryW(lpPathName, lpSecurityAttributes); CStringW strPathName = CHistoryManager::GetInstance()->Redirect(CStringW(lpPathName)); return NativeCreateDirectoryW(strPathName, lpSecurityAttributes); }
BOOL WINAPI DetourGetDiskFreeSpaceExW(LPCWSTR lpDirectoryName, PULARGE_INTEGER lpFreeBytesAvailable, PULARGE_INTEGER lpTotalNumberOfBytes, PULARGE_INTEGER lpTotalNumberOfFreeBytes) { if (lpDirectoryName == NULL) return NativeGetDiskFreeSpaceExW(lpDirectoryName, lpFreeBytesAvailable, lpTotalNumberOfBytes, lpTotalNumberOfFreeBytes); CStringW strDirectoryName = CHistoryManager::GetInstance()->Redirect(CStringW(lpDirectoryName)); return NativeGetDiskFreeSpaceExW(strDirectoryName, lpFreeBytesAvailable, lpTotalNumberOfBytes, lpTotalNumberOfFreeBytes); }
DWORD WINAPI DetourGetFileAttributesW(LPCWSTR lpFileName) { if (lpFileName == NULL) return NativeGetFileAttributesW(lpFileName); CStringW strFileName = CHistoryManager::GetInstance()->Redirect(CStringW(lpFileName)); return NativeGetFileAttributesW(strFileName); }
HANDLE WINAPI DetourFindFirstFileW(LPCWSTR lpFileName, LPWIN32_FIND_DATAW lpFindFileData) { if (lpFileName == NULL) return NativeFindFirstFileW(lpFileName, lpFindFileData); CStringW strFileName = CHistoryManager::GetInstance()->Redirect(CStringW(lpFileName)); return NativeFindFirstFileW(strFileName, lpFindFileData); }
BOOL WINAPI DetourSetCurrentDirectoryW(LPCWSTR lpPathName) { if (lpPathName == NULL) return NativeSetCurrentDirectoryW(lpPathName); CStringW strPathName = CHistoryManager::GetInstance()->Redirect(CStringW(lpPathName)); return NativeSetCurrentDirectoryW(strPathName); }
CComManager::CComManager(void) { CHAR szExePath[MAX_PATH]; DWORD ret = GetModuleFileNameExA(GetCurrentProcess(), NULL, szExePath, MAX_PATH); assert(ret <= MAX_PATH); CStringA strExePath = CStringA(szExePath); char* pLastSlash = strrchr(szExePath, '\\'); if(pLastSlash == NULL) { assert(false); return; } strcpy_s(pLastSlash, MAX_PATH,"\\COM\\*"); char* comdir_ptr = pLastSlash + strlen("\\COM"); WIN32_FIND_DATAA fd; memset(&fd, 0, sizeof(WIN32_FIND_DATAA)); HANDLE hFile = FindFirstFileA(szExePath, &fd); if (hFile != INVALID_HANDLE_VALUE) { do { if(!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) continue; // Check if it is a COM name if(strlen(fd.cFileName) != 38) continue; COM_CLSID clsid; CLSIDFromString((LPOLESTR)(const WCHAR*)CStringW(fd.cFileName), &clsid.clsid); sprintf_s(comdir_ptr,(MAX_PATH - 5), "\\%s\\*", fd.cFileName); char* com_ptr = comdir_ptr + strlen(comdir_ptr) - 1; WIN32_FIND_DATAA Comfd; memset(&Comfd, 0, sizeof(WIN32_FIND_DATAA)); HANDLE hComFile = FindFirstFileA(szExePath, &Comfd); if(hComFile == INVALID_HANDLE_VALUE) continue; do { if(strcmp(Comfd.cFileName, ".") == 0 || strcmp(Comfd.cFileName, "..") == 0) continue; strcpy_s(com_ptr,MAX_PATH, Comfd.cFileName); m_comlist.insert(std::make_pair(clsid, CStringA(szExePath))); }while(FindNextFileA(hComFile, &Comfd)); FindClose(hComFile); }while(FindNextFileA(hFile, &fd)); FindClose(hFile); } }
HANDLE WINAPI DetourCreateFileW(LPCWSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile) { if (lpFileName == NULL) return NativeCreateFileW(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile); CStringW strFileName = CHistoryManager::GetInstance()->Redirect(CStringW(lpFileName)); return NativeCreateFileW(strFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile); }