示例#1
1
//---------------------------------------------------------------------------
// UnregisterServer
//---------------------------------------------------------------------------
BOOL UnregisterServer(CLSID clsid, LPTSTR lpszTitle) {
  TCHAR szCLSID[GUID_SIZE + 1];
  TCHAR szCLSIDKey[GUID_SIZE + 32];
  TCHAR szKeyTemp[MAX_PATH + GUID_SIZE];
  LPWSTR pwsz;

  StringFromIID(clsid, &pwsz);
  if(pwsz) {
#ifdef UNICODE
    lstrcpy(szCLSID, pwsz);
#else
    WideCharToMultiByte(CP_ACP, 0, pwsz, -1, szCLSID, ARRAYSIZE(szCLSID), NULL, NULL);
#endif
    //free the string
    LPMALLOC pMalloc;
    CoGetMalloc(1, &pMalloc);
    pMalloc->Free(pwsz);
    pMalloc->Release();
  }

  lstrcpy(szCLSIDKey, TEXT("CLSID\\"));
  lstrcat(szCLSIDKey, szCLSID);

  wsprintf(szKeyTemp, TEXT("*\\shellex\\ContextMenuHandlers\\%s"), lpszTitle);
  RegDeleteKey(HKEY_CLASSES_ROOT, szKeyTemp);

  wsprintf(szKeyTemp, TEXT("%s\\%s"), szCLSIDKey, TEXT("InprocServer32"));
  RegDeleteKey(HKEY_CLASSES_ROOT, szKeyTemp);
  RegDeleteKey(HKEY_CLASSES_ROOT, szCLSIDKey);

  return TRUE;
}
void DirectShowAudioEndpointControl::updateEndpoints()
{
    IMalloc *oleMalloc = 0;
    if (m_deviceEnumerator && CoGetMalloc(1, &oleMalloc) == S_OK) {
        IEnumMoniker *monikers = 0;

        if (m_deviceEnumerator->CreateClassEnumerator(
                CLSID_AudioRendererCategory, &monikers, 0) == S_OK) {
            for (IMoniker *moniker = 0; monikers->Next(1, &moniker, 0) == S_OK; moniker->Release()) {
                OLECHAR *string = 0;
                if (moniker->GetDisplayName(m_bindContext, 0, &string) == S_OK) {
                    QString deviceId = QString::fromWCharArray(string);
                    oleMalloc->Free(string);

                    moniker->AddRef();
                    m_devices.insert(deviceId, moniker);

                    if (m_defaultEndpoint.isEmpty()
                            || deviceId.endsWith(QLatin1String("Default DirectSound Device"))) {
                        m_defaultEndpoint = deviceId;
                    }
                }
            }
            monikers->Release();
        }
        oleMalloc->Release();
    }
}
示例#3
0
文件: kdecm.cpp 项目: KDE/kde-runtime
//---------------------------------------------------------------------------
// UnregisterServer
//---------------------------------------------------------------------------
BOOL UnregisterServer(CLSID clsid, LPTSTR lpszTitle)
{
/*!
 * This function removes the keys from registry
 * NOTE: we can do this better with Qt
 */

    TCHAR szCLSID[GUID_SIZE + 1];
    TCHAR szCLSIDKey[GUID_SIZE + 32];
    TCHAR szKeyTemp[MAX_PATH + GUID_SIZE];
    LPTSTR pwsz;

    StringFromIID(clsid, &pwsz);
    if(pwsz) {
        lstrcpy(szCLSID, pwsz);
        //free the string
        LPMALLOC pMalloc;
        CoGetMalloc(1, &pMalloc);
        pMalloc->Free(pwsz);
        pMalloc->Release();
    }

    lstrcpy(szCLSIDKey, TEXT("CLSID\\"));
    lstrcat(szCLSIDKey, szCLSID);

    wsprintf(szKeyTemp, TEXT("*\\shellex\\ContextMenuHandlers\\%s"), lpszTitle);
    RegDeleteKey(HKEY_CLASSES_ROOT, szKeyTemp);

    wsprintf(szKeyTemp, TEXT("%s\\%s"), szCLSIDKey, TEXT("InprocServer32"));
    RegDeleteKey(HKEY_CLASSES_ROOT, szKeyTemp);
    RegDeleteKey(HKEY_CLASSES_ROOT, szCLSIDKey);

    return TRUE;
}
示例#4
0
int BrowseForFolder(HWND hwnd, char *szPath)
{
	int result = 0;
	LPMALLOC pMalloc;

	if (SUCCEEDED(CoGetMalloc(1, &pMalloc))) {
		ptrT tszPath(mir_a2t(szPath));
		BROWSEINFO bi = { 0 };
		bi.hwndOwner = hwnd;
		bi.pszDisplayName = tszPath;
		bi.lpszTitle = TranslateT("Select Folder");
		bi.ulFlags = BIF_EDITBOX | BIF_RETURNONLYFSDIRS;				// Use this combo instead of BIF_USENEWUI
		bi.lParam = (LPARAM)szPath;

		ITEMIDLIST *pidlResult = SHBrowseForFolder(&bi);
		if (pidlResult) {
			SHGetPathFromIDListA(pidlResult, szPath);
			mir_strcat(szPath, "\\");
			result = 1;
		}
		pMalloc->Free(pidlResult);
		pMalloc->Release();
	}

	return result;
}
示例#5
0
VOID
OleStdEnumFmtEtc_Destroy(LPOLESTDENUMFMTETC lpEF)
//----------------------------------------------------------------------------
//
//----------------------------------------------------------------------------
{
#ifdef Q_OS_TEMP
    return;
#else
    LPMALLOC lpMalloc=NULL;
    ULONG i;

    if (lpEF != NULL) {

        if (CoGetMalloc(MEMCTX_TASK, &lpMalloc) == NOERROR) {

            /* OLE2NOTE: we MUST free any memory that was allocated for
            **    TARGETDEVICES contained within the FORMATETC elements.
            */
            for (i=0; i<lpEF->m_nCount; i++) {
                OleStdFree(lpEF->m_lpEtc[i].ptd);
            }

            if (lpEF->m_lpEtc != NULL) {
                lpMalloc->lpVtbl->Free(lpMalloc, lpEF->m_lpEtc);
            }

            lpMalloc->lpVtbl->Free(lpMalloc, lpEF);
            lpMalloc->lpVtbl->Release(lpMalloc);
        }
    }
#endif
} /* OleStdEnumFmtEtc_Destroy()
示例#6
0
// Used (by getDeviceModes) to select a device
// so we can list its properties
static IBaseFilter* getDevFilter(QString devName)
{
    IBaseFilter* devFilter = nullptr;
    devName = devName.mid(6); // Remove the "video="
    IMoniker* m = nullptr;

    ICreateDevEnum* devenum = nullptr;
    if (CoCreateInstance(CLSID_SystemDeviceEnum, nullptr, CLSCTX_INPROC_SERVER,
                             IID_ICreateDevEnum, (void**) &devenum) != S_OK)
        return devFilter;

    IEnumMoniker* classenum = nullptr;
    if (devenum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory,
                                (IEnumMoniker**)&classenum, 0) != S_OK)
        return devFilter;

    while (classenum->Next(1, &m, nullptr) == S_OK)
    {
        LPMALLOC coMalloc = nullptr;
        IBindCtx* bindCtx = nullptr;
        LPOLESTR olestr = nullptr;
        char* devIdString;

        if (CoGetMalloc(1, &coMalloc) != S_OK)
            goto fail;
        if (CreateBindCtx(0, &bindCtx) != S_OK)
            goto fail;

        if (m->GetDisplayName(bindCtx, nullptr, &olestr) != S_OK)
            goto fail;
        devIdString = wcharToUtf8(olestr);

        // replace ':' with '_' since FFmpeg uses : to delimitate sources
        for (unsigned i = 0; i < strlen(devIdString); i++)
            if (devIdString[i] == ':')
                devIdString[i] = '_';

        if (devName != devIdString)
            goto fail;

        if (m->BindToObject(0, 0, IID_IBaseFilter, (void**)&devFilter) != S_OK)
            goto fail;

fail:
        if (olestr && coMalloc)
            coMalloc->Free(olestr);
        if (bindCtx)
            bindCtx->Release();
        delete[] devIdString;
        m->Release();
    }
    classenum->Release();

    if (!devFilter)
        qWarning() << "Could't find the device "<<devName;

    return devFilter;
}
示例#7
0
//---------------------------------------------------------------------------
// RegisterServer
//---------------------------------------------------------------------------
BOOL RegisterServer(CLSID clsid, LPTSTR lpszTitle) {
  int      i;
  HKEY     hKey;
  LRESULT  lResult;
  DWORD    dwDisp;
  TCHAR    szSubKey[MAX_PATH];
  TCHAR    szCLSID[MAX_PATH];
  TCHAR    szModule[MAX_PATH];
  LPWSTR   pwsz;

  if (!CheckNpp()) {
    MsgBoxError(TEXT("To register the Notepad++ context menu extension,\r\ninstall nppcm.dll in the same directory than Notepad++.exe."));
    return FALSE;
  }

  StringFromIID(clsid, &pwsz);
  if(pwsz) {
#ifdef UNICODE
    lstrcpy(szCLSID, pwsz);
#else
    WideCharToMultiByte(CP_ACP, 0, pwsz, -1, szCLSID, ARRAYSIZE(szCLSID), NULL, NULL);
#endif
    //free the string
    LPMALLOC pMalloc;
    CoGetMalloc(1, &pMalloc);
    pMalloc->Free(pwsz);
    pMalloc->Release();
  }

  //get this app's path and file name
  GetModuleFileName(_hModule, szModule, MAX_PATH);

  DOREGSTRUCT ClsidEntries[] = {
    HKEY_CLASSES_ROOT,   TEXT("CLSID\\%s"),                              NULL,                   lpszTitle,
    HKEY_CLASSES_ROOT,   TEXT("CLSID\\%s\\InprocServer32"),              NULL,                   szModule,
    HKEY_CLASSES_ROOT,   TEXT("CLSID\\%s\\InprocServer32"),              TEXT("ThreadingModel"), TEXT("Apartment"),
    HKEY_CLASSES_ROOT,   TEXT("*\\shellex\\ContextMenuHandlers\\Notepad++"), NULL,                   szCLSID,
    NULL,                NULL,                                           NULL,                   NULL
  };

  // Register the CLSID entries
  for(i = 0; ClsidEntries[i].hRootKey; i++) {
    // Create the sub key string - for this case, insert the file extension
    wsprintf(szSubKey, ClsidEntries[i].szSubKey, szCLSID);
    lResult = RegCreateKeyEx(ClsidEntries[i].hRootKey, szSubKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, &dwDisp);
    if(NOERROR == lResult) {
      TCHAR szData[MAX_PATH];
      // If necessary, create the value string
      wsprintf(szData, ClsidEntries[i].szData, szModule);
      lResult = RegSetValueEx(hKey, ClsidEntries[i].lpszValueName, 0, REG_SZ, (LPBYTE)szData, (lstrlen(szData) + 1) * sizeof(TCHAR));
      RegCloseKey(hKey);
    }
    else
      return FALSE;
  }
  return TRUE;
}
示例#8
0
OleStdEnumFmtEtc_Create(ULONG nCount, LPFORMATETC lpEtc)
//----------------------------------------------------------------------------
//
//----------------------------------------------------------------------------
{
#ifdef Q_OS_TEMP
    return NULL;
#else
    LPMALLOC lpMalloc=NULL;
    DWORD dwSize;
    ULONG i;
    HRESULT hRes;
    LPOLESTDENUMFMTETC lpEF;

    hRes = CoGetMalloc(MEMCTX_TASK, &lpMalloc);
    if (hRes != NOERROR) {
        return NULL;
    }

    lpEF = (LPOLESTDENUMFMTETC)lpMalloc->lpVtbl->Alloc(lpMalloc,
            sizeof(OLESTDENUMFMTETC));
    if (lpEF == NULL) {
        goto errReturn;
    }

    lpEF->lpVtbl = &g_EnumFORMATETCVtbl;
    lpEF->m_dwRefs = 1;
    lpEF->m_nCount = nCount;
    lpEF->m_nIndex = 0;

    dwSize = sizeof(FORMATETC) * lpEF->m_nCount;

    lpEF->m_lpEtc = (LPFORMATETC)lpMalloc->lpVtbl->Alloc(lpMalloc, dwSize);
    if (lpEF->m_lpEtc == NULL)
        goto errReturn;

    lpMalloc->lpVtbl->Release(lpMalloc);

    for (i=0; i<nCount; i++) {
        OleStdCopyFormatEtc(
            (LPFORMATETC)&(lpEF->m_lpEtc[i]), (LPFORMATETC)&(lpEtc[i]));
    }

    return (LPENUMFORMATETC)lpEF;

errReturn:
    if (lpEF != NULL)
        lpMalloc->lpVtbl->Free(lpMalloc, lpEF);

    if (lpMalloc != NULL)
        lpMalloc->lpVtbl->Release(lpMalloc);

    return NULL;
#endif
} /* OleStdEnumFmtEtc_Create()
示例#9
0
void allocIMalloc(bool bFree)
{
    IMalloc *imalloc = NULL;
    HRESULT hr = CoGetMalloc(1, &imalloc);
    assert(SUCCEEDED(hr));
    int* leaked_memory = static_cast<int*>(imalloc->Alloc(34));
    if (bFree)
    {
        imalloc->Free(leaked_memory);
    }
}
示例#10
0
static NTSTATUS EnumRunningObjectTable(
    _In_ PVOID ThreadParam
    )
{
    IRunningObjectTable* iRunningObjectTable = NULL;
    IEnumMoniker* iEnumMoniker = NULL;
    IMoniker* iMoniker = NULL;
    IBindCtx* iBindCtx = NULL;
    IMalloc* iMalloc = NULL;
    ULONG count = 0;

    HWND listViewHandle = (HWND)ThreadParam;

    if (!SUCCEEDED(CoGetMalloc(1, &iMalloc)))
        return STATUS_INSUFFICIENT_RESOURCES;

    // Query the running object table address
    if (SUCCEEDED(GetRunningObjectTable(0, &iRunningObjectTable)))
    {
        // Enum the objects registered
        if (SUCCEEDED(IRunningObjectTable_EnumRunning(iRunningObjectTable, &iEnumMoniker)))
        {
            while (IEnumMoniker_Next(iEnumMoniker, 1, &iMoniker, &count) == S_OK)
            {
                if (SUCCEEDED(CreateBindCtx(0, &iBindCtx)))
                {
                    OLECHAR* displayName = NULL;

                    // Query the object name
                    if (SUCCEEDED(IMoniker_GetDisplayName(iMoniker, iBindCtx, NULL, &displayName)))
                    {
                        // Set the items name column
                        PhAddListViewItem(listViewHandle, MAXINT, displayName, NULL);

                        // Free the object name
                        IMalloc_Free(iMalloc, displayName);
                    }

                    IBindCtx_Release(iBindCtx);
                }

                IEnumMoniker_Release(iMoniker);
            }

            IEnumMoniker_Release(iEnumMoniker);
        }

        IRunningObjectTable_Release(iRunningObjectTable);
    }

    IMalloc_Release(iMalloc);

    return STATUS_SUCCESS;
}
示例#11
0
// CoTaskMemFree uses the default OLE allocator to free a block of
// memory previously allocated through a call to CoTaskMemAlloc
void NEAR
CoTaskMemFree(LPVOID lpv)
{
	if (lpv) {
		LPMALLOC	pMalloc;
	
		if (SUCCEEDED(CoGetMalloc(MEMCTX_TASK, &pMalloc))) {
			pMalloc->Free(lpv);
			pMalloc->Release();
		}
	}
}
示例#12
0
// CoTaskMemRealloc changes the size of a previously allocated memory
// block in the same way that IMalloc::Realloc does
LPVOID NEAR
CoTaskMemRealloc(LPVOID lpv, ULONG cb)
{
	LPMALLOC	pMalloc;
	
	if (SUCCEEDED(CoGetMalloc(MEMCTX_TASK, &pMalloc))) {
		lpv = pMalloc->Realloc(lpv, cb);
		pMalloc->Release();
		return lpv;
	}

	return NULL;
}
示例#13
0
void
CPropertyPageEx::operator delete(LPVOID lpv)
{
#ifdef _WIN32
	HeapFree(GetProcessHeap(), 0, lpv);
#else
	LPMALLOC	pMalloc;

	if (SUCCEEDED(CoGetMalloc(MEMCTX_TASK, &pMalloc))) {
		pMalloc->Free(lpv);
		pMalloc->Release();
	}
#endif
}
示例#14
0
static void set_buffer(LPWSTR *buffer, LPCWSTR string)
{
    static const WCHAR empty_string[] = {0};
    IMalloc *malloc;
    ULONG cb;

    if (string == NULL)
        string = empty_string;
    CoGetMalloc(1, &malloc);

    cb = (strlenW(string) + 1)*sizeof(WCHAR);
    if (*buffer == NULL || cb > IMalloc_GetSize(malloc, *buffer))
        *buffer = IMalloc_Realloc(malloc, *buffer, cb);
    memcpy(*buffer, string, cb);
}
示例#15
0
HRESULT CSoftHIDInputKbdMapper::FinalConstruct()
/*++
Routine Description:
    Overwrites the default FinalConstruct. Creates the default
    properties, gets pointer to COM task memory allocator.

Synchronization: 
    None
 
Arguments:
    None
    
Return Value:
    E_OUTOFMEMORY
        Could not create safearray for Report Descriptor data
    From called function
--*/
{
    BYTE HUGEP* pArrayData = NULL;
    HRESULT     hr = S_OK;

    IfFailHrGo(CoGetMalloc(1, &m_pMalloc));

    // Register notification messages
    IfFailHrGo(RegisterMessage(MSG_KEYTOUCHED, &m_KeyTouchedMsg));
    IfFailHrGo(RegisterMessage(MSG_OUTREPORTREADY, &m_OutReportReadyMsg));

    // Create safearray with Report Descriptor data
    m_psaReportDescriptor = SafeArrayCreateVector(VT_UI1, 0, sizeof(m_ReportDescriptor));
    IfFalseHrGo(NULL != m_psaReportDescriptor, E_OUTOFMEMORY);

    IfFailHrGo(::SafeArrayAccessData(m_psaReportDescriptor, (void HUGEP**)&pArrayData));

    // Copy Report Descriptor data into safearray
    CopyMemory(pArrayData, &m_ReportDescriptor, sizeof(m_ReportDescriptor));

    IfFailHrGo(::SafeArrayUnaccessData(m_psaReportDescriptor));

    // Start internal thread
    IfFailHrGo(CMessageTask::Start(DEFAULT_SYNC_DELAY));

    // Call OnConstruct method of CSoftHIDDevice class
    IfFailHrGo(CSoftHID::OnConstruct(this, m_OutReportReadyMsg));

Exit:
    return hr;

} // CSoftHIDInputKbdMapper::FinalConstruct
示例#16
0
int
main(int argc, char **argv)
{
    void *p;
    com_result_t r;
    int n;
    size_t s;
    IMalloc *allocator;

    (void) argc;
    (void) argv;

    com_init("com.googlecode.libcom.test-1");

    p = CoTaskMemAlloc(64);
    if(NULL == p)
    {
        fprintf(stderr, "Failed to allocate 64 bytes via CoTaskMemAlloc()\n");
        exit(EXIT_FAILURE);
    }
    if(COM_S_OK != (r = CoGetMalloc(1, &allocator)))
    {
        fprintf(stderr, "Failed to obtain reference to task allocator; result = 0x%08x\n", r);
        exit(EXIT_FAILURE);
    }
    if(1 != (n = IMalloc_DidAlloc(allocator, p)))
    {
        if(0 == n)
        {
            fprintf(stderr, "IMalloc::DidAlloc() claims task allocator was not responsible for allocated block\n");
        }
        else
        {
            fprintf(stderr, "IMalloc::DidAlloc() could not determine responsibility for allocated block\n");
        }
        exit(EXIT_FAILURE);
    }
    if(64 != (s = IMalloc_GetSize(allocator, p)))
    {
        fprintf(stderr, "IMalloc::GetSize() returned an incorrect size (%ul bytes)\n", s);
        exit(EXIT_FAILURE);
    }
    IMalloc_Free(allocator, p);
    puts("PASS");

    com_shutdown();
    return 0;
}
示例#17
0
static bool GetFilterGraph(IFilterGraph** ppFG)
{
	if(!ppFG) return(false);

    CComPtr<IRunningObjectTable> pROT;
    if(FAILED(GetRunningObjectTable(0, &pROT)))
		return 1;

	CComPtr<IEnumMoniker> pEM;
	if(FAILED(pROT->EnumRunning(&pEM)))
		return 1;

	CComPtr<IBindCtx> pBindCtx;
	CreateBindCtx(0, &pBindCtx);

	for(CComPtr<IMoniker> pMoniker; S_OK == pEM->Next(1, &pMoniker, NULL); pMoniker = NULL)
	{
		LPOLESTR pDispName = NULL;
		if(FAILED(pMoniker->GetDisplayName(pBindCtx, NULL, &pDispName)))
			continue;

		CStringW strw(pDispName);
		
		CComPtr<IMalloc> pMalloc;
		if(FAILED(CoGetMalloc(1, &pMalloc)))
			continue;
		pMalloc->Free(pDispName);

		if(strw.Find(L"(MPC)") < 0)
			continue;

		CComPtr<IUnknown> pUnk;
		if(S_OK != pROT->GetObject(pMoniker, &pUnk))
			continue;

		CComQIPtr<IFilterGraph> pFG = pUnk;
		if(!pFG)
			continue;

		*ppFG = pFG.Detach();

		break;
	}

	return(!!*ppFG);
}
示例#18
0
HRESULT CSoftKeyboard::FinalConstruct()
/*++
Routine Description:
    Overwrites the default FinalConstruct. Creates the default
    properties, gets pointer to COM task memory allocator.

Synchronization: 
    None
 
Arguments:
    None
    
Return Value:
    From called function
--*/
{
    HRESULT hr = S_OK;
    ISoftKbdTranslator* piDefaultASCIIXlator = NULL;

    // Acquire COM memory management interface
    IfFailHrGo(CoGetMalloc(1, &m_pMalloc));

    // Register notification messages
    IfFailHrGo(RegisterMessage(MSG_KEYPRESSED, &m_KeyPressedMsg));
    IfFailHrGo(RegisterMessage(MSG_KEYRELEASED, &m_KeyReleasedMsg));

    // Construct default translator object
    //pcDefaultASCIIXlator = new CDefaultASCIIXlator();
    hr = CDefaultASCIIXlator::CreateInstance(&piDefaultASCIIXlator);
    IfFailHrGo(hr);

    m_piSoftKbdTranslator = piDefaultASCIIXlator;

    // Set default values to properties
    m_KbdAttributes.usKeyboardMode = KEYBOARD_SCAN_CODE_SET2;

    m_KbdTypematicParam.ulRate = KEYBOARD_TYPEMATIC_RATE_DEFAULT;
    m_KbdTypematicParam.ulDelay = KEYBOARD_TYPEMATIC_DELAY_DEFAULT;
    
    // Start internal thread
    IfFailHrGo(Start(60000));

Exit:
    return hr;

} // CSoftKeyboard::FinalConstruct
示例#19
0
COlePropPage::COlePropPage(CLSID clsidPage, LPUNKNOWN* lpAryUnk, int& count) : CPropertyPage(COlePropPage::IDD),
	m_clsidPage(clsidPage), m_pObject(lpAryUnk)
{
	// Create COM Property page and get IPropertyPage interface
	EnableAutomation();
	HRESULT hRes = E_FAIL;
	m_pPropPage=NULL;
	try {
		hRes = CoCreateInstance( m_clsidPage, NULL, CLSCTX_INPROC, IID_IPropertyPage, (void**)&m_pPropPage );
		if( FAILED( hRes ) )
			AfxThrowOleException( hRes );
		
		hRes = m_pPropPage->SetPageSite( (IPropertyPageSite*) GetInterface( &IID_IPropertyPageSite ) );
		if( FAILED( hRes ) )
			AfxThrowOleException( hRes );
		
		hRes = m_pPropPage->SetObjects( count, m_pObject );
		if( FAILED( hRes ) )
			AfxThrowOleException( hRes );
		
		IMalloc     *pIMalloc;
		if (FAILED(CoGetMalloc(MEMCTX_TASK, &pIMalloc)))
			AfxThrowOleException(E_FAIL);
		
		PROPPAGEINFO* pPPI = (PROPPAGEINFO*) pIMalloc->Alloc(sizeof(PROPPAGEINFO));
		pPPI->cb = sizeof(PROPPAGEINFO);
		hRes = m_pPropPage->GetPageInfo(pPPI);
#ifndef UNICODE
		m_strCaption.Format("%S", pPPI->pszTitle);
#else
		m_strCaption = pPPI->pszTitle;
#endif
		m_psp.pszTitle = m_strCaption;
		m_psp.dwFlags |= PSP_USETITLE;
		m_psp.hIcon = ::LoadIcon(NULL, IDI_QUESTION);
		
		pIMalloc->Free(pPPI);
		pIMalloc->Release();
		
		
	} catch (COleException * e)
	{
		throw (e);
	}
}
示例#20
0
//--------------------------------------------------------------------
// @mfunc COLEDB  
//
// @parm [IN] Test case name
//
//--------------------------------------------------------------------
COLEDB::COLEDB(WCHAR * pwszTestCaseName) : CTestCases(pwszTestCaseName) 
{

	// Init to S_OK and NULL
	m_hr		= S_OK;
	m_pIMalloc	= NULL;
	m_pExtError = NULL;
	m_fLocalize	= FALSE;

	// If we can't get our memory allocator, we're in trouble anyway, so assert
	CoGetMalloc(MEMCTX_TASK, &m_pIMalloc);
	ASSERT(m_pIMalloc);

	//Record if we are called within a TC or standalone object
	m_fInsideTestCase	= TRUE;
	if(pwszTestCaseName == INVALID(WCHAR*))
		m_fInsideTestCase = FALSE;
}
示例#21
0
LPVOID
CPropertyPageEx::operator new(size_t size)
{
#ifdef _WIN32
	return HeapAlloc(GetProcessHeap(), 0, size);
#else
	LPMALLOC	pMalloc;

	if (SUCCEEDED(CoGetMalloc(MEMCTX_TASK, &pMalloc))) {
		LPVOID	lpv = pMalloc->Alloc(size);

		pMalloc->Release();
		return lpv;
	}

	return NULL;
#endif
}
示例#22
0
/* OleStdMalloc
** ------------
**    allocate memory using the currently active IMalloc* allocator
*/
STDAPI_(LPVOID) OleStdMalloc(ULONG ulSize)
{
#ifdef Q_OS_TEMP
    return NULL;
#else
    LPVOID pout;
    LPMALLOC pmalloc;

    if (CoGetMalloc(MEMCTX_TASK, &pmalloc) != NOERROR) {
        return NULL;
    }

    pout = (LPVOID)pmalloc->lpVtbl->Alloc(pmalloc, ulSize);

    if (pmalloc != NULL) {
        pmalloc->lpVtbl->Release(pmalloc);
    }

    return pout;
#endif
}
示例#23
0
/* OleStdFree
** ----------
**    free memory using the currently active IMalloc* allocator
*/
STDAPI_(void) OleStdFree(LPVOID pmem)
{
#ifdef Q_OS_TEMP
    return;
#else
    LPMALLOC pmalloc;

    if (pmem == NULL)
        return;

    if (CoGetMalloc(MEMCTX_TASK, &pmalloc) != NOERROR) {
        return;
    }

    pmalloc->lpVtbl->Free(pmalloc, pmem);

    if (pmalloc != NULL) {
        pmalloc->lpVtbl->Release(pmalloc);
    }
#endif
}
HRESULT C$$Safe_root$$PropPage::GetPageInfo( LPPROPPAGEINFO pPageInfo )
{
	IMalloc* pIMalloc;
	if (FAILED( CoGetMalloc( MEMCTX_TASK, &pIMalloc ) ))
		return E_FAIL;

	pPageInfo->pszTitle = (LPOLESTR)pIMalloc->Alloc( 256 );

	pIMalloc->Release();

	if (!pPageInfo->pszTitle)
		return E_OUTOFMEMORY;

	static const char szTitle[] = "$$Safe_root$$";
	mbstowcs( pPageInfo->pszTitle, szTitle, strlen( szTitle ) );

	// Populate the page info structure
	pPageInfo->cb					= sizeof(PROPPAGEINFO);
	pPageInfo->size.cx      = 100;
	pPageInfo->size.cy      = 100;
	pPageInfo->pszDocString = NULL;
	pPageInfo->pszHelpFile  = NULL;
	pPageInfo->dwHelpContext= 0;

	// Create the property page in order to determine its size
	HWND const hWnd = CreateDialogParam( theApp.m_hInstance, MAKEINTRESOURCE( IDD_PROPPAGE ), 
													 ::GetDesktopWindow(), DialogProc, 0 );
	if (hWnd)
	{
		// Get the dialog size and destroy the window
		RECT rc;
		::GetWindowRect( hWnd, &rc );
		pPageInfo->size.cx = rc.right - rc.left;
		pPageInfo->size.cy = rc.bottom - rc.top;
		::DestroyWindow( hWnd );
	}

	return S_OK;
}
示例#25
0
文件: tkWinSend.c 项目: dgsb/tk
int
TkGetInterpNames(
    Tcl_Interp *interp,		/* Interpreter for returning a result. */
    Tk_Window tkwin)		/* Window whose display is to be used for the
				 * lookup. */
{
#ifndef TK_SEND_ENABLED_ON_WINDOWS
    /*
     * Temporarily disabled for bug #858822
     */

    return TCL_OK;
#else /* TK_SEND_ENABLED_ON_WINDOWS */

    LPRUNNINGOBJECTTABLE pROT = NULL;
    LPCOLESTR oleszStub = TKWINSEND_REGISTRATION_BASE;
    HRESULT hr = S_OK;
    Tcl_Obj *objList = NULL;
    int result = TCL_OK;

    hr = GetRunningObjectTable(0, &pROT);
    if (SUCCEEDED(hr)) {
	IBindCtx* pBindCtx = NULL;
	objList = Tcl_NewListObj(0, NULL);
	hr = CreateBindCtx(0, &pBindCtx);

	if (SUCCEEDED(hr)) {
	    IEnumMoniker* pEnum;

	    hr = pROT->lpVtbl->EnumRunning(pROT, &pEnum);
	    if (SUCCEEDED(hr)) {
		IMoniker* pmk = NULL;

		while (pEnum->lpVtbl->Next(pEnum, 1, &pmk, NULL) == S_OK) {
		    LPOLESTR olestr;

		    hr = pmk->lpVtbl->GetDisplayName(pmk, pBindCtx, NULL,
			    &olestr);
		    if (SUCCEEDED(hr)) {
			IMalloc *pMalloc = NULL;

			if (wcsncmp(olestr, oleszStub,
				wcslen(oleszStub)) == 0) {
			    LPOLESTR p = olestr + wcslen(oleszStub);

			    if (*p) {
				result = Tcl_ListObjAppendElement(interp,
					objList, Tcl_NewUnicodeObj(p + 1, -1));
			    }
			}

			hr = CoGetMalloc(1, &pMalloc);
			if (SUCCEEDED(hr)) {
			    pMalloc->lpVtbl->Free(pMalloc, (void*)olestr);
			    pMalloc->lpVtbl->Release(pMalloc);
			}
		    }
		    pmk->lpVtbl->Release(pmk);
		}
		pEnum->lpVtbl->Release(pEnum);
	    }
	    pBindCtx->lpVtbl->Release(pBindCtx);
	}
	pROT->lpVtbl->Release(pROT);
    }

    if (FAILED(hr)) {
	/*
	 * Expire the list if set.
	 */

	if (objList != NULL) {
	    Tcl_DecrRefCount(objList);
	}
	Tcl_SetObjResult(interp, Win32ErrorObj(hr));
	result = TCL_ERROR;
    }

    if (result == TCL_OK) {
	Tcl_SetObjResult(interp, objList);
    }

    return result;
#endif /* TK_SEND_ENABLED_ON_WINDOWS */
}
示例#26
0
文件: dshow.c 项目: 3688/FFmpeg
/**
 * Cycle through available devices using the device enumerator devenum,
 * retrieve the device with type specified by devtype and return the
 * pointer to the object found in *pfilter.
 * If pfilter is NULL, list all device names.
 */
static int
dshow_cycle_devices(AVFormatContext *avctx, ICreateDevEnum *devenum,
                    enum dshowDeviceType devtype, enum dshowSourceFilterType sourcetype, IBaseFilter **pfilter)
{
    struct dshow_ctx *ctx = avctx->priv_data;
    IBaseFilter *device_filter = NULL;
    IEnumMoniker *classenum = NULL;
    IMoniker *m = NULL;
    const char *device_name = ctx->device_name[devtype];
    int skip = (devtype == VideoDevice) ? ctx->video_device_number
                                        : ctx->audio_device_number;
    int r;

    const GUID *device_guid[2] = { &CLSID_VideoInputDeviceCategory,
                                   &CLSID_AudioInputDeviceCategory };
    const char *devtypename = (devtype == VideoDevice) ? "video" : "audio only";
    const char *sourcetypename = (sourcetype == VideoSourceDevice) ? "video" : "audio";

    r = ICreateDevEnum_CreateClassEnumerator(devenum, device_guid[sourcetype],
                                             (IEnumMoniker **) &classenum, 0);
    if (r != S_OK) {
        av_log(avctx, AV_LOG_ERROR, "Could not enumerate %s devices (or none found).\n",
               devtypename);
        return AVERROR(EIO);
    }

    while (!device_filter && IEnumMoniker_Next(classenum, 1, &m, NULL) == S_OK) {
        IPropertyBag *bag = NULL;
        char *friendly_name = NULL;
        char *unique_name = NULL;
        VARIANT var;
        IBindCtx *bind_ctx = NULL;
        LPOLESTR olestr = NULL;
        LPMALLOC co_malloc = NULL;
        int i;

        r = CoGetMalloc(1, &co_malloc);
        if (r != S_OK)
            goto fail1;
        r = CreateBindCtx(0, &bind_ctx);
        if (r != S_OK)
            goto fail1;
        /* GetDisplayname works for both video and audio, DevicePath doesn't */
        r = IMoniker_GetDisplayName(m, bind_ctx, NULL, &olestr);
        if (r != S_OK)
            goto fail1;
        unique_name = dup_wchar_to_utf8(olestr);
        /* replace ':' with '_' since we use : to delineate between sources */
        for (i = 0; i < strlen(unique_name); i++) {
            if (unique_name[i] == ':')
                unique_name[i] = '_';
        }

        r = IMoniker_BindToStorage(m, 0, 0, &IID_IPropertyBag, (void *) &bag);
        if (r != S_OK)
            goto fail1;

        var.vt = VT_BSTR;
        r = IPropertyBag_Read(bag, L"FriendlyName", &var, NULL);
        if (r != S_OK)
            goto fail1;
        friendly_name = dup_wchar_to_utf8(var.bstrVal);

        if (pfilter) {
            if (strcmp(device_name, friendly_name) && strcmp(device_name, unique_name))
                goto fail1;

            if (!skip--) {
                r = IMoniker_BindToObject(m, 0, 0, &IID_IBaseFilter, (void *) &device_filter);
                if (r != S_OK) {
                    av_log(avctx, AV_LOG_ERROR, "Unable to BindToObject for %s\n", device_name);
                    goto fail1;
                }
            }
        } else {
            av_log(avctx, AV_LOG_INFO, " \"%s\"\n", friendly_name);
            av_log(avctx, AV_LOG_INFO, "    Alternative name \"%s\"\n", unique_name);
        }

fail1:
        if (olestr && co_malloc)
            IMalloc_Free(co_malloc, olestr);
        if (bind_ctx)
            IBindCtx_Release(bind_ctx);
        av_free(friendly_name);
        av_free(unique_name);
        if (bag)
            IPropertyBag_Release(bag);
        IMoniker_Release(m);
    }

    IEnumMoniker_Release(classenum);

    if (pfilter) {
        if (!device_filter) {
            av_log(avctx, AV_LOG_ERROR, "Could not find %s device with name [%s] among source devices of type %s.\n",
                   devtypename, device_name, sourcetypename);
            return AVERROR(EIO);
        }
        *pfilter = device_filter;
    }

    return 0;
}
示例#27
0
QVector<QPair<QString,QString>> DirectShow::getDeviceList()
{
    IMoniker* m = nullptr;
    QVector<QPair<QString,QString>> devices;

    ICreateDevEnum* devenum = nullptr;
    if (CoCreateInstance(CLSID_SystemDeviceEnum, nullptr, CLSCTX_INPROC_SERVER,
                             IID_ICreateDevEnum, (void**) &devenum) != S_OK)
        return devices;

    IEnumMoniker* classenum = nullptr;
    if (devenum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory,
                                (IEnumMoniker**)&classenum, 0) != S_OK)
        return devices;

    while (classenum->Next(1, &m, nullptr) == S_OK)
    {
        VARIANT var;
        IPropertyBag* bag = nullptr;
        LPMALLOC coMalloc = nullptr;
        IBindCtx* bindCtx = nullptr;
        LPOLESTR olestr = nullptr;
        char *devIdString=nullptr, *devHumanName=nullptr;

        if (CoGetMalloc(1, &coMalloc) != S_OK)
            goto fail;
        if (CreateBindCtx(0, &bindCtx) != S_OK)
            goto fail;

        // Get an uuid for the device that we can pass to ffmpeg directly
        if (m->GetDisplayName(bindCtx, nullptr, &olestr) != S_OK)
            goto fail;
        devIdString = wcharToUtf8(olestr);

        // replace ':' with '_' since FFmpeg uses : to delimitate sources
        for (unsigned i = 0; i < strlen(devIdString); i++)
            if (devIdString[i] == ':')
                devIdString[i] = '_';

        // Get a human friendly name/description
        if (m->BindToStorage(nullptr, nullptr, IID_IPropertyBag, (void**)&bag) != S_OK)
            goto fail;

        var.vt = VT_BSTR;
        if (bag->Read(L"FriendlyName", &var, nullptr) != S_OK)
            goto fail;
        devHumanName = wcharToUtf8(var.bstrVal);

        devices += {QString("video=")+devIdString, devHumanName};

fail:
        if (olestr && coMalloc)
            coMalloc->Free(olestr);
        if (bindCtx)
            bindCtx->Release();
        delete[] devIdString;
        delete[] devHumanName;
        if (bag)
            bag->Release();
        m->Release();
    }
    classenum->Release();

    return devices;
}
void CRemoteGraphForm::OnRefreshClick()
{
	// let's load objects from ROT
	CComPtr<IRunningObjectTable>	rot;
	HRESULT							hr;

	graphs.RemoveAll();
    list_graphs.DeleteAllItems();
    sel_graph = RemoteGraph();

	hr = GetRunningObjectTable(0, &rot);
	if (FAILED(hr)) return ;

	// scan through running objects
	CComPtr<IEnumMoniker>			emon;
	CComPtr<IMoniker>				moniker;
	CComPtr<IBindCtx>				bindctx;
	ULONG							f;

	hr = CreateBindCtx(0, &bindctx);
	if (FAILED(hr)) {
		return ;
	}

    CAtlRegExp<> regex;
    REParseError status = regex.Parse(_T("^\\!FilterGraph {[0-9A-F]+} pid {[0-9A-F]+}(; process\\: {.+?}, time\\: {[0-9]+\\-[0-9]+\\-[0-9]+})?"), FALSE);

	rot->EnumRunning(&emon);
	emon->Reset();
	while (emon->Next(1, &moniker, &f) == NOERROR) {
		
		// is this a graph object ?
		LPOLESTR	displayname;
		moniker->GetDisplayName(bindctx, NULL, &displayname);

		CString		name(displayname);
		if (name.Find(_T("!FilterGraph")) == 0 && !GraphStudio::DisplayGraph::IsOwnRotGraph(name)) {
            RemoteGraph	gr = {0};

            CAtlREMatchContext<> mc;
            gr.name = name;
			gr.moniker = moniker;
            gr.pid = 0;
            gr.instance = 0;
            gr.processIsWOW64 = FALSE;

            if (regex.Match(name, &mc))
            {
                const CAtlREMatchContext<>::RECHAR* szStart = 0;
                const CAtlREMatchContext<>::RECHAR* szEnd = 0;
                mc.GetMatch(0, &szStart, &szEnd);
                int nLength = (int) (szEnd - szStart);
                const CString textInstance(szStart, nLength);
                StrToInt64ExW(CStringW(L"0x") + textInstance, STIF_SUPPORT_HEX, &reinterpret_cast<LONGLONG&>(gr.instance));

                mc.GetMatch(1, &szStart, &szEnd);
                nLength = (int) (szEnd - szStart);
                const CString textPID(szStart, nLength);
				CString nameSuffix(szEnd ? szEnd : _T(""));
				nameSuffix.Trim();

			    if (StrToIntExW(CStringW(L"0x") + textPID, STIF_SUPPORT_HEX, &reinterpret_cast<INT&>(gr.pid)))
                {
                    CHandle process;
					process.Attach(OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, gr.pid));
					if (process)
                    {
                        TCHAR pszPath[MAX_PATH] = { 0 };
					    if (GetModuleFileNameEx(process, NULL, pszPath, sizeof(pszPath)))
                        {
                            gr.processImagePath = pszPath;

                            // Extract filename
                            int fileNamePos = gr.processImagePath.FindFileName();
                            if (fileNamePos >= 0)
                                gr.processImageFileName = CString(gr.processImagePath).Mid(fileNamePos);
                        }
                        else
                        {
                            // a 32Bit process can't list the modules of a 64Bit process, so try to get the processImageFileName from the ROT-Name (works only for FilterGraphSpy-Entries)
                            mc.GetMatch(2, &szStart, &szEnd);
                            nLength = (int) (szEnd - szStart);
                            if (nLength > 0)
                            {
                                CString textFileName(szStart, nLength);
                                gr.processImageFileName = textFileName;
                            }
							else if (nameSuffix.GetLength() > 0)
							{
								gr.processImageFileName = nameSuffix;		// as a last resort add any suffix information from the ROT name rather than leaving blank
#ifndef _WIN64
								gr.processImageFileName += _T(" *64");		// If we're 32bit, assume that we can't get process name because remote process is 64bit and show this on the dialog
#endif
							}
                        }

                        IsWow64Process(process, &gr.processIsWOW64);
                    }
                }

                mc.GetMatch(3, &szStart, &szEnd);
                nLength = (int) (szEnd - szStart);
                if (nLength > 0)
                {
                    CString textTime(szStart, nLength);
                    textTime.Replace(_T("-"), _T(":"));
                    gr.time = textTime;
                }
            }
            graphs.Add(gr);

            CString entryName = gr.name;
            if (gr.pid > 0)
                entryName.Format(_T("%d (0x%08lX)"), gr.pid, gr.pid);
			int nIndex = list_graphs.InsertItem(list_graphs.GetItemCount(), entryName);
            
            if (gr.processIsWOW64)
            {
                CString val = gr.processImageFileName;
                val.Append(_T(" *32"));
                list_graphs.SetItemText(nIndex, 1, val);
            }
            else
                list_graphs.SetItemText(nIndex, 1, gr.processImageFileName);

            if (gr.instance > 0)
            {
                CString val;
                val.Format(_T("0x%I64d"), gr.instance);
                list_graphs.SetItemText(nIndex, 2, val);
            }

            list_graphs.SetItemText(nIndex, 3, gr.time);
            list_graphs.SetItemText(nIndex, 4, gr.processImagePath);

			if (graphs.GetCount() == 1) {
                list_graphs.SetItemState(0, LVIS_SELECTED, LVIS_SELECTED);
                list_graphs.SetSelectionMark(0);
			}
		}

		if (displayname) {
			CComPtr<IMalloc>	alloc;
			if (SUCCEEDED(CoGetMalloc(0, &alloc))) {
				alloc->Free(displayname);
			}
		}
		moniker = NULL;
	}

	// Set column width automatically to fit contents refreshed above
	for (int n=0; n<=4; n++) {
		list_graphs.SetColumnWidth(n, LVSCW_AUTOSIZE_USEHEADER);
	}
}
示例#29
0
/*************************************************************************
 *             SHGetMalloc            [SHELL32.@]
 *
 * Equivalent to CoGetMalloc(MEMCTX_TASK, ...). Under Windows 9x this function
 * could use the shell32 built-in "mini-COM" without the need to load ole32.dll -
 * see SHLoadOLE for details.
 *
 * PARAMS
 *  lpmal [O] Destination for IMalloc interface.
 *
 * RETURNS
 *  Success: S_OK. lpmal contains the shells IMalloc interface.
 *  Failure. An HRESULT error code.
 *
 * SEE ALSO
 *  CoGetMalloc, SHLoadOLE
 */
HRESULT WINAPI SHGetMalloc(LPMALLOC *lpmal)
{
    TRACE("(%p)\n", lpmal);
    return CoGetMalloc(MEMCTX_TASK, lpmal);
}
示例#30
0
void CRemoteGraphForm::OnRefreshClick()
{
	// let's load objects from ROT
	CComPtr<IRunningObjectTable>	rot;
	HRESULT							hr;

	graphs.RemoveAll();
	list_graphs.ResetContent();
	sel_graph = NULL;

	hr = GetRunningObjectTable(0, &rot);
	if (FAILED(hr)) return ;

	// scan through running objects
	CComPtr<IEnumMoniker>			emon;
	CComPtr<IMoniker>				moniker;
	CComPtr<IBindCtx>				bindctx;
	ULONG							f;

	hr = CreateBindCtx(0, &bindctx);
	if (FAILED(hr)) {
		rot = NULL;
		return ;
	}


	rot->EnumRunning(&emon);
	emon->Reset();
	while (emon->Next(1, &moniker, &f) == NOERROR) {
		
		// is this a graph object ?
		LPOLESTR	displayname;
		moniker->GetDisplayName(bindctx, NULL, &displayname);

		CString		name(displayname);
		if (name.Find(_T("!FilterGraph")) == 0) {
			RemoteGraph	gr;
			gr.name = name;
			gr.moniker = moniker;
			gr.moniker->AddRef();

			list_graphs.AddString(name);
			graphs.Add(gr);

			if (graphs.GetCount() == 1) {
				list_graphs.SetCurSel(0);
				OnLbnSelchangeListGraphs();
			}
		}

		if (displayname) {
			CComPtr<IMalloc>	alloc;
			if (SUCCEEDED(CoGetMalloc(0, &alloc))) {
				alloc->Free(displayname);
			}
			alloc = NULL;
		}
		moniker = NULL;
	}
	emon = NULL;
	bindctx = NULL;

	rot = NULL;
}