当前位置: 首页>>代码示例>>C++>>正文


C++ IDispatch::GetIDsOfNames方法代码示例

本文整理汇总了C++中IDispatch::GetIDsOfNames方法的典型用法代码示例。如果您正苦于以下问题:C++ IDispatch::GetIDsOfNames方法的具体用法?C++ IDispatch::GetIDsOfNames怎么用?C++ IDispatch::GetIDsOfNames使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IDispatch的用法示例。


在下文中一共展示了IDispatch::GetIDsOfNames方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Execute

		VARIANT ObjectInstance::Execute(const wstring methodName, DISPPARAMS inputParameters)
		{
			if (this->objectHandle == NULL)
			{
				throw new RuntimeHostException("ObjectHandle is no longer valid");
			}

			VARIANT v;
			DISPID	dispid;
			LPOLESTR szMethodName = _bstr_t(methodName.data());
			VARIANT result;
			EXCEPINFO pExcepInfo;
			unsigned int puArgErr = 0;
			
			// Initialze the variants
			VariantInit(&v);
			VariantInit(&result);
					
			HRESULT hr = this->objectHandle->Unwrap(&v);
			if (!SUCCEEDED(hr))
			{
				throw new RuntimeHostException("Unable to retrieve method information");
			}

			// The .NET Component should expose IDispatch
			IDispatch* pdispatch = v.pdispVal;				

			// Retrieve the DISPID
			hr = pdispatch->GetIDsOfNames(
								IID_NULL,
								&szMethodName,
								1,
								LOCALE_SYSTEM_DEFAULT,
								&dispid);
			if (!SUCCEEDED(hr))
			{
				throw new RuntimeHostException("Unable to retrieve method information");
			}

			// Invoke the method on the IDispatch Interface
			hr = pdispatch->Invoke(
							dispid,
							IID_NULL,
							LOCALE_SYSTEM_DEFAULT,
							DISPATCH_METHOD,
							&inputParameters,
							&result,
							&pExcepInfo,
							&puArgErr);

			if (!SUCCEEDED(hr))
			{
				throw new RuntimeHostException("Error on method execution");
			}

			return result;
		}
开发者ID:amroel,项目名称:NETProvider,代码行数:57,代码来源:ObjectInstance.cpp

示例2: PrintDocument

// Prints the WORD document if everything goes fine
// otherwise error is returned
int CAutoWord::PrintDocument(char *strFilePath)
{
	// Open the document
	VARIANT varRetVal;
	EXCEPINFO excepInfo; 	// this variable contains exception info if any Invoke call fails
	VARIANTARG varg;
	varg.vt = VT_BSTR;
	varg.bstrVal = _bstr_t(strFilePath); // this is the MS-word document filename, must be changed to a valid filename that exists on disk
	DISPPARAMS dpOpen = { &varg, NULL, 1, 0 };
	DISPID dispOpenID;
	LPOLESTR szOpenDoc = L"Open";
	HRESULT hr = m_pDocuments->GetIDsOfNames(IID_NULL, &szOpenDoc, 1, LOCALE_SYSTEM_DEFAULT, &dispOpenID);
	hr = m_pDocuments->Invoke(dispOpenID, IID_NULL, LOCALE_SYSTEM_DEFAULT, DISPATCH_METHOD, &dpOpen, &varRetVal, &excepInfo, NULL);
	if (FAILED(hr))
	{
		OutputDebugString("Error opening the document\n");
		Destroy();
		return -1;
	}
	
	IDispatch* pDocument = varRetVal.pdispVal;

	// Call PrintOut method of the opened Document 
	DISPPARAMS dpPrint = { NULL, NULL, 0, 0 };
	DISPID dispPrintID;
	LPOLESTR szPrintDoc = L"PrintOut";
	hr = pDocument->GetIDsOfNames(IID_NULL, &szPrintDoc, 1, LOCALE_SYSTEM_DEFAULT, &dispPrintID);
	hr = pDocument->Invoke(dispPrintID, IID_NULL, LOCALE_SYSTEM_DEFAULT, DISPATCH_METHOD, &dpPrint, &varRetVal, NULL, NULL);
	if (FAILED(hr))
	{
		OutputDebugString("The document could not be printed\n");
		Destroy();
		return -1;
	}

	// Close the document now.
	DISPPARAMS dpClose = { NULL, NULL, 0, 0 };
	DISPID dispCloseID;
	LPOLESTR szCloseDoc = L"Close";
	hr = pDocument->GetIDsOfNames(IID_NULL, &szCloseDoc, 1, LOCALE_SYSTEM_DEFAULT, &dispCloseID);
	hr = pDocument->Invoke(dispCloseID, IID_NULL, LOCALE_SYSTEM_DEFAULT, DISPATCH_METHOD, &dpClose, &varRetVal, &excepInfo, NULL);
	
	return 0;
}
开发者ID:anmol2701,项目名称:virtual,代码行数:46,代码来源:AutoWord.cpp

示例3: Run

HRESULT __stdcall ScriptHost::Run(WCHAR *procname, DISPPARAMS *args, VARIANT *results)
{
    assert(procname != nullptr);

    if (procname == nullptr)
        return E_POINTER;

	IDispatch *disp = nullptr;
	_activeScript->GetScriptDispatch(nullptr, &disp);
	DISPID dispid = 0;
	disp->GetIDsOfNames(IID_NULL, &procname, 1, LOCALE_SYSTEM_DEFAULT, &dispid);
	EXCEPINFO info;
	UINT argErr;
	args->rgdispidNamedArgs = &dispid;
	HRESULT hr = disp->Invoke(dispid, IID_NULL, NULL, DISPATCH_METHOD, args, results, &info, &argErr);
	return hr;
}
开发者ID:e1d1s1,项目名称:Logician,代码行数:17,代码来源:ashost.cpp

示例4: GetURL

void CEasyPDFCtrl::GetURL()
{
	USES_CONVERSION;  

	IOleContainer* pContainer = NULL;
	IHTMLDocument* pDoc = NULL;
	m_pClientSite->GetContainer( &pContainer );
	if ( pContainer != NULL )
	pContainer->QueryInterface( IID_IHTMLDocument, (void**)&pDoc );

	HRESULT hresult;
	OLECHAR FAR* szMember = T2W(_T("Initilize"));

	DISPID dispid;
	DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};

	IDispatch * pdisp = NULL;
	pDoc->get_Script(&pdisp);
	hresult = pdisp->GetIDsOfNames(IID_NULL,&szMember,1, LOCALE_SYSTEM_DEFAULT,&dispid);
	hresult = pdisp->Invoke(dispid,IID_NULL,LOCALE_USER_DEFAULT,DISPATCH_METHOD,&dispparamsNoArgs, NULL, NULL, NULL);
	pContainer->Release();
}
开发者ID:SkyblueMr,项目名称:EasyPDF,代码行数:22,代码来源:EasyPDFCtrl.cpp

示例5: get_dispid

DISPID get_dispid( IUnknown* punk, char *propname, BOOL *bVariant )
{
	//		IDispatch の DISPID を取得する
	//
	HRESULT hr;
	IDispatch *disp;
	DISPID dispid;
	char *name = propname;
	LPOLESTR list[]={ (LPOLESTR)(hspctx->stmp) };

	if ( name[0] == '\0' ) return DISPID_VALUE;

	if ( bVariant != NULL ) *bVariant = ( name[0] == '.' );
	if ( name[0] == '.' ) name++;

	disp = (IDispatch *)punk;
	cnvwstr( hspctx->stmp, name, HSPCTX_REFSTR_MAX/sizeof(WCHAR)-1 );
	hr = disp->GetIDsOfNames( IID_NULL, list, 1, LOCALE_SYSTEM_DEFAULT, &dispid );

	if ( FAILED(hr) || dispid == DISPID_UNKNOWN ) throw HSPERR_INVALID_PARAMETER;
	return dispid;
}
开发者ID:sharkpp,项目名称:openhsp,代码行数:22,代码来源:hsp3ext_win.cpp

示例6: setMultinameProperty

// ScriptObject::setMultinameProperty checks if our traits have 'needsHashtable' -
// but we don't.  Its possible 'needsHashtable' is misnamed and means more like 'isDynamic'
// so we should revisit this...
void MSIDispatchConsumer::setMultinameProperty(Multiname* name, Atom value)
{
    // its possible we should just call setStringProperty(), which calls
    // setAtomProperty(), and we should add our impl there - but let's see
    // if we can get away without that for now...
    DISPID id;
    AXTam *axcore = (AXTam *)core();
    OLECHAR *olename = (OLECHAR *)name->getName()->c_str();
    IDispatch *disp = (IDispatch *)getDispatch();
    HRESULT hr = disp->GetIDsOfNames(IID_NULL, &olename, 1, 0, &id);
    // ScriptObject::setMultinameProperty just throws an exception, so
    // no point trying it...
    if (FAILED(hr))
        axcore->throwCOMConsumerError(hr);
    // Now create args for the call.
    EXCEPINFO ei;
    CComVariant arg;
    axcore->atomToVARIANT(value, &arg);
    DISPPARAMS params = {&arg, NULL, 1, 0};
    hr = disp->Invoke(id, IID_NULL, 0, DISPATCH_PROPERTYPUT, &params, NULL, &ei, NULL);
    if (FAILED(hr))
        axcore->throwCOMConsumerError(hr, &ei);
}
开发者ID:sigma-random,项目名称:tamarin-central,代码行数:26,代码来源:mscom.cpp

示例7: callProperty

Atom MSIDispatchConsumer::callProperty(avmplus::Multiname *name, int argc, avmplus::Atom *argv)
{
    // Not sure how to best handle this re 'builtin' names, such as toString()
    // XXX - need a map of DISPIDs to speed things up, and/or optimizations
    // using the typelib.
    DISPID id;
    AXTam *axcore = (AXTam *)core();
    IDispatch *disp = (IDispatch *)getDispatch();
    OLECHAR *olename = (OLECHAR *)name->getName()->c_str();
    HRESULT hr = disp->GetIDsOfNames(IID_NULL, &olename, 1, 0, &id);
    if (hr == DISP_E_UNKNOWNNAME) {
        // not a name this object has - see if its builtin.
        return ScriptObject::callProperty(name, argc, argv);
    }
    if (FAILED(hr))
        axcore->throwCOMConsumerError(hr);
    // Now create args for the call.
    EXCEPINFO ei;
    CComVariant *pArgs = new CComVariant[argc];
    //memset(pArgs, 0, sizeof(VARIANT) * argc);
    // Take care to not early exit without cleaning up variants
    int i;
    for (i=0; i<argc; i++) {
        //VariantInit(pArgs+i);
        axcore->atomToVARIANT(argv[i+1], pArgs+i);
    }
    DISPPARAMS params = {pArgs, NULL, argc, 0};
    CComVariant ret;
    hr = disp->Invoke(id, IID_NULL, 0, DISPATCH_METHOD, &params, &ret, &ei, NULL);
    //for (i=0;i<argc;i++)
    //	VariantClear(pArg+i);
    delete [] pArgs;
    if (FAILED(hr))
        axcore->throwCOMConsumerError(hr, &ei);
    return axcore->toAtom(ret);
}
开发者ID:sigma-random,项目名称:tamarin-central,代码行数:36,代码来源:mscom.cpp

示例8: OnDocumentComplete

void CDownloads_Opinions_WBEvents::OnDocumentComplete(LPDISPATCH pdWB, VARIANT *URL)
{
	IWebBrowser2Ptr spWB (pdWB);
	if (spWB == NULL)
		return;

	IDispatchPtr spdDoc;
	spWB->get_Document (&spdDoc);
	IHTMLDocumentPtr spDoc (spdDoc);
	if (spDoc == NULL)
		return;

	ICustomDocPtr spCD (spDoc); 
	if (spCD != NULL)
		spCD->SetUIHandler (&m_wbUIHandler);

	bool bSetTab = false;
	if (m_pwndOpinions->m_cSetAsCurrentTabAfterLoadComplete)
	{
		InterlockedDecrement (&m_pwndOpinions->m_cSetAsCurrentTabAfterLoadComplete);
		bSetTab = true;
	}

	if (m_pwndOpinions->m_dld == NULL)
		return;

	if (bSetTab)
		_pwndDownloads->m_wndDownloads.m_info.set_CurTab (DIT_OPINIONS);

	

	IDispatch *pdScript;
	spDoc->get_Script (&pdScript);
	if (pdScript == NULL)
		return;

	

	DISPID didFun;
	OLECHAR* pwszFunName = L"processform";

	HRESULT hr;
	hr = pdScript->GetIDsOfNames (IID_NULL, &pwszFunName, 1, LOCALE_SYSTEM_DEFAULT, &didFun);
	if (FAILED (hr))
		return;	
	
	COleVariant vtResult;
	BYTE params [] = {VTS_BSTR VTS_BSTR VTS_BSTR VTS_BSTR VTS_BSTR};

	
	

	CString strVersion;
	CMainFrame* pFrm = (CMainFrame*)AfxGetApp ()->m_pMainWnd;
	strVersion.Format ("%s_%d", vmsFdmAppMgr::getBuildNumberAsString (), pFrm->m_Customizations.get_AffiliateID ());

	CString strState;
	if (m_pwndOpinions->m_dld->pMgr->IsDone ())
		strState = "Downloaded";
	else if (m_pwndOpinions->m_dld->pMgr->IsRunning ())
		strState = "Downloading";
	else
		strState = "Paused";
	CString strSize;
	UINT64 u = m_pwndOpinions->m_dld->pMgr->GetSSFileSize ();
	if (u != _UI64_MAX) {
		char sz [100];
		_i64toa ((__int64)u, sz, 10);
		strSize = sz;
	}
	else
		strSize = "Unknown";
	CString strComment = m_pwndOpinions->m_dld->strComment;
	strComment.Replace ("\r\n", " ");
	strComment.Replace ("\r", " ");
	strComment.Replace ("\n", " ");

	

	CString strUrl;
	if (m_pwndOpinions->m_dld->pMgr->IsBittorrent ())
		strUrl = m_pwndOpinions->m_dld->pMgr->GetBtDownloadMgr ()->get_InfoHash ();
	else
		strUrl = m_pwndOpinions->m_dld->pMgr->get_URL ();

	COleDispatchDriver ddr (pdScript);
	ddr.InvokeHelper (didFun, DISPATCH_METHOD, VT_VARIANT, (void*)&vtResult,
		params, strVersion, strUrl, strComment, 
		strState, strSize); 

	
	
	
	
	RetrieveLinkToUsText (spdDoc);
}
开发者ID:HackLinux,项目名称:Free-Download-Manager-vs2010,代码行数:96,代码来源:Downloads_Opinions_WBEvents.cpp

示例9: DisplayDialogs

int DisplayDialogs(HWND hWnd, int nDialog)
{
	// Let's make a little bit COM
	HRESULT hr;
	IUnknown *pUnknown;
	CLSID ClsID;

	hr = CLSIDFromProgID(OLESTR("VPinMAME.Controller"), &ClsID);
	if ( FAILED(hr) ) {
		DisplayError(hWnd, hr, "Class couldn't be found. Maybe it isn't registered");
		return 0;
	}

	hr = CoCreateInstance(ClsID, NULL, CLSCTX_INPROC_SERVER, IID_IUnknown, (void**) &pUnknown);
	if ( FAILED(hr) ) {
		DisplayError(hWnd, hr, "Can't create the Controller class! \nPlease check that you have installed Visual PinMAME properly!");
		return 0;
	}

	// Don't want to include the header files for the class, so let's using IDispatch
	IDispatch *pDispatch;
	
	hr = pUnknown->QueryInterface(IID_IDispatch, (void**) &pDispatch);
	if ( FAILED(hr) ) {
		DisplayError(hWnd, hr, "Can't get the dispatch interface");
		pUnknown->Release();
		return 0;
	}

	OLECHAR *pszName[3] = {L"ShowPathesDialog", L"ShowOptsDialog", L"ShowAboutDialog"};
	DISPID dispid;

	hr = pDispatch->GetIDsOfNames(IID_NULL, &pszName[nDialog], 1, LOCALE_SYSTEM_DEFAULT, &dispid);
	if ( FAILED(hr) ) {
		DisplayError(hWnd, hr, "Can't get the dispatch interface");
		pDispatch->Release();
		pUnknown->Release();
		return 0;
	}
	
	VARIANT varParam;
	varParam.vt   = VT_I4;
	varParam.lVal = (long) hWnd;

	DISPPARAMS DispParams = {&varParam,NULL,1,0};
	EXCEPINFO ExcepInfo;
	hr = pDispatch->Invoke(dispid, IID_NULL, LOCALE_SYSTEM_DEFAULT, DISPATCH_METHOD, &DispParams, NULL, &ExcepInfo, NULL);

	if ( FAILED(hr) ) {
		if ( hr==DISP_E_EXCEPTION )
			// actually we call the ONLY UNICODE function in Windows 9x
			MessageBoxW(0, ExcepInfo.bstrDescription, L"Error from the VPinMAME.Controller interface", MB_ICONERROR|MB_OK);
		else 
			DisplayError(hWnd, hr, "Can't get the dispatch interface");

		pDispatch->Release();
		pUnknown->Release();
		return 0;
	}

	pDispatch->Release();
	pUnknown->Release();

	return 1;
}
开发者ID:chrisjubb,项目名称:pinmame,代码行数:65,代码来源:InstallVPinMAME.cpp

示例10: initialize

void indri::parse::WordDocumentExtractor::open( const std::string& filename ) {
  // open the document
  initialize();
  HRESULT hr;
  VARIANT result;
  DISPPARAMS parameters;
  VARIANT fileNameParameter;
  int location = filename.find_last_of("\\/");
  if(filename[location+1]=='~'){
    //skip temp-Word files
    LEMUR_THROW( LEMUR_RUNTIME_ERROR, "Skipping temp Word Files starting with ~, they cause trouble parsing. " + filename + "." );
  }

  _documentPath = filename;

  WCHAR widePathCopy[ MAX_PATH ];
  ::MultiByteToWideChar( CP_UTF8, 0, filename.c_str(), filename.length()+1, widePathCopy, MAX_PATH );

  fileNameParameter.vt = VT_BSTR;
  fileNameParameter.bstrVal = ::SysAllocString( widePathCopy );

  parameters.cArgs = 1;
  parameters.cNamedArgs = 0;
  parameters.rgdispidNamedArgs = NULL;
  parameters.rgvarg = &fileNameParameter; 

  hr = v_internal->_documentsDispatch->Invoke( v_internal->_openDispatchID,
                                               IID_NULL,
                                               LOCALE_SYSTEM_DEFAULT,
                                               DISPATCH_METHOD,
                                               &parameters,
                                               &result,
                                               NULL,
                                               NULL );
  
  if( FAILED(hr) ) {
    _officeHelper.AutoWrap(DISPATCH_METHOD, NULL,v_internal->_wordDispatch, L"Quit", 0);
    v_internal->_wordDispatch->Release();
    LEMUR_THROW( LEMUR_RUNTIME_ERROR, "Couldn't open file " + filename + "." );
  }

  IDispatch* documentDispatch = result.pdispVal;



  // get content dispatch ID
  DISPID contentDispatchID;
  LPOLESTR contentPropertyName = L"Content";

  hr = documentDispatch->GetIDsOfNames( IID_NULL,
                                        &contentPropertyName,
                                        1,
                                        LOCALE_SYSTEM_DEFAULT,
                                        &contentDispatchID );

  if( FAILED(hr) ) {
    closeWord(documentDispatch,true);
    LEMUR_THROW( LEMUR_RUNTIME_ERROR, "Couldn't get ID of \"Content\" for file " + filename + "." );
  }


  // fetch the content property
  DISPPARAMS noParameters = { NULL, NULL, 0, 0 };

  hr = documentDispatch->Invoke( contentDispatchID,
                                 IID_NULL,
                                 LOCALE_SYSTEM_DEFAULT,
                                 DISPATCH_PROPERTYGET,
                                 &noParameters,
                                 &result,
                                 NULL,
                                 NULL );

  if( FAILED(hr) ) {
    closeWord(documentDispatch,true);
    LEMUR_THROW( LEMUR_RUNTIME_ERROR, "Couldn't get content for file " + filename + "." );
  }

  IDispatch* contentDispatch = result.pdispVal;

  // get the Text property dispatch ID
  DISPID textDispatchID;
  LPOLESTR textPropertyName = L"Text";

  hr = contentDispatch->GetIDsOfNames( IID_NULL,
                                       &textPropertyName,
                                       1,
                                       LOCALE_SYSTEM_DEFAULT,
                                       &textDispatchID );

  if( FAILED(hr) ) {
    closeWord(documentDispatch,true);
    LEMUR_THROW( LEMUR_RUNTIME_ERROR, "Couldn't get text for file " + filename + "." );
  }

  // call the text method on the content
  hr = contentDispatch->Invoke( textDispatchID,
                                IID_NULL,
                                LOCALE_SYSTEM_DEFAULT,
                                DISPATCH_PROPERTYGET,
//.........这里部分代码省略.........
开发者ID:wangxuemin,项目名称:coding,代码行数:101,代码来源:WordDocumentExtractor.cpp

示例11: ExecuteScript

    VARIANT ExecuteScript(IWebBrowser2 *pWebBrowser, const SStringW & fun,SArray<SStringW> & params)
    {
        VARIANT varErr;
        VariantInit( &varErr );

        //get document dispatch interface
        IDispatch* pDisp = NULL;

        HRESULT hr = pWebBrowser->get_Document( &pDisp );

        if ( FAILED( hr ) || pDisp == NULL )
        {
            return varErr;
        }

        IHTMLDocument2* pDoc = NULL;
        pDisp->QueryInterface( IID_IHTMLDocument2,(void**)&pDoc );
        pDisp->Release();

        IDispatch* pScript = NULL;
        hr = pDoc->get_Script( &pScript );
        pDoc->Release();

        if ( FAILED( hr ) || pScript == NULL )
        {
            return varErr;
        }

        sbstr bstrMember((int)fun.GetLength(),fun );
        DISPID dispid = 0;
        BSTR bstr = (BSTR)bstrMember;
        hr = pScript->GetIDsOfNames( IID_NULL,&(bstr),1,LOCALE_SYSTEM_DEFAULT,&dispid );

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

        DISPPARAMS dispparams;
        ::ZeroMemory( &dispparams,sizeof( DISPPARAMS ) );
        dispparams.cArgs = (UINT)params.GetCount();
        dispparams.rgvarg = new VARIANT[dispparams.cArgs];
        dispparams.cNamedArgs = 0;

        for ( size_t i = 0;i < params.GetCount();i++ )
        {
            size_t indx = params.GetCount() - i - 1;
            sbstr bstrParam((int)params[indx].GetLength(),params[indx]);
            dispparams.rgvarg[i].bstrVal = bstrParam.Release();
            dispparams.rgvarg[i].vt = VT_BSTR;
        }

        EXCEPINFO excepinfo;
        ::ZeroMemory( &excepinfo,sizeof( EXCEPINFO ) );
        VARIANT varRet;
        UINT nArgErr = (UINT)-1;	//initialize to invalid arg

        hr = pScript->Invoke( dispid,IID_NULL,0,DISPATCH_METHOD,&dispparams,&varRet,&excepinfo,&nArgErr );

        delete []dispparams.rgvarg;
        pScript->Release();

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

        return varRet;
    }
开发者ID:FuckGOV,项目名称:soui,代码行数:69,代码来源:SDocHostUIHandler.cpp

示例12: ExecScript

// thanks to Eugene Khodakovsky (I've just modified his code to make more lazy script call)
BOOL CHtmlViewer::ExecScript(TCHAR* ScriptContent,VARIANT* pScriptResult,EXCEPINFO* pExcepInfo)
{
    HRESULT hr = S_OK;

    IDispatch* pHtmlDocDispatch = NULL;
    IHTMLDocument2* pHtmlDoc = NULL;
    DISPID dispid = NULL;
    BSTR bstrMember;
    IDispatch* spScript;

    if (IsBadWritePtr(pExcepInfo,sizeof(EXCEPINFO)))
        return FALSE;

    memset(pExcepInfo, 0, sizeof(EXCEPINFO));
    pScriptResult->vt=VT_EMPTY;

    // Retrieve the document object.

    hr = pIWebBrowser->get_Document(&pHtmlDocDispatch);
    if (SUCCEEDED (hr) && (pHtmlDocDispatch != NULL))
    {
        hr = pHtmlDocDispatch->QueryInterface(IID_IHTMLDocument2,(void**)&pHtmlDoc);
        if (SUCCEEDED (hr) && (pHtmlDoc != NULL))
        {
            //Getting IDispatch for Java Script objects
            hr = pHtmlDoc->get_Script(&spScript);

            if (SUCCEEDED (hr) && (spScript != NULL))
            {
                bstrMember=SysAllocString(L"eval");// THE trick is here
                if (bstrMember)
                {
                    hr = spScript->GetIDsOfNames(IID_NULL,&bstrMember,1,LOCALE_SYSTEM_DEFAULT,&dispid);

                    if (SUCCEEDED (hr))
                    {
                        //Putting parameters
                        DISPPARAMS dispparams;
                        memset(&dispparams, 0, sizeof (DISPPARAMS));
                        dispparams.cArgs      = 1;
                        dispparams.rgvarg     = new VARIANT[dispparams.cArgs];
                        dispparams.cNamedArgs = 0;

                        dispparams.rgvarg[0].vt = VT_BSTR;

                        WCHAR* wScriptContent;
#if (defined(UNICODE)||defined(_UNICODE))
                        wScriptContent=ScriptContent;
#else
                        CAnsiUnicodeConvert::AnsiToUnicode(ScriptContent,&wScriptContent);
#endif
                        dispparams.rgvarg[0].bstrVal = SysAllocString(wScriptContent);

#if ((!defined(UNICODE))&& (!defined(_UNICODE)))
                        free(wScriptContent);
#endif
                        /*
                        // code for those who want to do the same thing
                        // using an array of string "const CStringArray& paramArray" as parameter
                        // instead of eval tips
                        
                        const int arraySize = paramArray.GetSize();
                        //Putting parameters
                        DISPPARAMS dispparams;
                        memset(&dispparams, 0, sizeof dispparams);
                        dispparams.cArgs      = arraySize;
                        dispparams.rgvarg     = new VARIANT[dispparams.cArgs];
                        dispparams.cNamedArgs = 0;

                        for( int i = 0; i < arraySize; i++)
                        {
                            CComBSTR> bstr = paramArray.GetAt(arraySize - 1 - i);
                            // back reading
                            bstr.CopyTo(&dispparams.rgvarg[i].bstrVal);
                            dispparams.rgvarg[i].vt = VT_BSTR;
                        }
                        */

                        if (dispparams.rgvarg[0].bstrVal)
                        {
                            UINT nArgErr = (UINT)-1;// initialize to invalid arg
                            //Call JavaScript function
                            hr = spScript->Invoke(dispid,
                                                    IID_NULL,
                                                    0,
                                                    DISPATCH_METHOD,
                                                    &dispparams,
                                                    pScriptResult,
                                                    pExcepInfo,
                                                    &nArgErr);

                            SysFreeString(dispparams.rgvarg[0].bstrVal);
                        }

                        delete [] dispparams.rgvarg;
                    }

                    SysFreeString(bstrMember);
                }
//.........这里部分代码省略.........
开发者ID:340211173,项目名称:hf-2011,代码行数:101,代码来源:HtmlViewer.cpp

示例13: _tmain


//.........这里部分代码省略.........

				if (SUCCEEDED(hr)) {
					// FINALLY can call methods on pErrorInfo! ...and handle the error!

					_bstr_t bstrErrorDescription;
					pErrorInfo->GetDescription(bstrErrorDescription.GetAddress());

					// エラー情報
					MessageBox(NULL, bstrErrorDescription, L"ErrorDescription", MB_OK);

					// don't forget to release!
					pErrorInfo->Release();
				}
			}

			// don't forget to release!
			pSupport->Release();
		}
	}

	// don't forget to release!
	pClassTest->Release();

	// ----------------------------------------------------------------------------------------------------
	// ----------------------------------------------------------------------------------------------------

	// <以下のコードは、レイトバインディング方式での呼び出し>

	// CLSID の取得
    CLSID clsid;
    hr = CLSIDFromProgID(L"VC_COM.ClassTest", &clsid);

    if(FAILED(hr)){
        printf("CLSIDFromProgID 失敗\n");
        return 0;
    }

	// インスタンスの作成(CLSIDとIID:[IID_IDispatch]を指定して、ポインタを取得)
    IDispatch* pDisp = NULL;
    hr = ::CoCreateInstance(clsid, NULL, CLSCTX_ALL, IID_IDispatch, (void**)&pDisp);

    if(FAILED(hr)){
        printf("CoCreateInstance 失敗\n");
        return 0;
    }
	
	// COMディスパッチ識別子の取得
	DISPID dispID;
	OLECHAR* wszName = L"MethodTest";
	hr = pDisp->GetIDsOfNames(IID_NULL, &wszName, 1, LOCALE_USER_DEFAULT, &dispID);

	if(FAILED(hr)){
        printf("GetIDsOfNames 失敗\n");
        exit(1);
    }
	
	// CComVariant クラス(CComVariant は VARIANT 型から派生)
	// http://msdn.microsoft.com/ja-jp/library/ac97df2h.aspx

	// 引数を VARIANT 配列に設定
    CComVariant pvArgs[2];
	pvArgs[0] = L"だいすけ";
	pvArgs[1] = L"にしの";

	// 戻り値を VARIANT変数
	CComVariant pvResult;

	// DISPPARAMS の設定
    DISPPARAMS dispParams;

    dispParams.rgvarg = pvArgs;
    dispParams.rgdispidNamedArgs = NULL;
    dispParams.cArgs = 2;
    dispParams.cNamedArgs = 0;

	// メソッドにレイトバインド(Invoke)
	hr = pDisp->Invoke(dispID, IID_NULL,
		LOCALE_USER_DEFAULT, DISPATCH_METHOD,
		&dispParams, &pvResult, NULL, NULL);

	if(FAILED(hr)){
        printf("MethodTest 失敗\n");
        return 0;
    }

	// BSTRで格納されている時、tagVARIANTのメンバ、bstrValで取得可能。
	// BSTRはOLECHAR(= WCHAR)のポインタなのでLPWSTRにキャスト可能。
	MessageBox(NULL, (LPWSTR)pvResult.bstrVal, L"戻り値", MB_OK);

	// don't forget to release!
	pDisp->Release();

	// ----------------------------------------------------------------------------------------------------
	// ----------------------------------------------------------------------------------------------------

    // COMの終了処理 ◆◆追加
    ::CoUninitialize();

    return 0;
}
开发者ID:NorihiroFukuyama,项目名称:SampleProgram,代码行数:101,代码来源:VC_Client3.cpp

示例14: getReturnVal

void comauto::CommonLanguageRuntime::call( tagVARIANT* res, const std::wstring& assembly_, const std::wstring& class_, const std::wstring& method_, unsigned int argc, const tagVARIANT* argv, unsigned int lcid) const
{
	struct Local
	{
		Local() {::memset( this, 0, sizeof( *this)); varResult.vt = VT_EMPTY;}
		~Local()
		{
			if (spType) spType->Release();
			if (spAssembly) spAssembly->Release();
			if (spDefaultAppDomain) spDefaultAppDomain->Release();
		}
		EXCEPINFO excepInfo;
		VARIANT varResult; 
		DISPPARAMS dispParams;
		IUnknownPtr spAppDomainThunk;
		_AppDomainPtr spDefaultAppDomain; 
		_AssemblyPtr spAssembly; 
		_TypePtr spType;

		void getReturnVal( VARIANT* res)
		{
			std::memcpy( res, &varResult, sizeof(varResult));
			varResult.vt = VT_EMPTY;
			return;
		}
	};
	Local local;

	// The identifiers of the method in the .NET class to invoke:
	bstr_t bstrAssemblyName( assembly_.c_str()); 
	bstr_t bstrClassName( class_.c_str()); 
	bstr_t bstrMethodName( method_.c_str()); 
 
	WRAP( m_impl->m_runtimehost->GetDefaultDomain( &local.spAppDomainThunk));
	WRAP( local.spAppDomainThunk->QueryInterface( IID_PPV_ARGS( &local.spDefaultAppDomain)));
	WRAP( local.spDefaultAppDomain->Load_2( bstrAssemblyName, &local.spAssembly));
	WRAP( local.spAssembly->GetType_2( bstrClassName, &local.spType));

	// Create an instance of the object to invoke the method:
	variant_t vtObject;
	WRAP( local.spAssembly->CreateInstance( bstrClassName, &vtObject));
	if (!vtObject.punkVal)
	{
		throw std::runtime_error( std::string( "class definition not found '") + utf8string( bstrClassName.GetBSTR()) + "'");
	}

	// Initialize the method arguments structure:
	local.dispParams.cNamedArgs = 0;
	local.dispParams.cArgs = argc;
	local.dispParams.rgvarg = const_cast<VARIANT*>(argv);

	// Get the method invoker interface (IDispatch):
	IDispatch* dispatch = NULL;
	WRAP( vtObject.punkVal->QueryInterface( IID_IDispatch, (void**)&dispatch));

	// Get the method handle:
	DISPID gDispId = 0;
	LPOLESTR bstrMethodName_ = bstrMethodName;
	WRAP( dispatch->GetIDsOfNames( IID_NULL, &bstrMethodName_, 1, lcid, &gDispId));

	// Call that method:
	UINT puArgErr;
	HRESULT hr = dispatch->Invoke( gDispId, IID_NULL, lcid, DISPATCH_METHOD, &local.dispParams, &local.varResult, &local.excepInfo, &puArgErr);
	if (hr != S_OK)
	{
		std::string methodname = comauto::utf8string(class_) + "." + comauto::utf8string(method_);
		if (hr == DISP_E_EXCEPTION)
		{
			throw std::runtime_error( std::string("Error calling ") + methodname + " " + comauto::tostring( local.excepInfo));
		}
		else
		{
			_com_error error(hr);
			std::ostringstream errcode; 
			errcode << std::hex << " [0x" << hr << "]";
			throw std::runtime_error( std::string("Error calling ") + methodname + ": '" + comauto::utf8string(error.ErrorMessage()) + errcode.str());
		}
	}
	local.getReturnVal( res);
}
开发者ID:ProjectTegano,项目名称:Tegano,代码行数:80,代码来源:clr.cpp

示例15: PyErr_Format

// @pymethod (int, ...)/int|PyIDispatch|GetIDsOfNames|Get the DISPID for the passed names.
PyObject *PyIDispatch::GetIDsOfNames(PyObject *self, PyObject *args)
{
	// @rdesc If the first parameter is a sequence, the result will be a tuple of integers
	// for each name in the sequence.  If the first parameter is a single string, the result
	// is a single integer with the ID of requested item.
	UINT i;

	// @pyparm string|name||A name to query for
	// @pyparmalt1 [string, ...]|[name, ...]||A sequence of string names to query
	// @comm Currently the LCID can not be specified, and  LOCALE_SYSTEM_DEFAULT is used.
	int argc = PyTuple_GET_SIZE(args);
	if ( argc < 1 )
		return PyErr_Format(PyExc_TypeError, "At least one argument must be supplied");

	LCID lcid = LOCALE_SYSTEM_DEFAULT;
	UINT offset = 0;
	if ( argc > 1 ){
		PyObject *ob = PyTuple_GET_ITEM(args, 0);
		lcid=PyLong_AsLong(ob);
		if (lcid==-1 && PyErr_Occurred()){
			PyErr_Clear();
			lcid=LOCALE_SYSTEM_DEFAULT;
			}
		else
			offset = 1;
		}

	UINT cNames = argc - offset;
	OLECHAR FAR* FAR* rgszNames = new LPOLESTR[cNames];

	for ( i = 0 ; i < cNames; ++i )
	{
		PyObject *ob = PySequence_GetItem(args, i + offset);
		if ( !ob )
		{
			for (;i>0;i--)
				PyWinObject_FreeBstr(rgszNames[i-1]);
			delete [] rgszNames;
			return NULL;
		}
		if (!PyWinObject_AsBstr(ob, rgszNames+i)) {
			for (;i>0;i--)
				PyWinObject_FreeBstr(rgszNames[i-1]);
			delete [] rgszNames;
			return NULL;
		}
		Py_DECREF(ob);
	}

	DISPID FAR* rgdispid = new DISPID[cNames];
	IDispatch *pMyDispatch = GetI(self);
	if (pMyDispatch==NULL) return NULL;
	PY_INTERFACE_PRECALL;
	HRESULT hr = pMyDispatch->GetIDsOfNames(IID_NULL, rgszNames, cNames, lcid, rgdispid);
	PY_INTERFACE_POSTCALL;

	for (i=0;i<cNames;i++)
		PyWinObject_FreeBstr(rgszNames[i]);
	delete [] rgszNames;

	if ( FAILED(hr) )
		return PyCom_BuildPyException(hr, pMyDispatch, IID_IDispatch);

	PyObject *result;

	/* if we have just one name, then return a single DISPID (int) */
	if ( cNames == 1 )
	{
		result = PyInt_FromLong(rgdispid[0]);
	}
	else
	{
		result = PyTuple_New(cNames);
		if ( result )
		{
			for ( i = 0; i < cNames; ++i )
			{
				PyObject *ob = PyInt_FromLong(rgdispid[i]);
				if ( !ob )
				{
					delete [] rgdispid;
					return NULL;
				}
				PyTuple_SET_ITEM(result, i, ob);
			}
		}
	}

	delete [] rgdispid;
	return result;
}
开发者ID:malrsrch,项目名称:pywin32,代码行数:92,代码来源:PyIDispatch.cpp


注:本文中的IDispatch::GetIDsOfNames方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。