Example #1
0
BOOL CXLAutomation::StartExcel()
{
	CLSID clsExcelApp;

	// if Excel is already running, return with current instance
	if (m_pdispExcelApp != NULL)
		return TRUE;

	/* Obtain the CLSID that identifies EXCEL.APPLICATION
	 * This value is universally unique to Excel versions 5 and up, and
	 * is used by OLE to identify which server to start.  We are obtaining
	 * the CLSID from the ProgID.
	 */
	if (FAILED(CLSIDFromProgID(L"Excel.Application", &clsExcelApp))) 
	{
		MessageBox(NULL, _T("Cannot obtain CLSID from ProgID"), "Failed", MB_OK | MB_ICONSTOP);
		return FALSE;
	}

	// start a new copy of Excel, grab the IDispatch interface
	if (FAILED(CoCreateInstance(clsExcelApp, NULL, CLSCTX_LOCAL_SERVER, IID_IDispatch, (void**)&m_pdispExcelApp))) 
	{
		MessageBox(NULL, _T("Cannot start an instance of Excel for Automation."), "Failed", MB_OK | MB_ICONSTOP);
		return FALSE;
	}

	return TRUE;

}
Example #2
0
INT CmDevice_RT::GetMaxValueFromCaps(CM_HAL_MAX_VALUES & MaxValues,
				  CM_HAL_MAX_VALUES_EX & MaxValuesEx)
{
	DXVA_CM_QUERY_CAPS queryCaps;
	UINT querySize = sizeof(DXVA_CM_QUERY_CAPS);
	CmSafeMemSet(&queryCaps, 0, sizeof(DXVA_CM_QUERY_CAPS));
	queryCaps.Type = DXVA_CM_MAX_VALUES;

	INT hr = GetCapsInternal(&queryCaps, &querySize);
	if (FAILED(hr)) {
		CM_ASSERT(0);
		return CM_FAILURE;
	}

	MaxValues = queryCaps.MaxValues;
	MaxValues.iMaxArgsPerKernel =
	    (queryCaps.MaxValues.iMaxArgsPerKernel >
	     CM_MAX_ARGS_PER_KERNEL) ? (CM_MAX_ARGS_PER_KERNEL) :
	    queryCaps.MaxValues.iMaxArgsPerKernel;

	CmSafeMemSet(&queryCaps, 0, sizeof(DXVA_CM_QUERY_CAPS));
	queryCaps.Type = DXVA_CM_MAX_VALUES_EX;

	hr = GetCapsInternal(&queryCaps, &querySize);
	if (FAILED(hr)) {
		CM_ASSERT(0);
		return CM_FAILURE;
	}
	MaxValuesEx = queryCaps.MaxValuesEx;

	return CM_SUCCESS;
}
Example #3
0
void KG3DTestLoadMesh::TestLoadOneMeshFile(const char cszFileName[])
{
	HRESULT hrRetCode = E_FAIL;
	KG3DMesh* pMesh = NULL;

	_ASSERTE(cszFileName);
	hrRetCode = m_pMeshTable->LoadResourceFromFile(cszFileName, 0, 0, (IKG3DResourceBase**)&pMesh);
	if (FAILED(hrRetCode) || pMesh == NULL)
	{
		m_vecLoadFailedMesh.push_back(cszFileName);
	}
	if (pMesh)
	{
		//这里要注意加参数RELEASE_ATONCE,以便立即释放资源,默认是放入释放队列(RELEASE_INQUEUE)
		//否则内存中会一直占用释一定数量的资源,数量等于释放资源队列的大小
		hrRetCode = m_pMeshTable->ReleaseResource((KG3DMesh*)pMesh, RELEASE_ATONCE);
		if (FAILED(hrRetCode))
		{
			KGLogPrintf(KGLOG_ERR, "Release Mtl Failed!");
		}
		else
		{
			pMesh = NULL;
		}
	}
}
Example #4
0
bool CreateOrUpdateShortcutLink(fs::path const& shortcut_path, fs::path const& target_path)
{
    bool shortcut_existed = fs::exists(shortcut_path);

    {
        base::com::unique_ptr<IShellLinkW> pShellLink;
        HRESULT hr = pShellLink.CreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER);
        if (FAILED(hr))
            return false;

        pShellLink->SetPath(target_path.c_str());

        base::com::unique_ptr<IPersistFile> pPf;
        hr = pPf.QueryFrom(pShellLink.get());
        if (FAILED(hr))
            return false;

        hr = pPf->Save(shortcut_path.c_str(), TRUE);
        if (FAILED(hr))
            return false;

    }

    if (shortcut_existed)
    {
        ::SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL);
    }
    else
    {
        ::SHChangeNotify(SHCNE_CREATE, SHCNF_PATH, shortcut_path.c_str(), NULL);
    }

    return true;
}
lpta::LptaTexture::DATA LptaD3DTextureManager::GenerateDefaultData(void)
{
    LPDIRECT3DTEXTURE9 textureData = nullptr;
    D3DLOCKED_RECT d3dLockedRect;
    HRESULT result = d3ddev->CreateTexture(
        DEFAULT_TEXTURE_WIDTH, DEFAULT_TEXTURE_HEIGHT,
        1, 0,
        D3DFMT_A8R8G8B8,
        D3DPOOL_MANAGED,
        &textureData,
        nullptr
    );
    if (FAILED(result)) {
        throw TextureD3DFailure("could not obtain texture object for default");
    }
    result = textureData->LockRect(0, &d3dLockedRect, nullptr, 0);
    if (FAILED(result)) {
        textureData->Release();
        throw TextureD3DFailure("failed to lock rectangle to set default texture color");
    }
    unsigned long *rawData = (unsigned long *)d3dLockedRect.pBits;
    for (unsigned long *pixel = rawData; 
        pixel < rawData + (DEFAULT_TEXTURE_WIDTH * DEFAULT_TEXTURE_HEIGHT); ++pixel) {

        *pixel = DEFAULT_TEXTURE_COLOR;
    }
    textureData->UnlockRect(0);
    return (lpta::LptaTexture::DATA)textureData;
}
bool MediaPlayerPrivateMediaFoundation::createTopologyFromSource()
{
    if (!MFCreateTopologyPtr())
        return false;

    // Create a new topology.
    if (FAILED(MFCreateTopologyPtr()(&m_topology)))
        return false;

    // Create the presentation descriptor for the media source.
    if (FAILED(m_mediaSource->CreatePresentationDescriptor(&m_sourcePD)))
        return false;

    // Get the number of streams in the media source.
    DWORD sourceStreams = 0;
    if (FAILED(m_sourcePD->GetStreamDescriptorCount(&sourceStreams)))
        return false;

    // For each stream, create the topology nodes and add them to the topology.
    for (DWORD i = 0; i < sourceStreams; i++) {
        if (!addBranchToPartialTopology(i))
            return false;
    }

    return true;
}
bool MediaPlayerPrivateMediaFoundation::createSourceStreamNode(COMPtr<IMFStreamDescriptor> sourceSD, COMPtr<IMFTopologyNode>& node)
{
    if (!MFCreateTopologyNodePtr())
        return false;

    if (!m_mediaSource || !m_sourcePD || !sourceSD)
        return false;

    // Create the source-stream node.
    HRESULT hr = MFCreateTopologyNodePtr()(MF_TOPOLOGY_SOURCESTREAM_NODE, &node);
    if (FAILED(hr))
        return false;

    // Set attribute: Pointer to the media source.
    hr = node->SetUnknown(MF_TOPONODE_SOURCE, m_mediaSource.get());
    if (FAILED(hr))
        return false;

    // Set attribute: Pointer to the presentation descriptor.
    hr = node->SetUnknown(MF_TOPONODE_PRESENTATION_DESCRIPTOR, m_sourcePD.get());
    if (FAILED(hr))
        return false;

    // Set attribute: Pointer to the stream descriptor.
    hr = node->SetUnknown(MF_TOPONODE_STREAM_DESCRIPTOR, sourceSD.get());
    if (FAILED(hr))
        return false;

    return true;
}
Example #8
0
static HRESULT ConnectFilters(IGraphBuilder *graph,
							  IBaseFilter *lhs,
							  IBaseFilter *rhs)
{
	HRESULT hr = S_OK;
    IPin *out = 0;
	IPin *in  = 0;
	
    hr = GetPin(lhs, PINDIR_OUTPUT, &out);
	
    if (FAILED(hr))
		return hr;
	
    hr = GetPin(rhs, PINDIR_INPUT, &in);
	
    if (FAILED(hr)) 
    {
        out->Release();
        return hr;
	}
	
    hr = graph->Connect(out, in);
    in->Release();
    out->Release();
    return hr;
}
Example #9
0
/***********************************************************************
 *           AtlRegisterTypeLib         [atl80.18]
 */
HRESULT WINAPI AtlComModuleRegisterServer(_ATL_COM_MODULE *mod, BOOL bRegTypeLib, const CLSID *clsid)
{
    const struct _ATL_CATMAP_ENTRY *catmap;
    _ATL_OBJMAP_ENTRY **iter;
    HRESULT hres;

    TRACE("(%p %x %s)\n", mod, bRegTypeLib, debugstr_guid(clsid));

    for(iter = mod->m_ppAutoObjMapFirst; iter < mod->m_ppAutoObjMapLast; iter++) {
        if(!*iter || (clsid && !IsEqualCLSID((*iter)->pclsid, clsid)))
            continue;

        TRACE("Registering clsid %s\n", debugstr_guid((*iter)->pclsid));
        hres = (*iter)->pfnUpdateRegistry(TRUE);
        if(FAILED(hres))
            return hres;

        catmap = (*iter)->pfnGetCategoryMap();
        if(catmap) {
            hres = AtlRegisterClassCategoriesHelper((*iter)->pclsid, catmap, TRUE);
            if(FAILED(hres))
                return hres;
        }
    }

    if(bRegTypeLib) {
        hres = AtlRegisterTypeLib(mod->m_hInstTypeLib, NULL);
        if(FAILED(hres))
            return hres;
    }

    return S_OK;
}
/* Initialize the XTAPI COM module
 */
BOOL CFillUpdateApp::InitInstance()
{
	// Initializes the COM library on the current thread and identifies the 
	// concurrency model as single-thread apartment (STA).
	if (FAILED(CoInitialize(NULL)))
	{
		return FALSE;
	}

	// Initialize ATL
	if (FAILED(_Module.Init(ObjectMap, AfxGetInstanceHandle())))
	{
		return FALSE;
	}

	// create and display our dialog window
	CFillUpdateDialog dlg;
	CWinThread::m_pMainWnd = &dlg;

	INT_PTR nRet = dlg.DoModal();
	// nRet can be handled here if need be

	// The dialog has been closed - return false so the application exits
	return FALSE;
}
Example #11
0
HRESULT CDataCallback::ReAllocBuffer(ULONG nSize)
{
    HRESULT hr;

    // If m_pStream is not initialized yet, create a new stream object
    if (m_pStream == 0)
    {
        hr = CreateStreamOnHGlobal(0, TRUE, &m_pStream);

        if (FAILED(hr))
        {
            return hr;
        }
    }

    // Next, set the size of the stream object

    ULARGE_INTEGER liSize = { nSize };

    hr = m_pStream->SetSize(liSize);

    if (FAILED(hr))
    {
        return hr;
    }

    m_nDataSize = nSize;

    return S_OK;
}
Example #12
0
static HRESULT create_moniker(LPCWSTR url, IMoniker **mon)
{
    WCHAR new_url[INTERNET_MAX_URL_LENGTH];
    DWORD size;
    HRESULT hres;

    if(PathIsURLW(url))
        return CreateURLMoniker(NULL, url, mon);

    if(url[1] == ':') {
        size = sizeof(new_url);
        hres = UrlCreateFromPathW(url, new_url, &size, 0);
        if(FAILED(hres)) {
            WARN("UrlCreateFromPathW failed: %08x\n", hres);
            return hres;
        }
    }else {
        size = sizeof(new_url);
        hres = UrlApplySchemeW(url, new_url, &size, URL_APPLY_GUESSSCHEME);
        TRACE("got %s\n", debugstr_w(new_url));
        if(FAILED(hres)) {
            WARN("UrlApplyScheme failed: %08x\n", hres);
            return hres;
        }
    }

    return CreateURLMoniker(NULL, new_url, mon);
}
Example #13
0
static HRESULT FolderItem_Constructor(VARIANT *dir, FolderItem **ppfi)
{
    FolderItemImpl *This;
    HRESULT ret;

    *ppfi = NULL;

    This = HeapAlloc(GetProcessHeap(), 0, sizeof(FolderItemImpl));
    if (!This) return E_OUTOFMEMORY;
    This->FolderItem_iface.lpVtbl = &FolderItemImpl_Vtbl;
    This->ref = 1;

    ret = load_type_info(&IID_FolderItem, &This->iTypeInfo);
    if (FAILED(ret))
    {
        HeapFree(GetProcessHeap(), 0, This);
        return ret;
    }

    VariantInit(&This->dir);
    ret = VariantCopy(&This->dir, dir);
    if (FAILED(ret))
    {
        ITypeInfo_Release(This->iTypeInfo);
        HeapFree(GetProcessHeap(), 0, This);
        return E_OUTOFMEMORY;
    }

    *ppfi = (FolderItem*)This;
    return ret;
}
Example #14
0
BOOL CXLAutomation::ExlInvoke(IDispatch *pdisp, LPOLESTR szMember, VARIANTARG * pvargReturn,
			WORD wInvokeAction, WORD wFlags)
{
	HRESULT hr;
	DISPPARAMS dispparams;
	unsigned int uiArgErr;
	EXCEPINFO excep;
	
	// Get the IDs for the member and its arguments.  GetIDsOfNames expects the
	// member name as the first name, followed by argument names (if any).
	m_alpszArgNames[0] = szMember;
	hr = pdisp->GetIDsOfNames( IID_NULL, m_alpszArgNames,
								1 + m_iNamedArgCount, LOCALE_SYSTEM_DEFAULT, m_aDispIds);
	if (FAILED(hr)) 
	{
		if (!(wFlags & DISP_NOSHOWEXCEPTIONS))
			ShowException(szMember, hr, NULL, 0);
		return FALSE;
	}
	
	if (pvargReturn != NULL)
		ClearVariant(pvargReturn);
	
	// if doing a property put(ref), we need to adjust the first argument to have a
	// named arg of DISPID_PROPERTYPUT.
	if (wInvokeAction & (DISPATCH_PROPERTYPUT | DISPATCH_PROPERTYPUTREF)) 
	{
		m_iNamedArgCount = 1;
		m_aDispIds[1] = DISPID_PROPERTYPUT;
		pvargReturn = NULL;
	}
	
	dispparams.rgdispidNamedArgs = m_aDispIds + 1;
	dispparams.rgvarg = m_aVargs;
	dispparams.cArgs = m_iArgCount;
	dispparams.cNamedArgs = m_iNamedArgCount;
	
	excep.pfnDeferredFillIn = NULL;
	
	hr = pdisp->Invoke(m_aDispIds[0], IID_NULL, LOCALE_SYSTEM_DEFAULT,
								wInvokeAction, &dispparams, pvargReturn, &excep, &uiArgErr);
	
	if (wFlags & DISP_FREEARGS)
		ClearAllArgs();
	
	if (FAILED(hr)) 
	{
		// display the exception information if appropriate:
		if (!(wFlags & DISP_NOSHOWEXCEPTIONS))
			ShowException(szMember, hr, &excep, uiArgErr);
	
		// free exception structure information
		SysFreeString(excep.bstrSource);
		SysFreeString(excep.bstrDescription);
		SysFreeString(excep.bstrHelpFile);
	
		return FALSE;
	}
	return TRUE;
}
Example #15
0
HRESULT bind_to_storage(IUri *uri, IBindCtx *pbc, REFIID riid, void **ppv)
{
    Binding *binding = NULL, *binding_ctx;
    HRESULT hres;

    *ppv = NULL;

    binding_ctx = get_bctx_binding(pbc);

    hres = start_binding(NULL, binding_ctx, uri, pbc, FALSE, riid, &binding);
    if(binding_ctx)
        IBinding_Release(BINDING(binding_ctx));
    if(FAILED(hres))
        return hres;

    if(binding->hres == S_OK && binding->stgmed_buf->init) {
        if((binding->state & BINDING_STOPPED) && (binding->state & BINDING_LOCKED))
            IInternetProtocol_UnlockRequest(binding->protocol);

        hres = binding->stgmed_obj->vtbl->get_result(binding->stgmed_obj, binding->bindf, ppv);
    } else if(binding->bindf & BINDF_ASYNCHRONOUS) {
        hres = MK_S_ASYNCHRONOUS;
    } else {
        hres = FAILED(binding->hres) ? binding->hres : S_OK;
    }

    IBinding_Release(BINDING(binding));

    return hres;
}
Example #16
0
mfxStatus CD3D11Device::CreateVideoProcessor(mfxFrameSurface1 * pSrf)
{
    HRESULT hres = S_OK;

    if (!!m_VideoProcessorEnum || NULL == pSrf)
        return MFX_ERR_NONE;

    //create video processor
    D3D11_VIDEO_PROCESSOR_CONTENT_DESC ContentDesc;
    MSDK_ZERO_MEMORY( ContentDesc );

    ContentDesc.InputFrameFormat = D3D11_VIDEO_FRAME_FORMAT_PROGRESSIVE;
    ContentDesc.InputFrameRate.Numerator = 30000;
    ContentDesc.InputFrameRate.Denominator = 1000;
    ContentDesc.InputWidth  = pSrf->Info.CropW;
    ContentDesc.InputHeight = pSrf->Info.CropH;
    ContentDesc.OutputWidth = pSrf->Info.CropW;
    ContentDesc.OutputHeight = pSrf->Info.CropH;
    ContentDesc.OutputFrameRate.Numerator = 30000;
    ContentDesc.OutputFrameRate.Denominator = 1000;

    ContentDesc.Usage = D3D11_VIDEO_USAGE_PLAYBACK_NORMAL;

    hres = m_pDX11VideoDevice->CreateVideoProcessorEnumerator( &ContentDesc, m_VideoProcessorEnum.Assign() );
    if (FAILED(hres))
        return MFX_ERR_DEVICE_FAILED;

    hres = m_pDX11VideoDevice->CreateVideoProcessor( m_VideoProcessorEnum, 0, m_pVideoProcessor.Assign() );
    if (FAILED(hres))
        return MFX_ERR_DEVICE_FAILED;
    
    return MFX_ERR_NONE;
}
Example #17
0
void AVIWrite::SetSoundFormat(WAVEFORMATEX *format)
{
  memcpy(&m_soundFormat, format, sizeof(WAVEFORMATEX));
  ZeroMemory(&m_soundHeader, sizeof(AVISTREAMINFO));
  // setup the sound stream header
  m_soundHeader.fccType = streamtypeAUDIO;
  m_soundHeader.dwQuality = (DWORD)-1;
  m_soundHeader.dwScale = format->nBlockAlign;
  m_soundHeader.dwInitialFrames = 1;
  m_soundHeader.dwRate = format->nAvgBytesPerSec;
  m_soundHeader.dwSampleSize = format->nBlockAlign;
  
  // create the sound stream
  if(FAILED(AVIFileCreateStream(m_file, &m_streamSound, &m_soundHeader))) {
    m_failed = true;
    return;
  }
  
  // setup the sound stream format
  if(FAILED(AVIStreamSetFormat(m_streamSound, 0 , (void *)&m_soundFormat,
                               sizeof(WAVEFORMATEX)))) {
    m_failed = true;
    return;
  }
}
static char* cookieJarPath()
{
    char* cookieJarPath = getenv("CURL_COOKIE_JAR_PATH");
    if (cookieJarPath)
        return fastStrDup(cookieJarPath);

#if OS(WINDOWS)
    char executablePath[MAX_PATH];
    char appDataDirectory[MAX_PATH];
    char cookieJarFullPath[MAX_PATH];
    char cookieJarDirectory[MAX_PATH];

    if (FAILED(::SHGetFolderPathA(0, CSIDL_LOCAL_APPDATA | CSIDL_FLAG_CREATE, 0, 0, appDataDirectory))
        || FAILED(::GetModuleFileNameA(0, executablePath, MAX_PATH)))
        return fastStrDup("cookies.dat");

    ::PathRemoveExtensionA(executablePath);
    LPSTR executableName = ::PathFindFileNameA(executablePath);
    sprintf_s(cookieJarDirectory, MAX_PATH, "%s/%s", appDataDirectory, executableName);
    sprintf_s(cookieJarFullPath, MAX_PATH, "%s/cookies.dat", cookieJarDirectory);

    if (::SHCreateDirectoryExA(0, cookieJarDirectory, 0) != ERROR_SUCCESS
        && ::GetLastError() != ERROR_FILE_EXISTS
        && ::GetLastError() != ERROR_ALREADY_EXISTS)
        return fastStrDup("cookies.dat");

    return fastStrDup(cookieJarFullPath);
#else
    return fastStrDup("cookies.dat");
#endif
}
bool MediaPlayerPrivateMediaFoundation::addBranchToPartialTopology(int stream)
{
    // Get the stream descriptor for this stream.
    COMPtr<IMFStreamDescriptor> sourceSD;
    BOOL selected = FALSE;
    if (FAILED(m_sourcePD->GetStreamDescriptorByIndex(stream, &selected, &sourceSD)))
        return false;

    // Create the topology branch only if the stream is selected.
    // Otherwise, do nothing.
    if (!selected)
        return true;

    // Create a source node for this stream.
    COMPtr<IMFTopologyNode> sourceNode;
    if (!createSourceStreamNode(sourceSD, sourceNode))
        return false;

    COMPtr<IMFTopologyNode> outputNode;
    if (!createOutputNode(sourceSD, outputNode))
        return false;

    // Add both nodes to the topology.
    if (FAILED(m_topology->AddNode(sourceNode.get())))
        return false;

    if (FAILED(m_topology->AddNode(outputNode.get())))
        return false;

    // Connect the source node to the output node.
    if (FAILED(sourceNode->ConnectOutput(0, outputNode.get(), 0)))
        return false;

    return true;
}
Example #20
0
static void dinput_joypad_poll(void)
{
    unsigned i;
    for (i = 0; i < MAX_USERS; i++)
    {
        struct dinput_joypad *pad = &g_pads[i];
        bool polled = g_xinput_pad_indexes[i] < 0;

        if (!pad || !pad->joypad || !polled)
            continue;

        memset(&pad->joy_state, 0, sizeof(pad->joy_state));

        if (FAILED(IDirectInputDevice8_Poll(pad->joypad)))
        {
            if (FAILED(IDirectInputDevice8_Acquire(pad->joypad)))
            {
                memset(&pad->joy_state, 0, sizeof(DIJOYSTATE2));
                continue;
            }

            /* If this fails, something *really* bad must have happened. */
            if (FAILED(IDirectInputDevice8_Poll(pad->joypad)))
            {
                memset(&pad->joy_state, 0, sizeof(DIJOYSTATE2));
                continue;
            }
        }

        IDirectInputDevice8_GetDeviceState(pad->joypad,
                                           sizeof(DIJOYSTATE2), &pad->joy_state);
    }
}
Example #21
0
//--------------------------------------------------------------------------------------
// Entry point to the program. Initializes everything and goes into a message processing 
// loop. Idle time is used to render the scene.
//--------------------------------------------------------------------------------------
int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow )
{
	UNREFERENCED_PARAMETER( hPrevInstance );
    UNREFERENCED_PARAMETER( lpCmdLine );

    if( FAILED( InitWindow( hInstance, nCmdShow ) ) )
        return 0;

	if (FAILED(MyD3DRenderer.InitDevice(g_hWnd)))
    {
		MyD3DRenderer.CleanupDevice();
        return 0;
    }

    // Main message loop
    MSG msg = {0};
    while( WM_QUIT != msg.message )
    {
        if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
        {
            TranslateMessage( &msg );
            DispatchMessage( &msg );
        }
        else
        {
			MyD3DRenderer.Render();
        }
    }

	MyD3DRenderer.CleanupDevice();

    return ( int )msg.wParam;
}
Example #22
0
File: link.c Project: GYGit/reactos
static HRESULT read_hlink_string(IStream *pStm, LPWSTR *out_str)
{
    LPWSTR str;
    DWORD len;
    ULONG read;
    HRESULT hr;

    hr = IStream_Read(pStm, &len, sizeof(len), &read);
    if (FAILED(hr)) return hr;
    if (read != sizeof(len)) return STG_E_READFAULT;

    TRACE("read len %d\n", len);

    str = heap_alloc(len * sizeof(WCHAR));
    if (!str) return E_OUTOFMEMORY;

    hr = IStream_Read(pStm, str, len * sizeof(WCHAR), &read);
    if (FAILED(hr))
    {
        heap_free(str);
        return hr;
    }
    if (read != len * sizeof(WCHAR))
    {
        heap_free(str);
        return STG_E_READFAULT;
    }
    TRACE("read string %s\n", debugstr_w(str));

    *out_str = str;
    return S_OK;
}
Example #23
0
bool ResolveShortcut(fs::path const& shortcut_path, fs::path* target_path)
{
    HRESULT hr;
    base::com::unique_ptr<IShellLinkW> pShellLink;

    hr = pShellLink.CreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER);
    if (FAILED(hr))
        return false;

    base::com::unique_ptr<IPersistFile> pPf;

    hr = pPf.QueryFrom(pShellLink.get());
    if (FAILED(hr))
        return false;

    hr = pPf->Load(shortcut_path.c_str(), STGM_READ);
    if (FAILED(hr))
        return false;

    wchar_t temp[MAX_PATH];
    if (target_path)
    {
        hr = pShellLink->Resolve(0, SLR_NO_UI | SLR_NOSEARCH);
        if (FAILED(hr))
            return false;

        hr = pShellLink->GetPath(temp, MAX_PATH, NULL, SLGP_UNCPRIORITY);
        if (FAILED(hr))
            return false;

        *target_path = fs::path(temp);
    }

    return true;
}
Example #24
0
/*******************************************************************************
  Function Name  : vUpdateGraphControl
  Input(s)       : [in]pGraphCtrl - Pointer to Graph control interface
                   [in]ppGraphElement - Double pointer to Graph element
  Output         : HRESULT indicating success /Failure
  Functionality  : This function will return the currently selected
                    graph element in graph control.
  Member of      : CGraphLeftView
  Author(s)      : MSamoila
  Date Created   : 01-Dec-2011
  Modifications  :
*******************************************************************************/
HRESULT CGraphLeftView::GetCurrentElement(IDMGraphCtrl* pGraphCtrl, IDMGraphElement** ppGraphElement)
{
    ASSERT(pGraphCtrl);
    CComPtr<IDMGraphCollection> spElements;
    long nSelected = 0;
    HRESULT hr;
    hr = pGraphCtrl->get_Elements(&spElements);

    if(FAILED(hr))
    {
        return hr;
    }

    hr = spElements->get_Selected(&nSelected);

    if(FAILED(hr))
    {
        return hr;
    }

    if(nSelected <0 )
    {
        return S_FALSE;
    }

    CComPtr<IDispatch> spDispatch;
    hr = spElements->get_Item(nSelected, &spDispatch);

    if(FAILED(hr))
    {
        return hr;
    }

    return spDispatch.QueryInterface(ppGraphElement);
}
void SpriteD3D::createVertexBuffer() {

    const int numVertices(6);
    const int bufferSize(numVertices * sizeof(SPRITE_VERTEX));

    assert(Platform::getInstancePtr());
    WindowsPlatform* pWin(static_cast<WindowsPlatform*>(Platform::getInstancePtr()));
    assert(pWin);

    assert(!FAILED(pWin->getDevice()->CreateVertexBuffer(bufferSize, 0, FVF_SPRITE_VERTEX, D3DPOOL_DEFAULT, &pVertexBuffer_, nullptr)));

    SPRITE_VERTEX *pVertices( nullptr);

    assert(!FAILED(pVertexBuffer_->Lock(0, 0, (void**)&pVertices, 0)));

    pVertices[0] = vertices_[3];
    pVertices[1] = vertices_[0];
    pVertices[2] = vertices_[1];

    pVertices[3] = vertices_[3];
    pVertices[4] = vertices_[1];
    pVertices[5] = vertices_[2];

    pVertexBuffer_->Unlock();
}
Example #26
0
bool CDynamicTexture::CreateTexture(LPDIRECT3DDEVICE9 device, UINT width, UINT height, D3DFORMAT format)
{
    assert(m_textureSystem == NULL && m_surfaceSystem == NULL
           && m_textureDefault == NULL && m_surfaceDefault == NULL);
    m_device = device;

    m_width = width;
    m_height = height;
    m_format = format;

    if (CreateDefaultTexture() == false)
        return false;

    if (FAILED(device->CreateTexture(width, height, 1,
                                     D3DUSAGE_DYNAMIC, format,
                                     D3DPOOL_SYSTEMMEM, &m_textureSystem, NULL)))
    {
        MessageBox(NULL, "Create Texture Error", "ERROR", 0);
        return false;
    }
    if (FAILED(m_textureSystem->GetSurfaceLevel(0, &m_surfaceSystem)))
    {
        m_textureSystem->Release();
        m_textureSystem = NULL;
        MessageBox(NULL, "Get Surface Error", "ERROR", 0);
        return false;
    }
    return true;
}
Example #27
0
int LoadBitmapToSurface(char* PathName, LPDIRECT3DSURFACE8* ppSurface, LPDIRECT3DDEVICE8 pDevice){
	HRESULT r;
	HBITMAP hBitmap;
	BITMAP Bitmap;

	hBitmap = (HBITMAP)LoadImage(NULL, PathName, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION);
	if(hBitmap == NULL){
		SetError("Unable to load bitmap");
		return E_FAIL;
	}

	GetObject(hBitmap, sizeof(BITMAP), &Bitmap);
	DeleteObject(hBitmap);//we only needed it for the header info to create a D3D surface

	//create surface for bitmap
	r=pDevice->CreateImageSurface(Bitmap.bmWidth, Bitmap.bmHeight, D3DFMT_X8R8G8B8, ppSurface);
	if(FAILED(r)){
		SetError("Unable to create surface for bitmap load");
		return E_FAIL;
	}

	//load bitmap onto surface
	r = D3DXLoadSurfaceFromFile(*ppSurface, NULL, NULL, PathName, NULL, D3DX_FILTER_NONE, 0, NULL);
	if(FAILED(r)){
		SetError("Unable to laod file to surface");
		return E_FAIL;
	}

	return S_OK;
}
Example #28
0
HRESULT COutputPin::CreateAllocator()
{
    HRESULT hr = S_OK;

    if (m_pAlloc != NULL)
        return S_OK;

    m_pAlloc = new CAllocator("CAllocator", NULL, &hr);
    if (!m_pAlloc)
    {
        return E_OUTOFMEMORY;
    }

    if (FAILED(hr))
    {
        delete m_pAlloc;
        m_pAlloc = NULL;
        return hr;
    }

    hr = m_pAlloc->QueryInterface(IID_IMemAllocator, (void**)&m_pIAlloc);
    if (FAILED(hr))
    {
        delete m_pAlloc;
        m_pAlloc = NULL;
        return hr;
    }

    return S_OK;
}
Example #29
0
JNIEXPORT jlong JNICALL Java_com4j_Native_getErrorInfo(
	JNIEnv* env, jclass __unused__, jlong pComObject, jlong iid1, jlong iid2) {

	MyGUID iid(iid1,iid2);

  try {
	  ISupportErrorInfoPtr p(reinterpret_cast<IUnknown*>(pComObject));
	  if(p==NULL)
		  return 0;	// not supported

	  HRESULT hr = p->InterfaceSupportsErrorInfo(iid);
	  if(FAILED(hr)) {
		  error(env,__FILE__,__LINE__,hr,"ISupportErrorInfo::InterfaceSupportsErrorInfo failed");
		  return 0;
	  }

	  if(hr!=S_OK)	return 0; // not supported

	  IErrorInfo* pError;
	  hr = GetErrorInfo(0,&pError);
	  if(FAILED(hr)) {
		  error(env,__FILE__,__LINE__,hr,"GetErrorInfo failed");
		  return 0;
	  }

	  // return the pointer
	  return reinterpret_cast<jlong>(pError);
  } catch (...) {
    // an exception occured. This might happen, if the automation server is not available due to a crash.
    return 0;
  }
  return 0;
}
Example #30
0
AutoPtr<IView> PreviewInflater::InflateWidgetView(
    /* [in] */ WidgetInfo* widgetInfo)
{
    AutoPtr<IView> widgetView;
    ECode ec = NOERROR;
    do {
        AutoPtr<IContext> appContext;
        ec = mContext->CreatePackageContext(
                widgetInfo->mContextPackage, IContext::CONTEXT_RESTRICTED, (IContext**)&appContext);
        if (FAILED(ec)) break;

        AutoPtr<IInterface> obj;
        ec = appContext->GetSystemService(IContext::LAYOUT_INFLATER_SERVICE, (IInterface**)&obj);
        if (FAILED(ec)) break;
        AutoPtr<ILayoutInflater> appInflater = ILayoutInflater::Probe(obj);

        ec = appInflater->CloneInContext(appContext, (ILayoutInflater**)&appInflater);
        if (FAILED(ec)) break;
        ec = appInflater->Inflate(widgetInfo->mLayoutId, NULL, FALSE, (IView**)&widgetView);
    } while (/*PackageManager.NameNotFoundException|RuntimeException e*/0);

    if (FAILED(ec)) {
        Logger::W(TAG, "Error creating widget view");
    }
    return widgetView;
}