Exemplo n.º 1
0
ITypeDecl* getRef( CTypeDecl* pTypeInfo, HREFTYPE href ) {
	ITypeInfoPtr pRefType;
	if(FAILED(pTypeInfo->m_pType->GetRefTypeInfo( href, &pRefType )))
		return NULL;

	ITypeLibPtr pLib;
	UINT index;
	if(FAILED(pRefType->GetContainingTypeLib(&pLib,&index)))
		return NULL;
	
	// if we already have CTypeDecl for this pRefType, return it.
	return static_cast<IInterfaceDecl*>(CTypeLib::get(pLib)->getChild(pRefType));
}
Exemplo n.º 2
0
void EnumTypeLib(ITypeLib *typeLib, EnumTypeLibProc pfn)
{
    UINT count = typeLib->GetTypeInfoCount();
    for (UINT i = 0; i < count; i++)
    {
        ITypeInfoPtr typeInfo;
        typeLib->GetTypeInfo(i, &typeInfo);
        TYPEATTR *typeAttr = NULL;
        typeInfo->GetTypeAttr(&typeAttr);
        pfn(typeInfo, typeAttr);
        typeInfo->ReleaseTypeAttr(typeAttr);
    }
}
Exemplo n.º 3
0
HRESULT GetDispatchProperty(IDispatch* pDisp, LPOLESTR lpName, VARIANT* pRes)
{
#ifdef _DEBUG
	ITypeInfoPtr pTypeInfo;
	LPTYPEATTR pTypeAttr;
	pDisp->GetTypeInfo(1, GetSystemDefaultLCID(), &pTypeInfo);
	pTypeInfo->GetTypeAttr(&pTypeAttr);
	pTypeInfo->ReleaseTypeAttr(pTypeAttr);
#endif
	DISPID DispId = 0;
	HRESULT hr = pDisp->GetIDsOfNames(IID_NULL, &lpName, 1, GetSystemDefaultLCID(), &DispId);
	if (hr != S_OK)
		return hr;
	_variant_t varRes;
	unsigned int ArgError;
	DISPPARAMS Params;
	Params.cArgs = 0;
	Params.rgvarg = NULL;
	Params.cNamedArgs = 0;
	Params.rgdispidNamedArgs = NULL;
	hr = pDisp->Invoke(DispId, IID_NULL, GetSystemDefaultLCID(), DISPATCH_PROPERTYGET, &Params, pRes, NULL, &ArgError);
	return hr;
}
Exemplo n.º 4
0
HRESULT CScript::LoadScript( LPCTSTR pszFileName, LPCTSTR pszScriptName )
{
   ITypeInfoPtr pTypeInfo;
   HRESULT hResult;
   CLSID clsid;
   CFile file;
   ULONGLONG nFileSize;
   BSTR bstrScript;
   BOOL tSuccess;
   int iMethod;
   UINT nNames;
   BSTR bstrName;
   CString strName;
   CString strExtension;
   int iChar;

   ENSURE( pszFileName != NULL );
   ENSURE( pszScriptName != NULL );
   ENSURE( m_pActiveScript == NULL );

   iChar = lstrlen( pszFileName )-1;
   while( (iChar >= 0) && (pszFileName[iChar] != _T( '.' )) )
   {
	  iChar--;
   }

   if( (iChar >= 0) && (_tcsicmp( &pszFileName[iChar], _T( ".js" ) ) == 0) )
   {
	  hResult = CLSIDFromProgID( L"JScript", &clsid );
	  if( FAILED( hResult ) )
	  {
		 return( hResult );
	  }
   }
   else
   {
	  hResult = CLSIDFromProgID( L"VBScript", &clsid );
	  if( FAILED( hResult ) )
	  {
		 return( hResult );
	  }
   }

   hResult = m_pActiveScript.CreateInstance( clsid, NULL,
	  CLSCTX_INPROC_SERVER );
   if( FAILED( hResult ) )
   {
	  return( hResult );
   }

   m_pActiveScriptParse = m_pActiveScript;
   if( m_pActiveScriptParse == NULL )
   {
	  return( E_NOINTERFACE );
   }

   hResult = m_pActiveScript->SetScriptSite( &m_xActiveScriptSite );
   if( FAILED( hResult ) )
   {
	  return( hResult );
   }

   hResult = m_pActiveScriptParse->InitNew();
   if( FAILED( hResult ) )
   {
	  return( hResult );
   }

   CFileException error;
   tSuccess = file.Open( pszFileName, CFile::modeRead|CFile::shareDenyWrite,
	  &error );
   if( !tSuccess )
   {
	  return( HRESULT_FROM_WIN32( error.m_lOsError ) );
   }

   nFileSize = file.GetLength();
   if( nFileSize > INT_MAX )
   {
      return( E_OUTOFMEMORY );
   }

   nFileSize = file.Read( m_strScriptText.GetBuffer( ULONG( nFileSize ) ), ULONG( nFileSize ) );
   file.Close();
   m_strScriptText.ReleaseBuffer( ULONG( nFileSize ) );
   bstrScript = m_strScriptText.AllocSysString();

   hResult = m_pActiveScriptParse->ParseScriptText( bstrScript, NULL, NULL,
	  NULL, DWORD( this ), 0, SCRIPTTEXT_ISVISIBLE, NULL, NULL );
   SysFreeString( bstrScript );
   if( FAILED( hResult ) )
   {
	  return( hResult );
   }

   hResult = m_pManager->AddNamedItems( m_pActiveScript );
   if( FAILED( hResult ) )
   {
	  return( hResult );
   }

   hResult = m_pActiveScript->SetScriptState( SCRIPTSTATE_CONNECTED );
   if( FAILED( hResult ) )
   {
	  return( hResult );
   }

   hResult = m_pActiveScript->GetScriptDispatch( NULL, &m_pDispatch );
   if( FAILED( hResult ) )
   {
	  return( hResult );
   }

   hResult = m_pDispatch->GetTypeInfo( 0, GetUserDefaultLCID(), &pTypeInfo );
   if( FAILED( hResult ) )
   {
	  return( hResult );
   }

   CSmartTypeAttr pTypeAttr( pTypeInfo );
   CSmartFuncDesc pFuncDesc( pTypeInfo );

   hResult = pTypeInfo->GetTypeAttr( &pTypeAttr );
   if( FAILED( hResult ) )
   {
	  return( hResult );
   }

   for( iMethod = 0; iMethod < pTypeAttr->cFuncs; iMethod++ )
   {
	  hResult = pTypeInfo->GetFuncDesc( iMethod, &pFuncDesc );
	  if( FAILED( hResult ) )
	  {
		 return( hResult );
	  }

	  if( (pFuncDesc->funckind == FUNC_DISPATCH) && (pFuncDesc->invkind ==
		 INVOKE_FUNC) && (pFuncDesc->cParams == 0) )
	  {
		 bstrName = NULL;
		 hResult = pTypeInfo->GetNames( pFuncDesc->memid, &bstrName, 1,
			&nNames );
		 if( FAILED( hResult ) )
		 {
			return( hResult );
		 }
		 ASSERT( nNames == 1 );

		 strName = bstrName;
		 SysFreeString( bstrName );
		 bstrName = NULL;

		 // Macros can't contain underscores, since those denote event handlers
		 if( strName.Find( _T( '_' ) ) == -1 )
		 {
			m_mapMacros.SetAt( strName, pFuncDesc->memid );
		 }
	  }

	  pFuncDesc.Release();
   }

   m_strScriptName = pszScriptName;

   return( S_OK );
}
Exemplo n.º 5
0
void DumpXPCOMInterfaceIDL(FILE *f, ITypeInfo *tiInterface)
{
    HRESULT hr;

    // [scriptable, uuid(00000000-0000-0000-0000-000000000000)]
    // interface axIFoo : axIBar
    // {
    //    void method1();
    // };

    TYPEATTR *attr;
    tiInterface->GetTypeAttr(&attr);

    USES_CONVERSION;

    //
    // Attribute block
    //
    fputs("[scriptable, ", f);

    // uuid()
	WCHAR szGUID[64];
	StringFromGUID2(attr->guid, szGUID, sizeof(szGUID));
    szGUID[0] = L'(';
    szGUID[wcslen(szGUID) - 1] = L')';
    fprintf(f, "uuid%s", W2A(szGUID));
    
    fputs("]\n", f);


    //
    // Interface block
    //

    fprintf(f, "interface ");

    BSTR bstrName = NULL;
    hr = tiInterface->GetDocumentation(MEMBERID_NIL, &bstrName, NULL, NULL, NULL);
    fprintf(f, "ax%s", W2A(bstrName));
    SysFreeString(bstrName);

    // Check for the base interface
	for (UINT n = 0; n <  attr->cImplTypes; n++)
	{
		HREFTYPE href = NULL;
		if (FAILED(hr = tiInterface->GetRefTypeOfImplType(n, &href)))
           ;  // TODO

        ITypeInfoPtr tiParent;
		if (FAILED(hr = tiInterface->GetRefTypeInfo(href, &tiParent)))
           ; // TODO

		if (FAILED(hr = tiParent->GetDocumentation(MEMBERID_NIL, &bstrName, NULL, NULL, NULL)))
           ; // TODO

		fprintf(f, " : ax%s", W2A(bstrName));

		SysFreeString(bstrName);
        bstrName = NULL;

		tiParent.Release();
	}


    //
    // Methods and properties block
    //

    fprintf(f, "\n");
    fprintf(f, "{\n");


    for (n = 0; n < attr->cFuncs; n++)
    {
        FUNCDESC *func;
        tiInterface->GetFuncDesc(n, &func);

        fprintf(f, "  ");
        if (func->invkind & INVOKE_PROPERTYPUT ||
            func->invkind & INVOKE_PROPERTYGET)
		{
		}

        // Return type
        TypeDesc tf(tiInterface, &func->elemdescFunc.tdesc);
        if (tf.mType == TypeDesc::T_RESULT)
        {
            fprintf(f, "void ");
        }
        else
        {
            fprintf(f, "%s ", tf.ToXPIDLString().c_str());
        }

        // Method / property name
        BSTR bstrName = NULL;
    	tiInterface->GetDocumentation(func->memid, &bstrName, NULL, NULL, NULL);
        fprintf(f, "%s (\n", W2A(bstrName));
        SysFreeString(bstrName);

        // Get the names of all the arguments
		UINT cNames;
	    BSTR rgbstrNames[100];
  		hr = tiInterface->GetNames(func->memid, rgbstrNames, 100, (UINT FAR*) &cNames);

        // Dump out all parameters
        for (int p = 0; p < func->cParams; p++)
        {
            fputs("    ", f);

            BOOL isIn = FALSE;
            BOOL isOut = FALSE;

            // Keywords
			if (func->lprgelemdescParam[p].idldesc.wIDLFlags & IDLFLAG_FRETVAL)
			{
				fputs("[retval] ", f);
			}
			if (func->lprgelemdescParam[p].idldesc.wIDLFlags & IDLFLAG_FIN &&
                func->lprgelemdescParam[p].idldesc.wIDLFlags & IDLFLAG_FOUT)
            {
                fputs("inout ", f);
            }
            else if (func->lprgelemdescParam[p].idldesc.wIDLFlags & IDLFLAG_FIN)
            {
                fputs("in ", f);
            }
            else if (func->lprgelemdescParam[p].idldesc.wIDLFlags & IDLFLAG_FOUT)
            {
                fputs("out ", f);
            }

            // Type
            // NOTE: If the arg is an out param, lop off the first pointer reference,
            //       because XPIDL implicitly expects out params to be pointers.
            TypeDesc tp(tiInterface, &func->lprgelemdescParam[p].tdesc);
            if (tp.mType == TypeDesc::T_POINTER &&
                func->lprgelemdescParam[p].idldesc.wIDLFlags & IDLFLAG_FOUT)
            {
                fprintf(f, "%s ", tp.mData.mPtr->ToXPIDLString().c_str());
            }
            else
            {
                // Type
                fprintf(f, "%s ", tp.ToXPIDLString().c_str());
            }

            // Name
            fputs(W2A(rgbstrNames[p+1]), f);

            if (p < func->cParams - 1)
            {
                fprintf(f, ",\n");
            }
            else
            {
                fprintf(f, "\n");
            }
        	SysFreeString(rgbstrNames[0]);
        }
        fputs("  );\n", f);

        tiInterface->ReleaseFuncDesc(func);
    }


    // Fin
    fputs("};\n\n", f);

    tiInterface->ReleaseTypeAttr(attr);
}