本文整理汇总了C++中CComPtr类的典型用法代码示例。如果您正苦于以下问题:C++ CComPtr类的具体用法?C++ CComPtr怎么用?C++ CComPtr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CComPtr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LOG
bool BrowserFactory::AttachToBrowser(ProcessWindowInfo* process_window_info,
std::string* error_message) {
LOG(TRACE) << "Entering BrowserFactory::AttachToBrowser";
clock_t end = clock() + (this->browser_attach_timeout_ / 1000 * CLOCKS_PER_SEC);
while (process_window_info->hwndBrowser == NULL) {
if (this->browser_attach_timeout_ > 0 && (clock() > end)) {
break;
}
::EnumWindows(&BrowserFactory::FindBrowserWindow,
reinterpret_cast<LPARAM>(process_window_info));
if (process_window_info->hwndBrowser == NULL) {
::Sleep(250);
}
}
if (process_window_info->hwndBrowser == NULL) {
*error_message = StringUtilities::Format(ATTACH_TIMEOUT_ERROR_MESSAGE,
process_window_info->dwProcessId,
this->browser_attach_timeout_);
return false;
}
CComPtr<IHTMLDocument2> document;
if (this->GetDocumentFromWindowHandle(process_window_info->hwndBrowser,
&document)) {
CComPtr<IHTMLWindow2> window;
HRESULT hr = document->get_parentWindow(&window);
// Test for zoom level = 100%
int zoom_level = 100;
LOG(DEBUG) << "Ignoring zoom setting: " << this->ignore_zoom_setting_;
if (!this->ignore_zoom_setting_) {
zoom_level = this->GetZoomLevel(document, window);
}
if (zoom_level != 100) {
*error_message = StringUtilities::Format(ZOOM_SETTING_ERROR_MESSAGE,
zoom_level);
return false;
}
if (SUCCEEDED(hr)) {
// http://support.microsoft.com/kb/257717
CComPtr<IServiceProvider> provider;
window->QueryInterface<IServiceProvider>(&provider);
if (provider) {
CComPtr<IServiceProvider> child_provider;
hr = provider->QueryService(SID_STopLevelBrowser,
IID_IServiceProvider,
reinterpret_cast<void**>(&child_provider));
if (SUCCEEDED(hr)) {
IWebBrowser2* browser;
hr = child_provider->QueryService(SID_SWebBrowserApp,
IID_IWebBrowser2,
reinterpret_cast<void**>(&browser));
if (SUCCEEDED(hr)) {
process_window_info->pBrowser = browser;
return true;
} else {
LOGHR(WARN, hr) << "IServiceProvider::QueryService for SID_SWebBrowserApp failed";
}
} else {
LOGHR(WARN, hr) << "IServiceProvider::QueryService for SID_STopLevelBrowser failed";
}
} else {
LOG(WARN) << "QueryInterface for IServiceProvider failed";
}
} else {
LOGHR(WARN, hr) << "Call to IHTMLDocument2::get_parentWindow failed";
}
} else {
*error_message = "Could not get document from window handle";
}
return false;
}
示例2: FindOtherSplitterPin
HRESULT FindOtherSplitterPin(IPin *pPinIn, GUID guid, int nStream, IPin **ppSplitPin)
{
if (!ppSplitPin)
return E_POINTER;
CComPtr< IPin > pPinOut;
pPinOut = pPinIn;
while(pPinOut)
{
PIN_INFO ThisPinInfo;
pPinOut->QueryPinInfo(&ThisPinInfo);
if(ThisPinInfo.pFilter) ThisPinInfo.pFilter->Release();
pPinOut = NULL;
CComPtr< IEnumPins > pEnumPins;
ThisPinInfo.pFilter->EnumPins(&pEnumPins);
if(!pEnumPins)
{
return NULL;
}
// look at every pin on the current filter...
//
ULONG Fetched = 0;
while(1)
{
CComPtr< IPin > pPin;
Fetched = 0;
_ASSERT(!pPin); // is it out of scope?
pEnumPins->Next(1, &pPin, &Fetched);
if(!Fetched)
{
break;
}
PIN_INFO pi;
pPin->QueryPinInfo(&pi);
if(pi.pFilter) pi.pFilter->Release();
// if it's an input pin...
//
if(pi.dir == PINDIR_INPUT)
{
// continue searching upstream from this pin
//
pPin->ConnectedTo(&pPinOut);
// a pin that supports the required media type is the
// splitter pin we are looking for! We are done
//
}
else
{
CComPtr< IEnumMediaTypes > pMediaEnum;
pPin->EnumMediaTypes(&pMediaEnum);
if(pMediaEnum)
{
Fetched = 0;
AM_MEDIA_TYPE *pMediaType;
pMediaEnum->Next(1, &pMediaType, &Fetched);
if(Fetched)
{
if(pMediaType->majortype == guid)
{
if(nStream-- == 0)
{
DeleteMediaType(pMediaType);
*ppSplitPin = pPin;
(*ppSplitPin)->AddRef();
return S_OK;
}
}
DeleteMediaType(pMediaType);
}
}
}
// go try the next pin
} // while
}
_ASSERT(FALSE);
return E_FAIL;
}
示例3: deinit
int Receive::init(int devNum, unsigned minRepeat)
{
m_minRepeat = minRepeat;
deinit();
int devCount=0;
// create system device enumerator
CComPtr <ICreateDevEnum> pSysDevEnum = nullptr;
HRESULT hr = pSysDevEnum.CoCreateInstance(CLSID_SystemDeviceEnum);
if (hr == S_OK)
{
// create a class enumerator for the desired category defined by classGuid.
CComPtr <IEnumMoniker> pEnumCat = nullptr; //moniker enumerator for filter categories
hr = pSysDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, &pEnumCat, 0);
if (hr == S_OK)
{
// reset the enumeration
pEnumCat->Reset();
// now iterate through enumeration
ULONG cFetched = 0;
CComPtr <IMoniker> pMoniker = nullptr;
// get a pointer to each moniker
while(pEnumCat->Next(1, &pMoniker, &cFetched) == S_OK)
{
CComPtr <IBaseFilter> pFilter = nullptr;
// create an instance of the filter
hr = pMoniker->BindToObject(0, 0, IID_IBaseFilter, (void**)&pFilter);
if (hr == S_OK)
{
m_pKsVCPropSet = nullptr;
// query for interface
hr = pFilter->QueryInterface(IID_IKsPropertySet, (void **)&m_pKsVCPropSet);
if (m_pKsVCPropSet)
{
DWORD type_support;
hr = m_pKsVCPropSet->QuerySupported(KSPROPSETID_CustomIRCaptureProperties,
KSPROPERTY_IRCAPTURE_COMMAND,
&type_support);
if ( SUCCEEDED(hr) && (type_support & KSPROPERTY_SUPPORT_SET) )
if (devCount == devNum)
break;
}
}
pMoniker.Release();
}
}
}
if ( FAILED(hr) || !m_pKsVCPropSet )
return 0;
KSPROPERTY_IRCAPTURE_COMMAND_S ir_cmd;
ir_cmd.CommandCode = IRCAPTURE_COMMAND_START;
// make call into driver
hr = m_pKsVCPropSet->Set(KSPROPSETID_CustomIRCaptureProperties,
KSPROPERTY_IRCAPTURE_COMMAND,
&ir_cmd, sizeof(ir_cmd),
&ir_cmd, sizeof(ir_cmd));
if FAILED(hr) return 0;
threadHandle = CreateThread(nullptr,0,IRReader,(void *)this,0,nullptr);
return threadHandle!=nullptr;
}
示例4: EumerateContactsServices
// Enumerates all Contacts Services, displaying the associated device of each service.
void EumerateContactsServices(CAtlArray<PWSTR>& ContactsServicePnpIDs)
{
HRESULT hr = S_OK;
DWORD cPnpDeviceIDs = 0;
PWSTR* pPnpDeviceIDs = NULL;
CComPtr<IPortableDeviceManager> pPortableDeviceManager;
CComPtr<IPortableDeviceServiceManager> pServiceManager;
// CoCreate the IPortableDeviceManager interface to enumerate
// portable devices and to get information about them.
hr = CoCreateInstance(CLSID_PortableDeviceManager,
NULL,
CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&pPortableDeviceManager));
if (FAILED(hr))
{
printf("! Failed to CoCreateInstance CLSID_PortableDeviceManager, hr = 0x%lx\n",hr);
}
// Retrieve the IPortableDeviceServiceManager interface to enumerate device services.
if (SUCCEEDED(hr))
{
hr = pPortableDeviceManager->QueryInterface(IID_PPV_ARGS(&pServiceManager));
if (FAILED(hr))
{
printf("! Failed to QueryInterface IID_IPortableDeviceServiceManager, hr = 0x%lx\n",hr);
}
}
if (SUCCEEDED(hr))
{
// First, pass NULL as the PWSTR array pointer to get the total number
// of devices found on the system.
hr = pPortableDeviceManager->GetDevices(NULL, &cPnpDeviceIDs);
if (FAILED(hr))
{
printf("! Failed to get number of devices on the system, hr = 0x%lx\n",hr);
}
if (SUCCEEDED(hr) && (cPnpDeviceIDs > 0))
{
// Second, allocate an array to hold the PnPDeviceID strings returned from
// the IPortableDeviceManager::GetDevices method
pPnpDeviceIDs = new (std::nothrow) PWSTR[cPnpDeviceIDs];
if (pPnpDeviceIDs != NULL)
{
DWORD dwIndex = 0;
hr = pPortableDeviceManager->GetDevices(pPnpDeviceIDs, &cPnpDeviceIDs);
if (SUCCEEDED(hr))
{
//<SnippetOpenService1>
// For each device found, find the contacts service
for (dwIndex = 0; dwIndex < cPnpDeviceIDs; dwIndex++)
{
DWORD cPnpServiceIDs = 0;
PWSTR pPnpServiceID = NULL;
// First, pass NULL as the PWSTR array pointer to get the total number
// of contacts services (SERVICE_Contacts) found on the device.
// To find the total number of all services on the device, use GUID_DEVINTERFACE_WPD_SERVICE.
hr = pServiceManager->GetDeviceServices(pPnpDeviceIDs[dwIndex], SERVICE_Contacts, NULL, &cPnpServiceIDs);
if (SUCCEEDED(hr) && (cPnpServiceIDs > 0))
{
// For simplicity, we are only using the first contacts service on each device
cPnpServiceIDs = 1;
hr = pServiceManager->GetDeviceServices(pPnpDeviceIDs[dwIndex], SERVICE_Contacts, &pPnpServiceID, &cPnpServiceIDs);
if (SUCCEEDED(hr))
{
// We've found the service, display it and save its PnP Identifier
ContactsServicePnpIDs.Add(pPnpServiceID);
printf("[%d] ", static_cast<DWORD>(ContactsServicePnpIDs.GetCount()-1));
// Display information about the device that contains this service.
DisplayDeviceInformation(pServiceManager, pPnpServiceID);
// ContactsServicePnpIDs now owns the memory for this string
pPnpServiceID = NULL;
}
else
{
printf("! Failed to get the first contacts service from '%ws, hr = 0x%lx\n",pPnpDeviceIDs[dwIndex],hr);
}
}
}
//</SnippetOpenService1>
}
// Free all returned PnPDeviceID strings
FreePortableDevicePnPIDs(pPnpDeviceIDs, cPnpDeviceIDs);
// Delete the array of PWSTR pointers
delete [] pPnpDeviceIDs;
//.........这里部分代码省略.........
示例5: ChooseDeviceService
// Calls EnumerateDeviceServices() function to display device services on the system
// and to obtain the total number of device services found. If 1 or more device services
// are found, this function prompts the user to choose a device service using
// a zero-based index.
void ChooseDeviceService(IPortableDeviceService** ppService)
{
HRESULT hr = S_OK;
UINT uiCurrentService = 0;
CHAR szSelection[81] = {0};
CComPtr<IPortableDeviceValues> pClientInformation;
CAtlArray<PWSTR> ContactsServicesArray;
if (ppService == NULL)
{
printf("! A NULL IPortableDeviceService interface pointer was received\n");
return;
}
if (*ppService != NULL)
{
// To avoid operating on potiential bad pointers, reject any non-null
// IPortableDeviceService interface pointers. This will force the caller
// to properly release the interface before obtaining a new one.
printf("! A non-NULL IPortableDeviceService interface pointer was received, please release this interface before obtaining a new one.\n");
return;
}
// Fill out information about your application, so the device knows
// who they are speaking to.
GetClientInformation(&pClientInformation);
// Enumerate and display all Contacts services
EumerateContactsServices(ContactsServicesArray);
DWORD cServicePnPIDs = static_cast<DWORD>(ContactsServicesArray.GetCount());
if (cServicePnPIDs > 0)
{
CComPtr<IPortableDeviceService> pService;
// Prompt user to enter an index for the device they want to choose.
printf("Enter the index of the Contacts device service you wish to use.\n>");
hr = StringCbGetsA(szSelection,sizeof(szSelection));
if (SUCCEEDED(hr))
{
uiCurrentService = (UINT) atoi(szSelection);
if (uiCurrentService >= cServicePnPIDs)
{
printf("An invalid Contacts device service index was specified, defaulting to the first in the list.\n");
uiCurrentService = 0;
}
}
else
{
printf("An invalid Contacts device service index was specified, defaulting to the first in the list.\n");
uiCurrentService = 0;
}
// CoCreate the IPortableDeviceService interface and call Open() with
// the chosen PnPServiceID string.
//<SnippetOpenService2>
hr = CoCreateInstance(CLSID_PortableDeviceServiceFTM,
NULL,
CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&pService));
if (SUCCEEDED(hr))
{
hr = pService->Open(ContactsServicesArray[uiCurrentService], pClientInformation);
if (FAILED(hr))
{
if (hr == E_ACCESSDENIED)
{
printf("Failed to Open the service for Read Write access, will open it for Read-only access instead\n");
pClientInformation->SetUnsignedIntegerValue(WPD_CLIENT_DESIRED_ACCESS, GENERIC_READ);
hr = pService->Open(ContactsServicesArray[uiCurrentService], pClientInformation);
if (FAILED(hr))
{
printf("! Failed to Open the service for Read access, hr = 0x%lx\n",hr);
}
}
else
{
printf("! Failed to Open the service, hr = 0x%lx\n",hr);
}
}
//</SnippetOpenService2>
if (SUCCEEDED(hr))
{
printf("Successfully opened the selected Contacts service\n");
// Successfully opened a service, set the result
*ppService = pService.Detach();
}
}
//.........这里部分代码省略.........
示例6: BackgroundImage
void ImageHandler::LoadDesktopWallpaperWin8(MonitorEnumData* pEnumData)
{
CComPtr<IDesktopWallpaper> desktopWallpaper;
HRESULT hr = desktopWallpaper.CoCreateInstance(CLSID_DesktopWallpaper, nullptr, CLSCTX_ALL);
if(FAILED(hr)) return;
UINT count;
hr = desktopWallpaper->GetMonitorDevicePathCount(&count);
if(FAILED(hr)) return;
for(UINT i = 0; i < count; i++)
{
// Get the device path for the monitor.
CComHeapPtr<wchar_t> spszId;
hr = desktopWallpaper->GetMonitorDevicePathAt(i, &spszId);
if(FAILED(hr)) continue;
// Get the monitor location.
CRect rectMonitor;
hr = desktopWallpaper->GetMonitorRECT(spszId, (LPRECT)rectMonitor);
if(FAILED(hr)) continue;
// Get the wallpaper on that monitor.
CComHeapPtr<wchar_t> spszWallpaper;
hr = desktopWallpaper->GetWallpaper(spszId, &spszWallpaper);
if(FAILED(hr)) continue;
TRACE(
L"wallpaper picture on '%s' (%ix%i)-(%ix%i) is '%s'\n",
static_cast<wchar_t*>(spszId),
rectMonitor.left, rectMonitor.top,
rectMonitor.right, rectMonitor.bottom,
static_cast<wchar_t*>(spszWallpaper));
std::shared_ptr<BackgroundImage> bkImage;
if(spszWallpaper.m_pData && *spszWallpaper.m_pData)
{
bkImage.reset(new BackgroundImage (pEnumData->bkImage->imageData));
bkImage->imageData.strFilename = spszWallpaper.m_pData;
bkImage->bWallpaper = true;
ImageHandler::LoadImageW(bkImage);
}
else
{
bkImage = pEnumData->bkImage;
}
if( bkImage->originalImage.get() )
{
// create template image
CDC dcTemplate;
CBitmap bmpTemplate;
dcTemplate.CreateCompatibleDC(NULL);
DWORD dwNewWidth = rectMonitor.Width();
DWORD dwNewHeight = rectMonitor.Height();
ImageHandler::PaintRelativeImage(pEnumData->dcTemplate, bmpTemplate, bkImage, dwNewWidth, dwNewHeight);
dcTemplate.SelectBitmap(bmpTemplate);
ImageHandler::PaintTemplateImage(
dcTemplate,
rectMonitor.left - ::GetSystemMetrics(SM_XVIRTUALSCREEN),
rectMonitor.top - ::GetSystemMetrics(SM_YVIRTUALSCREEN),
dwNewWidth,
dwNewHeight,
rectMonitor.Width(),
rectMonitor.Height(),
pEnumData->bkImage);
}
}
}
示例7: streamBk
bool ImageHandler::GetDesktopImageData(ImageData& imageData)
{
CRegKey keyColors;
if (keyColors.Open(HKEY_CURRENT_USER, L"Control Panel\\Colors", KEY_READ) != ERROR_SUCCESS) return false;
CString strBackground;
DWORD dwDataSize = 32;
if (keyColors.QueryStringValue(L"Background", strBackground.GetBuffer(dwDataSize), &dwDataSize) != ERROR_SUCCESS)
{
strBackground.ReleaseBuffer();
return false;
}
strBackground.ReleaseBuffer();
wstringstream streamBk(wstring(strBackground.operator LPCTSTR()));
DWORD r = 0;
DWORD g = 0;
DWORD b = 0;
streamBk >> r;
streamBk >> g;
streamBk >> b;
CRegKey keyDesktop;
if (keyDesktop.Open(HKEY_CURRENT_USER, L"Control Panel\\Desktop", KEY_READ) != ERROR_SUCCESS) return false;
DWORD dwChars = 0;
CString strWallpaperFile;
CString strWallpaperStyle;
CString strWallpaperTile;
dwChars = 32;
keyDesktop.QueryStringValue(L"WallpaperStyle", strWallpaperStyle.GetBuffer(dwChars), &dwChars);
dwChars = 32;
keyDesktop.QueryStringValue(L"TileWallpaper", strWallpaperTile.GetBuffer(dwChars), &dwChars);
dwChars = MAX_PATH;
keyDesktop.QueryStringValue(L"Wallpaper", strWallpaperFile.GetBuffer(dwChars), &dwChars);
strWallpaperStyle.ReleaseBuffer();
strWallpaperFile.ReleaseBuffer();
strWallpaperTile.ReleaseBuffer();
// set background data
imageData.strFilename = strWallpaperFile;
imageData.bRelative = true;
imageData.bExtend = false;
imageData.crBackground = RGB(static_cast<BYTE>(r), static_cast<BYTE>(g), static_cast<BYTE>(b));
if (strWallpaperTile == L"1")
{
imageData.imagePosition= imagePositionTile;
}
else
{
if (strWallpaperStyle == L"0")
{
imageData.imagePosition= imagePositionCenter;
}
else if (strWallpaperStyle == L"6")
{
imageData.imagePosition= imagePositionFit;
}
else if (strWallpaperStyle == L"10")
{
imageData.imagePosition= imagePositionFill;
}
else if (strWallpaperStyle == L"22")
{
imageData.imagePosition= imagePositionFill;
imageData.bExtend = true;
}
else
{
imageData.imagePosition= imagePositionStretch;
}
}
#if _WIN32_WINNT >= 0x0602
if( ImageHandler::IsWin8() )
{
CComPtr<IDesktopWallpaper> desktopWallpaper;
HRESULT hr = desktopWallpaper.CoCreateInstance(CLSID_DesktopWallpaper, nullptr, CLSCTX_ALL);
if( SUCCEEDED(hr) )
{
DESKTOP_WALLPAPER_POSITION position;
hr = desktopWallpaper->GetPosition(&position);
UINT count = 0;
hr = desktopWallpaper->GetMonitorDevicePathCount(&count);
if( hr == S_OK && position == DWPOS_SPAN && count > 1 )
{
CComHeapPtr<wchar_t> spszWallpaper;
hr = desktopWallpaper->GetWallpaper(NULL, &spszWallpaper);
if( hr == S_OK )
imageData.bExtend = true;
}
}
}
//.........这里部分代码省略.........
示例8: EnumerateComponents
BOOL EnumerateComponents(CComPtr<INetCfg>& pINetCfg, const GUID* pguidClass)
{
TRACE_ENTER();
/* cout << "\n\nEnumerating " << GUID2Str(pguidClass) << " class:\n" << endl;*/
// IEnumNetCfgComponent provides methods that enumerate the INetCfgComponent interfaces
// for network components of a particular type installed on the operating system.
// Types of network components include network cards, protocols, services, and clients.
CComPtr<IEnumNetCfgComponent> pIEnumNetCfgComponent;
// get enumeration containing network components of the provided class (GUID)
HRESULT hr = pINetCfg->EnumComponents(pguidClass, &pIEnumNetCfgComponent);
if(!SUCCEEDED(hr))
{
TRACE_PRINT1("INetCfg::EnumComponents: error, errCode = 0x%08x.", hr);
throw 1;
}
// INetCfgComponent interface provides methods that control and retrieve
// information about a network component.
CComPtr<INetCfgComponent> pINetCfgComponent;
unsigned int nIndex = 1;
BOOL bFound = FALSE;
BOOL bFailed = FALSE;
// retrieve the next specified number of INetCfgComponent interfaces in the enumeration sequence.
while(pIEnumNetCfgComponent->Next(1, &pINetCfgComponent, 0) == S_OK)
{
/* cout << GUID2Desc(pguidClass) << " "<< nIndex++ << ":\n";*/
// LPWSTR pszDisplayName = NULL;
// pINetCfgComponent->GetDisplayName(&pszDisplayName);
// wcout << L"\tDisplay name: " << wstring(pszDisplayName) << L'\n';
// CoTaskMemFree(pszDisplayName);
LPWSTR pszBindName = NULL;
pINetCfgComponent->GetBindName(&pszBindName);
// wcout << L"\tBind name: " << wstring(pszBindName) << L'\n';
// DWORD dwCharacteristics = 0;
// pINetCfgComponent->GetCharacteristics(&dwCharacteristics);
// cout << "\tCharacteristics: " << dwCharacteristics << '\n';
//
// GUID guid;
// pINetCfgComponent->GetClassGuid(&guid);
// cout << "\tClass GUID: " << guid.Data1 << '-' << guid.Data2 << '-'
// << guid.Data3 << '-' << (unsigned int) guid.Data4 << '\n';
//
// ULONG ulDeviceStatus = 0;
// pINetCfgComponent->GetDeviceStatus(&ulDeviceStatus);
// cout << "\tDevice Status: " << ulDeviceStatus << '\n';
//
// LPWSTR pszHelpText = NULL;
// pINetCfgComponent->GetHelpText(&pszHelpText);
// wcout << L"\tHelp Text: " << wstring(pszHelpText) << L'\n';
// CoTaskMemFree(pszHelpText);
//
// LPWSTR pszID = NULL;
// pINetCfgComponent->GetId(&pszID);
// wcout << L"\tID: " << wstring(pszID) << L'\n';
// CoTaskMemFree(pszID);
//
// pINetCfgComponent->GetInstanceGuid(&guid);
// cout << "\tInstance GUID: " << guid.Data1 << '-' << guid.Data2 << '-'
// << guid.Data3 << '-' << (unsigned int) guid.Data4 << '\n';
LPWSTR pszPndDevNodeId = NULL;
hr = pINetCfgComponent->GetPnpDevNodeId(&pszPndDevNodeId);
if (!SUCCEEDED(hr))
{
TRACE_PRINT1("GetPnpDevNodeId failed: %#x", hr);
TRACE_EXIT();
return FALSE;
}
// wcout << L"\tPNP Device Node ID: " << wstring(pszPndDevNodeId) << L'\n';
int iDevID = getIntDevID(pszPndDevNodeId);
TRACE_PRINT4("INetCfgComponent::GetPnpDevNodeId: executing, pszPndDevNodeId = %s, iDevID = %d, g_NpcapAdapterID = %d, pszBindName = %ws.",
pszPndDevNodeId, iDevID, g_NpcapAdapterID, pszBindName);
if (g_NpcapAdapterID == iDevID)
{
bFound = TRUE;
TRACE_PRINT2("INetCfgComponent::SetDisplayName: executing, g_NpcapAdapterID = iDevID = %d, pszBindName = %ws.", g_NpcapAdapterID, pszBindName);
hr = pINetCfgComponent->SetDisplayName(NPCAP_LOOPBACK_ADAPTER_NAME);
if (hr != S_OK)
{
TRACE_PRINT1("INetCfgComponent::SetDisplayName: error, errCode = 0x%08x.", hr);
bFailed = TRUE;
}
if (!AddFlagToRegistry(pszBindName))
{
TRACE_PRINT1("AddFlagToRegistry: error, pszBindName = %ws.", pszBindName);
bFailed = TRUE;
}
//.........这里部分代码省略.........
示例9: SHELL32_GetFSItemAttributes
HRESULT SHELL32_GetFSItemAttributes(IShellFolder * psf, LPCITEMIDLIST pidl, LPDWORD pdwAttributes)
{
DWORD dwFileAttributes, dwShellAttributes;
if (!_ILIsFolder(pidl) && !_ILIsValue(pidl))
{
ERR("Got wrong type of pidl!\n");
*pdwAttributes &= SFGAO_CANLINK;
return S_OK;
}
if (*pdwAttributes & ~dwSupportedAttr)
{
WARN ("attributes 0x%08x not implemented\n", (*pdwAttributes & ~dwSupportedAttr));
*pdwAttributes &= dwSupportedAttr;
}
dwFileAttributes = _ILGetFileAttributes(pidl, NULL, 0);
/* Set common attributes */
dwShellAttributes = *pdwAttributes;
dwShellAttributes |= SFGAO_FILESYSTEM | SFGAO_DROPTARGET | SFGAO_HASPROPSHEET | SFGAO_CANDELETE |
SFGAO_CANRENAME | SFGAO_CANLINK | SFGAO_CANMOVE | SFGAO_CANCOPY;
if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
dwShellAttributes |= (SFGAO_FOLDER | SFGAO_HASSUBFOLDER | SFGAO_FILESYSANCESTOR);
}
else
dwShellAttributes &= ~(SFGAO_FOLDER | SFGAO_HASSUBFOLDER | SFGAO_FILESYSANCESTOR);
if (dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
dwShellAttributes |= SFGAO_HIDDEN;
else
dwShellAttributes &= ~SFGAO_HIDDEN;
if (dwFileAttributes & FILE_ATTRIBUTE_READONLY)
dwShellAttributes |= SFGAO_READONLY;
else
dwShellAttributes &= ~SFGAO_READONLY;
if (SFGAO_LINK & *pdwAttributes)
{
char ext[MAX_PATH];
if (!_ILGetExtension(pidl, ext, MAX_PATH) || lstrcmpiA(ext, "lnk"))
dwShellAttributes &= ~SFGAO_LINK;
}
if (SFGAO_HASSUBFOLDER & *pdwAttributes)
{
CComPtr<IShellFolder> psf2;
if (SUCCEEDED(psf->BindToObject(pidl, 0, IID_PPV_ARG(IShellFolder, &psf2))))
{
CComPtr<IEnumIDList> pEnumIL;
if (SUCCEEDED(psf2->EnumObjects(0, SHCONTF_FOLDERS, &pEnumIL)))
{
if (pEnumIL->Skip(1) != S_OK)
dwShellAttributes &= ~SFGAO_HASSUBFOLDER;
}
}
}
*pdwAttributes &= dwShellAttributes;
TRACE ("-- 0x%08x\n", *pdwAttributes);
return S_OK;
}
示例10: FindDevice
BOOL FindDevice(const CComBSTR& deviceIdentifier, IDeviceEmulatorManagerVMID** pDeviceVMID)
{
HRESULT hr;
CComPtr<IDeviceEmulatorManager> pDeviceEmulatorManager;
hr = pDeviceEmulatorManager.CoCreateInstance(__uuidof(DeviceEmulatorManager));
if (FAILED(hr)) {
wprintf(L"Error: Unable to instantiate DeviceEmulatorManager. ErrorCode=0x%08X\n", hr);
return FALSE;
}
for (; SUCCEEDED(hr); (hr = pDeviceEmulatorManager->MoveNext()))
{
CComPtr<IEnumManagerSDKs> pSDKEnumerator;
hr = pDeviceEmulatorManager->EnumerateSDKs(&pSDKEnumerator);
if (FAILED(hr)) {
continue;
}
for (; SUCCEEDED(hr); (hr = pSDKEnumerator->MoveNext())) {
CComPtr<IEnumVMIDs> pDeviceEnumerator;
hr = pSDKEnumerator->EnumerateVMIDs(&pDeviceEnumerator);
if (FAILED(hr)) {
continue;
}
for (; SUCCEEDED(hr); (hr = pDeviceEnumerator->MoveNext())) {
CComBSTR deviceName;
CComBSTR deviceVMID;
CComPtr<IDeviceEmulatorManagerVMID> pDevice;
hr = pDeviceEnumerator->GetVMID(&pDevice);
if (FAILED(hr)) {
continue;
}
hr = pDevice->get_Name(&deviceName);
if (FAILED(hr)){
continue;
}
hr = pDevice->get_VMID(&deviceVMID);
if (FAILED(hr)){
continue;
}
if (deviceIdentifier == deviceName || deviceIdentifier == deviceVMID){
*pDeviceVMID = pDevice;
(*pDeviceVMID)->AddRef();
return TRUE;
}
}
}
}
wprintf(L"Error: Unable to locate the device '%s'", deviceIdentifier);
return FALSE;
}
示例11: switch
HRESULT CPixelShaderCompiler::InternalCompile(
LPCSTR pSrcData,
SIZE_T SrcDataSize,
LPCSTR pSourceName,
LPCSTR pEntrypoint,
LPCSTR pProfile,
DWORD Flags,
IDirect3DPixelShader9** ppPixelShader,
CString* pDisasm,
CString* pErrMsg)
{
if (!m_pD3DCompile) {
return E_FAIL;
}
if (pDisasm && !m_pD3DDisassemble) {
return E_FAIL;
}
if (ppPixelShader && !m_pD3DDev) {
return E_FAIL;
}
LPCSTR pSelProfile = pProfile;
if (!pSelProfile || *pSelProfile == '\0') {
D3DCAPS9 caps;
if (m_pD3DDev && m_pD3DDev->GetDeviceCaps(&caps) == D3D_OK) {
switch (D3DSHADER_VERSION_MAJOR(caps.PixelShaderVersion)) {
case 2:
if (caps.PS20Caps.NumInstructionSlots < 512) {
pSelProfile = "ps_2_0";
} else if (caps.PS20Caps.Caps > 0) {
pSelProfile = "ps_2_a";
} else {
pSelProfile = "ps_2_b";
}
break;
case 3:
pSelProfile = "ps_3_0";
break;
}
} else {
ASSERT(FALSE);
}
}
if (!pSelProfile || *pSelProfile == '\0') {
return E_FAIL;
}
LPCSTR defProfile = "MPC_HC_SHADER_PROFILE";
LPCSTR defProfileVal;
if (!strcmp(pSelProfile, "ps_2_0")) {
defProfileVal = "0";
} else if (!strcmp(pSelProfile, "ps_2_b")) {
defProfileVal = "1";
} else if (!strcmp(pSelProfile, "ps_2_a") || !strcmp(pSelProfile, "ps_2_sw")) {
defProfileVal = "2";
} else if (!strcmp(pSelProfile, "ps_3_0") || !strcmp(pSelProfile, "ps_3_sw")) {
defProfileVal = "3";
} else {
defProfileVal = "-1";
}
D3D_SHADER_MACRO macros[] = { { defProfile, defProfileVal }, { 0 } };
CComPtr<ID3DBlob> pShaderBlob, pErrorBlob;
HRESULT hr = m_pD3DCompile(pSrcData, SrcDataSize, pSourceName, macros, nullptr, pEntrypoint,
pSelProfile, Flags, 0, &pShaderBlob, &pErrorBlob);
if (pErrMsg) {
CStringA msg;
if (pErrorBlob) {
auto len = pErrorBlob->GetBufferSize();
VERIFY(memcpy_s(msg.GetBufferSetLength((int)len), len, pErrorBlob->GetBufferPointer(), len) == 0);
msg.ReleaseBuffer((int)len);
}
*pErrMsg = msg;
}
if (FAILED(hr)) {
return hr;
}
if (ppPixelShader) {
hr = m_pD3DDev->CreatePixelShader((DWORD*)pShaderBlob->GetBufferPointer(), ppPixelShader);
if (FAILED(hr)) {
return hr;
}
}
if (pDisasm) {
CComPtr<ID3DBlob> pDisasmBlob;
CStringA defs;
for (auto pMacro = macros; pMacro && pMacro->Name && pMacro->Definition; pMacro++) {
defs.Append("// #define ");
defs.Append(pMacro->Name);
defs.Append(" ");
defs.Append(pMacro->Definition);
defs.Append("\n");
}
//.........这里部分代码省略.........
示例12: memcpy
HRESULT CAVIVideoPin::Deliver(IMediaSample *pSample)
{
CComPtr<IMediaSample> pSampleDeliver = pSample;
if (pSample->IsDiscontinuity() == S_OK)
{
if (m_seqHParser.isInited())
{
BYTE* pBuffer = NULL;
pSample->GetPointer(&pBuffer);
long len = pSample->GetActualDataLength();
if (!m_seqHParser.ParseFrame(pBuffer, len))
{
// get it from the first sample
const INDEXENTRY& entry = (*m_pIndex)[0];
BYTE* pTempData = new BYTE[entry.dwChunkLength];
CAVIScanner* scanner = m_pSplitter->GetAVIScanner();
scanner->ReadData(entry.chunkOffset, entry.dwChunkLength, pTempData);
BYTE* pDecoderConfig = NULL;
int decoderConfigLen = 0;
if (m_seqHParser.ParseFrame(pTempData, entry.dwChunkLength))
{
decoderConfigLen = m_seqHParser.VisualObjSeq().obj_len+m_seqHParser.Pic_Parameter_Set().obj_len;
pDecoderConfig = new BYTE[decoderConfigLen];
memcpy(pDecoderConfig, m_seqHParser.VisualObjSeq().obj, m_seqHParser.VisualObjSeq().obj_len);
if (m_seqHParser.Pic_Parameter_Set().obj_len)
memcpy(pDecoderConfig+m_seqHParser.VisualObjSeq().obj_len, m_seqHParser.Pic_Parameter_Set().obj, m_seqHParser.Pic_Parameter_Set().obj_len);
long newsampleLen = decoderConfigLen+len;
CComPtr<IMediaSample> pNewSample;
HRESULT hr = GetNewSample(&pNewSample, newsampleLen);
ASSERT(hr == S_OK);
if (SUCCEEDED(hr))
{
CComPtr<IMediaSample2> pSmp = NULL;
pSample->QueryInterface(&pSmp);
AM_SAMPLE2_PROPERTIES props_in = {0};
hr = pSmp->GetProperties(sizeof( AM_SAMPLE2_PROPERTIES ), (BYTE*)&props_in);
CComPtr<IMediaSample2> pSmp2 = NULL;
pNewSample->QueryInterface(&pSmp2);
AM_SAMPLE2_PROPERTIES props_out = {0};
hr = pSmp2->GetProperties(sizeof( AM_SAMPLE2_PROPERTIES ), (BYTE*)&props_out);
props_out.dwTypeSpecificFlags = props_in.dwTypeSpecificFlags;
props_out.dwSampleFlags = props_in.dwSampleFlags;
props_out.lActual = decoderConfigLen+len;
props_out.tStart = props_in.tStart;
props_out.tStop = props_in.tStop;
props_out.dwStreamId = props_in.dwStreamId;
if (props_in.pMediaType)
props_out.pMediaType = CreateMediaType(props_in.pMediaType);
memcpy(props_out.pbBuffer, pDecoderConfig, decoderConfigLen);
memcpy(props_out.pbBuffer+decoderConfigLen, pBuffer, len);
hr = pSmp2->SetProperties(sizeof( AM_SAMPLE2_PROPERTIES ), (BYTE*)&props_out);
pSampleDeliver = pNewSample;
}
delete pDecoderConfig;
}
delete pTempData;
}
}
}
return CAVIOutputPin::Deliver(pSampleDeliver);
}
示例13: XlLibraryInitialize
bool XlLibraryInitialize(XlAddInExportInfo* pExportInfo)
{
HRESULT hr;
CComPtr<ICorRuntimeHost> pHost;
hr = LoadClr20(&pHost);
if (FAILED(hr) || pHost == NULL)
{
// LoadClr20 shows diagnostic MessageBoxes if needed.
// Perhaps remember that we are not loaded?
return 0;
}
// If all is fine now, also start the CLR (always safe to do again.
hr = pHost->Start();
if (FAILED(hr))
{
ShowMessage(IDS_MSG_HEADER_NEEDCLR20,
IDS_MSG_BODY_HOSTSTART,
IDS_MSG_FOOTER_UNEXPECTED,
hr);
return 0;
}
CString addInFullPath = AddInFullPath();
CPath xllDirectory(addInFullPath);
xllDirectory.RemoveFileSpec();
CComPtr<IUnknown> pAppDomainSetupUnk;
hr = pHost->CreateDomainSetup(&pAppDomainSetupUnk);
if (FAILED(hr) || pAppDomainSetupUnk == NULL)
{
ShowMessage(IDS_MSG_HEADER_APPDOMAIN,
IDS_MSG_BODY_APPDOMAINSETUP,
IDS_MSG_FOOTER_UNEXPECTED,
hr);
return 0;
}
CComQIPtr<IAppDomainSetup> pAppDomainSetup = pAppDomainSetupUnk;
hr = pAppDomainSetup->put_ApplicationBase(CComBSTR(xllDirectory));
if (FAILED(hr))
{
ShowMessage(IDS_MSG_HEADER_APPDOMAIN,
IDS_MSG_BODY_APPLICATIONBASE,
IDS_MSG_FOOTER_UNEXPECTED,
hr);
return 0;
}
CComBSTR configFileName = addInFullPath;
configFileName.Append(L".config");
pAppDomainSetup->put_ConfigurationFile(configFileName);
CComBSTR appDomainName = L"ExcelDna: ";
appDomainName.Append(addInFullPath);
pAppDomainSetup->put_ApplicationName(appDomainName);
IUnknown *pAppDomainUnk = NULL;
hr = pHost->CreateDomainEx(appDomainName, pAppDomainSetupUnk, 0, &pAppDomainUnk);
if (FAILED(hr) || pAppDomainUnk == NULL)
{
ShowMessage(IDS_MSG_HEADER_APPDOMAIN,
IDS_MSG_BODY_APPDOMAIN,
IDS_MSG_FOOTER_UNEXPECTED,
hr);
return 0;
}
CComQIPtr<_AppDomain> pAppDomain(pAppDomainUnk);
// Load plan for ExcelDna.Loader:
// Try AppDomain.Load with the name ExcelDna.Loader.
// Then if it does not work, we will try to load from a known resource in the .xll.
CComPtr<_Assembly> pExcelDnaLoaderAssembly;
hr = pAppDomain->Load_2(CComBSTR(L"ExcelDna.Loader"), &pExcelDnaLoaderAssembly);
if (FAILED(hr) || pExcelDnaLoaderAssembly == NULL)
{
HRSRC hResInfoLoader = FindResource(hModuleCurrent, L"EXCELDNA_LOADER", L"ASSEMBLY");
if (hResInfoLoader == NULL)
{
ShowMessage(IDS_MSG_HEADER_APPDOMAIN,
IDS_MSG_BODY_MISSINGEXCELDNALOADER,
IDS_MSG_FOOTER_UNEXPECTED,
hr);
return 0;
}
HGLOBAL hLoader = LoadResource(hModuleCurrent, hResInfoLoader);
void* pLoader = LockResource(hLoader);
ULONG sizeLoader = (ULONG)SizeofResource(hModuleCurrent, hResInfoLoader);
CComSafeArray<BYTE> bytesLoader;
bytesLoader.Add(sizeLoader, (byte*)pLoader);
hr = pAppDomain->Load_3(bytesLoader, &pExcelDnaLoaderAssembly);
if (FAILED(hr))
{
//.........这里部分代码省略.........
示例14: ENSURE
HRESULT
VideoDecoder::SampleToVideoFrame(IMFSample* aSample,
int32_t aWidth,
int32_t aHeight,
int32_t aStride,
GMPVideoi420Frame* aVideoFrame)
{
ENSURE(aSample != nullptr, E_POINTER);
ENSURE(aVideoFrame != nullptr, E_POINTER);
HRESULT hr;
CComPtr<IMFMediaBuffer> mediaBuffer;
// Must convert to contiguous mediaBuffer to use IMD2DBuffer interface.
hr = aSample->ConvertToContiguousBuffer(&mediaBuffer);
ENSURE(SUCCEEDED(hr), hr);
// Try and use the IMF2DBuffer interface if available, otherwise fallback
// to the IMFMediaBuffer interface. Apparently IMF2DBuffer is more efficient,
// but only some systems (Windows 8?) support it.
BYTE* data = nullptr;
LONG stride = 0;
CComPtr<IMF2DBuffer> twoDBuffer;
hr = mediaBuffer->QueryInterface(static_cast<IMF2DBuffer**>(&twoDBuffer));
if (SUCCEEDED(hr)) {
hr = twoDBuffer->Lock2D(&data, &stride);
ENSURE(SUCCEEDED(hr), hr);
} else {
hr = mediaBuffer->Lock(&data, NULL, NULL);
ENSURE(SUCCEEDED(hr), hr);
stride = aStride;
}
// The V and U planes are stored 16-row-aligned, so we need to add padding
// to the row heights to ensure the Y'CbCr planes are referenced properly.
// YV12, planar format: [YYYY....][VVVV....][UUUU....]
// i.e., Y, then V, then U.
uint32_t padding = 0;
if (aHeight % 16 != 0) {
padding = 16 - (aHeight % 16);
}
int32_t y_size = stride * (aHeight + padding);
int32_t v_size = stride * (aHeight + padding) / 4;
int32_t halfStride = (stride + 1) / 2;
int32_t halfHeight = (aHeight + 1) / 2;
auto err = aVideoFrame->CreateEmptyFrame(stride, aHeight, stride, halfStride, halfStride);
ENSURE(GMP_SUCCEEDED(err), E_FAIL);
err = aVideoFrame->SetWidth(aWidth);
ENSURE(GMP_SUCCEEDED(err), E_FAIL);
err = aVideoFrame->SetHeight(aHeight);
ENSURE(GMP_SUCCEEDED(err), E_FAIL);
uint8_t* outBuffer = aVideoFrame->Buffer(kGMPYPlane);
ENSURE(outBuffer != nullptr, E_FAIL);
assert(aVideoFrame->AllocatedSize(kGMPYPlane) >= stride*aHeight);
memcpy(outBuffer, data, stride*aHeight);
outBuffer = aVideoFrame->Buffer(kGMPUPlane);
ENSURE(outBuffer != nullptr, E_FAIL);
assert(aVideoFrame->AllocatedSize(kGMPUPlane) >= halfStride*halfHeight);
memcpy(outBuffer, data+y_size, halfStride*halfHeight);
outBuffer = aVideoFrame->Buffer(kGMPVPlane);
ENSURE(outBuffer != nullptr, E_FAIL);
assert(aVideoFrame->AllocatedSize(kGMPVPlane) >= halfStride*halfHeight);
memcpy(outBuffer, data + y_size + v_size, halfStride*halfHeight);
if (twoDBuffer) {
twoDBuffer->Unlock2D();
} else {
mediaBuffer->Unlock();
}
LONGLONG hns = 0;
hr = aSample->GetSampleTime(&hns);
ENSURE(SUCCEEDED(hr), hr);
aVideoFrame->SetTimestamp(HNsToUsecs(hns));
hr = aSample->GetSampleDuration(&hns);
ENSURE(SUCCEEDED(hr), hr);
aVideoFrame->SetDuration(HNsToUsecs(hns));
return S_OK;
}
示例15: DeliverNewSegment
DWORD CAVIOutputPin::ThreadProc()
{
CAVIScanner* scanner = m_pSplitter->GetAVIScanner();
bool bFirst = true;
REFERENCE_TIME tStart = 0;
REFERENCE_TIME tStop = 0;
REFERENCE_TIME duration = 0;
bool bDeliverEOS = true;
DWORD req = 0;
HRESULT hr = S_OK;
REFERENCE_TIME tSeekStart = 0;
REFERENCE_TIME tSeekStop = 0;
double dRate;
m_pSplitter->GetSeekingParams(&tSeekStart, &tSeekStop, &dRate);
DeliverNewSegment(tSeekStart, tSeekStop, dRate);
int startPos = GetIndexStartPosEntry(tSeekStart);
for (int i = startPos; i < m_pIndex->size(); i++)
{
const INDEXENTRY& entry = (*m_pIndex)[i];
if (!entry.dwChunkLength)
continue;
CComPtr<IMediaSample> pSample;
hr = GetNewSample(&pSample, entry.dwChunkLength);
// Break out without calling EndOfStream if we're asked to
// do something different
if (CheckRequest(&req))
{
bDeliverEOS = false;
break;
}
if (bFirst)
{
bFirst = false;
pSample->SetDiscontinuity(TRUE);
}
if (entry.dwFlags & AVIIF_INDEX)
pSample->SetSyncPoint(TRUE);
tStart = GetCurTime(i) - tSeekStart;
tStop = GetCurTime(i+1)- tSeekStart;
pSample->SetTime(&tStart,&tStop);
if (tStart < 0 && tStop <= 0)
pSample->SetPreroll(TRUE);
BYTE* pbData = 0;
pSample->GetPointer(&pbData);
scanner->ReadData(entry.chunkOffset, entry.dwChunkLength, pbData);
hr = Deliver(pSample);
if (FAILED(hr) || hr == S_FALSE)
{
while(true)
{
if (CheckRequest(&req))
{
bDeliverEOS = false;
break;
}
Sleep(100);
}
}
}
if (bDeliverEOS)
DeliverEndOfStream();
req =GetRequest();
Reply(S_OK);
return 0;
}