Example #1
1
const Interface *
Reference::findInterfaceFromDispatch (IUnknown *pUnknown)
{
    HRESULT hr;

    // See if the object implements IDispatch.
    IDispatchPtr pDispatch;
    hr = pUnknown->QueryInterface(
        IID_IDispatch, reinterpret_cast<void **>(&pDispatch));
    if (FAILED(hr)) {
        return 0;
    }

    // Ask the IDispatch interface for type information.
    unsigned count;
    hr = pDispatch->GetTypeInfoCount(&count);
    if (hr == E_NOTIMPL) {
        return 0;
    }
    if (FAILED(hr)) {
        _com_issue_error(hr);
    }
    if (count == 0) {
        return 0;
    }

    ITypeInfoPtr pTypeInfo;
    hr = pDispatch->GetTypeInfo(
        0, 
        LOCALE_USER_DEFAULT,
        &pTypeInfo);
    if (FAILED(hr)) {
        _com_issue_error(hr);
    }

    // Get the interface description.
    TypeAttr typeAttr(pTypeInfo);

    if (IsEqualIID(typeAttr->guid, __uuidof(DotNetObject))) {
        // The .NET Framework implements IDispatch::GetTypeInfo for classes
        // declared with the attribute ClassInterface(ClassInterfaceType.None)
        // by returning a description of the _Object interface.
        return 0;
    }

    const Interface *pInterface =
        InterfaceManager::instance().newInterface(typeAttr->guid, pTypeInfo);

    if (pInterface->methods().empty() && pInterface->properties().empty()) {
        // No invokable methods or properties where found in the interface
        // description.
        return 0;
    }
    return pInterface;
}
EXPORT_C TInt CSenWsSecurityHeader::UsernameTokenL(const TDesC8& aUsername,
                                    const TDesC8& aPassword,
                                    CSenWsSecurityHeader::TPasswordType aType,
                                    HBufC8*& aToken)
    {
    switch(aType)
        {
        case EText:
            {
            return UsernameTokenL(aUsername, aPassword, aToken);
            }
        case EDigest:
            {
            TPtrC8 nsPrefix = KSecurityXmlNsPrefix();
            TPtrC8 typeAttr(KSecurityAttrTypeDigest);

            aToken = HBufC8::NewLC( KUsernameTokenStartTagFmt().Length() +
                                    KUsernameFmt().Length() +
                                    KUsernameTokenEndTag().Length() +
                                    KPasswordStartTagTypeFmt().Length() +
                                    KPasswordEndTagFmt().Length() +
                                    aUsername.Length() + 
                                    aPassword.Length() +
                                    typeAttr.Length() +
                                    nsPrefix.Length() * 7 );
            TPtr8 ptr = aToken->Des();
            ptr.Format(KUsernameTokenStartTagFmt, &nsPrefix);
            ptr.AppendFormat(KUsernameFmt, &nsPrefix, &aUsername, &nsPrefix);
            ptr.AppendFormat(KPasswordStartTagTypeFmt, &nsPrefix, &nsPrefix, 
                             &typeAttr, &aPassword); // Type = wsse:PasswordDigest
            ptr.AppendFormat(KPasswordEndTagFmt, &nsPrefix);
            ptr.AppendFormat(KUsernameTokenEndTag, &nsPrefix);
            CleanupStack::Pop();    // aToken
            return KErrNone;
            }
        default:
            {
            return KErrNotSupported;
            }
        }
    }
std::string stringifyCOMMethod(FUNCDESC* funcDesc, ITypeInfo* pti) 
{
	CComPtr<ITypeInfo> pTypeInfo(pti);
	std::ostringstream oss;
	const int MAX_NAMES = 256;
	CComBSTR name[MAX_NAMES];
	UINT cNames;

	// get parameter names

	HRESULT hr(pTypeInfo->GetNames(funcDesc->memid, reinterpret_cast<BSTR*>(&name), MAX_NAMES - 1, &cNames));
	if(hr)
		cNames = 0;
	else
	{
  		// fix for 'rhs' problem (see tblodl.cpp of MS Visual C++ OLEVIEW sample for more details)

		if (cNames != MAX_NAMES - 1 && (int)cNames < funcDesc->cParams + 1)
		{
			name[cNames] = ::SysAllocString(OLESTR("rhs")) ;
			cNames++;
		}
	}

	// function attribute (only IDL-style)

	if(g_bIDLStyle)
	{
		if(funcDesc->funckind == FUNC_DISPATCH)	
			oss<< "[id("<< (int)funcDesc->memid<< ')';
		else 
			oss<< "[VOffset("<< funcDesc->oVft<< ')';

		switch(funcDesc->invkind) 
		{
			case INVOKE_PROPERTYGET: 
				oss<< ", propget] "; 
				break;
			case INVOKE_PROPERTYPUT: 
				oss<< ", propput] "; 
				break;
			case INVOKE_PROPERTYPUTREF: 
				oss<< ", propputref] "; 
				break;
			case INVOKE_FUNC: oss<< "] "; 
				break;
		}
	}

	// function type

	oss<< stringifyTypeDesc(&funcDesc->elemdescFunc.tdesc, pTypeInfo);

	// calling convention (only C-style)

	if(!g_bIDLStyle)
	{
		CComTypeAttr typeAttr(pTypeInfo);

		if (typeAttr->typekind != TKIND_DISPATCH)
		{   // Write calling convention
			switch(funcDesc->callconv)
			{
				case CC_CDECL:
					oss<< " _cdecl";           
					break ;
				/*
				case CC_MSCPASCAL:  
					oss<< " _mspascal";        
					break ;
				*/
				case CC_PASCAL:     
					oss<< " _pascal";          
					break ;
				case CC_MACPASCAL:  
					oss<< " _macpascal";       
					break ;
				case CC_STDCALL :   
					oss<< " _stdcall";          
					break ;
				/*
				case CC_RESERVED:   
					oss<< " _reserved";         
					break ;
				*/
				case CC_SYSCALL:    
					oss<< " _syscall";          
					break ;
				case CC_MPWCDECL:   
					oss<< " _mpwcdecl";         
					break ;
				case CC_MPWPASCAL:  
					oss<< " _mpwpascal";        
					break ;
			}
		}
	}

	// function name

	CComBSTR bstrName;
	pTypeInfo->GetDocumentation(funcDesc->memid, &bstrName, 0, 0, 0);

	char ansiName[MAX_PATH];
	WideCharToMultiByte(CP_ACP, 0, bstrName, bstrName.Length() + 1, ansiName, MAX_PATH, 0, 0);

	oss<< ' '<< ansiName<< '(';


	// first parameter is hidden "this" pointer (C-style only)

	if(!g_bIDLStyle)
	{
		oss<< "void *pThis";
		if(funcDesc->cParams) 
			oss<< ", ";
	}

	// parameters

	for(int curParam(0); curParam < funcDesc->cParams; ++curParam) 
	{
		oss<< stringifyFunctionArgument(&funcDesc->lprgelemdescParam[curParam], pTypeInfo);

		// function parameter name (index 0 is the function name)

		if(cNames)
		{
			if(curParam + 1 < cNames)
			{
				WideCharToMultiByte(CP_ACP, 0, name[curParam + 1], name[curParam + 1].Length() + 1, ansiName, MAX_PATH, 0, 0);
				oss<< ' '<< ansiName;
			}
			else
				oss<< " arg" << (curParam + 1);
		}

		if(curParam < funcDesc->cParams - 1) 
			oss<< ", ";
	}

	// trailer

	if(g_bIDLStyle)
		oss<< ')';
	else
		oss<< ");";

	return oss.str();
}