#include "appdomain.inl"
#include "typestring.h"
-// The enum that describes the value of the IDispatchImplAttribute custom attribute.
-enum IDispatchImplType
-{
- SystemDefinedImpl = 0,
- InternalImpl = 1,
- CompatibleImpl = 2
-};
-
// The enum that describe the value of System.Runtime.InteropServices.CustomQueryInterfaceResult
// It is the return value of the method System.Runtime.InteropServices.ICustomQueryInterface.GetInterface
enum CustomQueryInterfaceResult
}
//--------------------------------------------------------------------------
-// Determines if the Compatible IDispatch implementation is required for
-// the specified class.
-//--------------------------------------------------------------------------
-bool IsOleAutDispImplRequiredForClass(MethodTable *pClass)
-{
- CONTRACTL
- {
- THROWS;
- GC_NOTRIGGER;
- MODE_ANY;
- PRECONDITION(CheckPointer(pClass));
- }
- CONTRACTL_END;
-
- HRESULT hr;
- const BYTE * pVal;
- ULONG cbVal;
- Assembly * pAssembly = pClass->GetAssembly();
- IDispatchImplType DispImplType = SystemDefinedImpl;
-
- // First check for the IDispatchImplType custom attribute first.
- hr = pClass->GetCustomAttribute(WellKnownAttribute::IDispatchImpl, (const void**)&pVal, &cbVal);
- if (hr == S_OK)
- {
- CustomAttributeParser cap(pVal, cbVal);
- IfFailThrow(cap.SkipProlog());
- UINT8 u1;
- IfFailThrow(cap.GetU1(&u1));
-
- DispImplType = (IDispatchImplType)u1;
- if ((DispImplType > 2) || (DispImplType < 0))
- DispImplType = SystemDefinedImpl;
- }
-
- // If the custom attribute was set to something other than system defined then we will use that.
- if (DispImplType != SystemDefinedImpl)
- return (bool) (DispImplType == CompatibleImpl);
-
- // Check to see if the assembly has the IDispatchImplType attribute set.
- hr = pAssembly->GetCustomAttribute(pAssembly->GetManifestToken(), WellKnownAttribute::IDispatchImpl, (const void**)&pVal, &cbVal);
- if (hr == S_OK)
- {
- CustomAttributeParser cap(pVal, cbVal);
- IfFailThrow(cap.SkipProlog());
- UINT8 u1;
- IfFailThrow(cap.GetU1(&u1));
-
- DispImplType = (IDispatchImplType)u1;
- if ((DispImplType > 2) || (DispImplType < 0))
- DispImplType = SystemDefinedImpl;
- }
-
- // If the custom attribute was set to something other than system defined then we will use that.
- if (DispImplType != SystemDefinedImpl)
- return (bool) (DispImplType == CompatibleImpl);
-
- // Removed registry key check per reg cleanup bug 45978
- // Effect: Will return false so code cleanup
- return false;
-}
-
-//--------------------------------------------------------------------------
// This routine is called anytime a com method is invoked for the first time.
// It is responsible for generating the real stub.
//
pTemplate->m_flags |= enum_SupportsIClassX;
}
- if (IsOleAutDispImplRequiredForClass(pMT))
- {
- // Determine what IDispatch implementation this class should use
- pTemplate->m_flags |= enum_UseOleAutDispatchImpl;
- }
-
// Eagerly create the interface CMTs.
// when iterate the interfaces implemented by the methodtable, we can check whether
// the interface supports ICustomQueryInterface.
return (m_flags & enum_RepresentsVariantInterface);
}
- BOOL IsUseOleAutDispatchImpl()
- {
- LIMITED_METHOD_CONTRACT;
- return (m_flags & enum_UseOleAutDispatchImpl);
- }
-
BOOL ImplementsIMarshal()
{
LIMITED_METHOD_CONTRACT;
enum_RepresentsVariantInterface = 0x400, // this is a template for an interface with variance
- enum_UseOleAutDispatchImpl = 0x800, // the class is decorated with IDispatchImplAttribute(CompatibleImpl)
+ // enum_Unused = 0x800,
enum_ImplementsIMarshal = 0x1000, // the class implements a managed interface with Guid == IID_IMarshal
if (pCMT->HasInvisibleParent())
return E_NOTIMPL;
- ComCallWrapperTemplate *pTemplate = MapIUnknownToWrapper(pDisp)->GetComCallWrapperTemplate();
- if (pTemplate->IsUseOleAutDispatchImpl())
- {
- return OleAutDispatchImpl_GetIDsOfNames(pDisp, riid, rgszNames, cNames, lcid, rgdispid);
- }
-
return InternalDispatchImpl_GetIDsOfNames(pDisp, riid, rgszNames, cNames, lcid, rgdispid);
}
if (pCMT->HasInvisibleParent())
return E_NOTIMPL;
- ComCallWrapperTemplate *pTemplate = MapIUnknownToWrapper(pDisp)->GetComCallWrapperTemplate();
- if (pTemplate->IsUseOleAutDispatchImpl())
- {
- return OleAutDispatchImpl_Invoke(pDisp, dispidMember, riid, lcid, wFlags, pdispparams, pvarResult, pexcepinfo, puArgErr);
- }
-
return InternalDispatchImpl_Invoke(pDisp, dispidMember, riid, lcid, wFlags, pdispparams, pvarResult, pexcepinfo, puArgErr);
}
-
-//------------------------------------------------------------------------------------------
-// IDispatch methods for COM+ objects implemented internally using reflection.
-
-
-HRESULT __stdcall
-OleAutDispatchImpl_GetIDsOfNames
-(
- IDispatch* pDisp,
- REFIID riid,
- _In_reads_(cNames) OLECHAR **rgszNames,
- unsigned int cNames,
- LCID lcid,
- DISPID *rgdispid
-)
-{
- CONTRACTL
- {
- NOTHROW;
- GC_TRIGGERS;
- MODE_PREEMPTIVE;
- INJECT_FAULT(return E_OUTOFMEMORY);
- PRECONDITION(CheckPointer(pDisp));
- PRECONDITION(IsInProcCCWTearOff(pDisp));
- PRECONDITION(CheckPointer(rgszNames));
- }
- CONTRACTL_END;
-
- // Make sure that riid is IID_NULL.
- if (riid != IID_NULL)
- return DISP_E_UNKNOWNINTERFACE;
-
- // Retrieve the COM method table from the IP.
- ComMethodTable *pCMT = ComMethodTable::ComMethodTableFromIP(pDisp);
- if (pCMT->IsIClassXOrBasicItf() && pCMT->GetClassInterfaceType() != clsIfNone)
- if (pCMT->HasInvisibleParent())
- return E_NOTIMPL;
-
- ITypeInfo *pTI;
- HRESULT hr = GetITypeInfoForMT(pCMT, &pTI);
- if (FAILED(hr))
- return (hr);
-
- hr = pTI->GetIDsOfNames(rgszNames, cNames, rgdispid);
- return hr;
-}
-
-HRESULT __stdcall
-OleAutDispatchImpl_Invoke
- (
- IDispatch* pDisp,
- DISPID dispidMember,
- REFIID riid,
- LCID lcid,
- unsigned short wFlags,
- DISPPARAMS *pdispparams,
- VARIANT *pvarResult,
- EXCEPINFO *pexcepinfo,
- unsigned int *puArgErr
- )
-{
- CONTRACTL
- {
- NOTHROW;
- GC_TRIGGERS;
- MODE_PREEMPTIVE;
- PRECONDITION(CheckPointer(pDisp));
- PRECONDITION(IsInProcCCWTearOff(pDisp));
- }
- CONTRACTL_END;
-
- HRESULT hr = S_OK;
-
- // Make sure that riid is IID_NULL.
- if (riid != IID_NULL)
- return DISP_E_UNKNOWNINTERFACE;
-
- // Retrieve the COM method table from the IP.
- ComMethodTable *pCMT = ComMethodTable::ComMethodTableFromIP(pDisp);
- if (pCMT->IsIClassXOrBasicItf() && pCMT->GetClassInterfaceType() != clsIfNone)
- if (pCMT->HasInvisibleParent())
- return E_NOTIMPL;
-
- ITypeInfo *pTI;
- hr = GetITypeInfoForMT(pCMT, &pTI);
- if (FAILED(hr))
- return hr;
-
- EX_TRY
- {
- // If we have a basic or IClassX interface then we're going to invoke through
- // the class interface.
- if (pCMT->IsIClassXOrBasicItf())
- {
- CCWHolder pCCW = ComCallWrapper::GetWrapperFromIP(pDisp);
- pDisp = (IDispatch*)pCCW->GetIClassXIP();
- }
-
- hr = pTI->Invoke(pDisp, dispidMember, wFlags, pdispparams, pvarResult, pexcepinfo, puArgErr);
- }
- EX_CATCH
- {
- hr = GET_EXCEPTION()->GetHR();
- }
- EX_END_CATCH(SwallowAllExceptions);
-
- return hr;
-}
-
HRESULT __stdcall
InternalDispatchImpl_GetIDsOfNames (
IDispatch* pDisp,
EXCEPINFO *pexcepinfo,
unsigned int *puArgErr);
-
-//------------------------------------------------------------------------------------------
-// IDispatch methods for COM+ objects that use our OleAut's implementation.
-
-
-// IDispatch::GetIDsofNames
-HRESULT __stdcall OleAutDispatchImpl_GetIDsOfNames (
- IDispatch* pDisp,
- REFIID riid,
- _In_reads_(cNames) OLECHAR **rgszNames,
- unsigned int cNames,
- LCID lcid,
- DISPID *rgdispid);
-
-// IDispatch::Invoke
-HRESULT __stdcall OleAutDispatchImpl_Invoke (
- IDispatch* pDisp,
- DISPID dispidMember,
- REFIID riid,
- LCID lcid,
- unsigned short wFlags,
- DISPPARAMS *pdispparams,
- VARIANT *pvarResult,
- EXCEPINFO *pexcepinfo,
- unsigned int *puArgErr);
-
-
-
//------------------------------------------------------------------------------------------
// IDispatch methods for COM+ objects that use our internal implementation.
DefaultDllImportSearchPaths,
Guid,
LCIDConversion,
- IDispatchImpl,
ImportedFromTypeLib,
Intrinsic,
IsByRefLike,
return "System.Runtime.InteropServices.GuidAttribute";
case WellKnownAttribute::LCIDConversion:
return "System.Runtime.InteropServices.LCIDConversionAttribute";
- case WellKnownAttribute::IDispatchImpl:
- return "System.Runtime.InteropServices.IDispatchImplAttribute";
case WellKnownAttribute::ImportedFromTypeLib:
return "System.Runtime.InteropServices.ImportedFromTypeLibAttribute";
case WellKnownAttribute::Intrinsic:
[assembly: ComVisible(true)] // not embed
[assembly: TypeLibVersion(1, 0)] // not embed
// [assembly: SetWin32ContextInIDispatch()]
-// [assembly: IDispatchImpl(IDispatchImplType.CompatibleImpl)] // not embed
namespace MockInterop01
{
TypesMustExist : Type 'System.Runtime.InteropServices.AssemblyRegistrationFlags' does not exist in the reference but it does exist in the implementation.
CannotChangeAttribute : Attribute 'System.Runtime.Versioning.UnsupportedOSPlatformAttribute' on 'System.Runtime.InteropServices.ComWrappers' changed from '[UnsupportedOSPlatformAttribute("android")]' in the implementation to '[UnsupportedOSPlatformAttribute("android")]' in the reference.
TypesMustExist : Type 'System.Runtime.InteropServices.ExporterEventKind' does not exist in the reference but it does exist in the implementation.
-TypesMustExist : Type 'System.Runtime.InteropServices.IDispatchImplAttribute' does not exist in the reference but it does exist in the implementation.
-TypesMustExist : Type 'System.Runtime.InteropServices.IDispatchImplType' does not exist in the reference but it does exist in the implementation.
TypesMustExist : Type 'System.Runtime.InteropServices.RegistrationClassContext' does not exist in the reference but it does exist in the implementation.
TypesMustExist : Type 'System.Runtime.InteropServices.RegistrationConnectionType' does not exist in the reference but it does exist in the implementation.
TypesMustExist : Type 'System.Runtime.InteropServices.SetWin32ContextInIDispatchAttribute' does not exist in the reference but it does exist in the implementation.
<Compile Include="System\Runtime\InteropServices\ComUnregisterFunctionAttribute.cs" />
<Compile Include="System\Runtime\InteropServices\ExporterEventKind.cs" />
<Compile Include="System\Runtime\InteropServices\HandleCollector.cs" />
- <Compile Include="System\Runtime\InteropServices\IDispatchImplAttribute.cs" />
- <Compile Include="System\Runtime\InteropServices\IDispatchImplType.cs" />
<Compile Include="System\Runtime\InteropServices\ImportedFromTypeLibAttribute.cs" />
<Compile Include="System\Runtime\InteropServices\ManagedToNativeComInteropStubAttribute.cs" />
<Compile Include="System\Runtime\InteropServices\PrimaryInteropAssemblyAttribute.cs" />
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-namespace System.Runtime.InteropServices
-{
- [AttributeUsage(AttributeTargets.Class | AttributeTargets.Assembly, Inherited = false)]
- [Obsolete("IDispatchImplAttribute has been deprecated and is not supported.")]
- public sealed class IDispatchImplAttribute : Attribute
- {
- public IDispatchImplAttribute(short implType) : this((IDispatchImplType)implType)
- {
- }
-
- public IDispatchImplAttribute(IDispatchImplType implType) => Value = implType;
-
- public IDispatchImplType Value { get; }
- }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-namespace System.Runtime.InteropServices
-{
- [Obsolete("IDispatchImplAttribute and IDispatchImplType have been deprecated and are not supported.")]
- public enum IDispatchImplType
- {
- CompatibleImpl = 2,
- InternalImpl = 1,
- SystemDefinedImpl = 0,
- }
-}
<Compile Include="System\Runtime\InteropServices\GuidAttributeTests.cs" />
<Compile Include="System\Runtime\InteropServices\HandleCollectorTests.cs" />
<Compile Include="System\Runtime\InteropServices\HandleRefTests.cs" />
- <Compile Include="System\Runtime\InteropServices\IDispatchImplAttributeTests.cs" />
<Compile Include="System\Runtime\InteropServices\InterfaceTypeAttributeTests.cs" />
<Compile Include="System\Runtime\InteropServices\LCIDConversionAttributeTests.cs" />
<Compile Include="System\Runtime\InteropServices\LibraryImportAttributeTests.cs" />
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using System.Reflection;
-using Xunit;
-
-namespace System.Runtime.InteropServices.Tests
-{
- public class IDispatchImplAttributeTests
- {
- [Theory]
- [InlineData(-1)]
- [InlineData(0)]
- [InlineData(2)]
- public void Ctor_ImplTypeShort(short implType)
- {
- Type type = Type.GetType("System.Runtime.InteropServices.IDispatchImplAttribute, System.Runtime.InteropServices");
- PropertyInfo valueProperty = type.GetProperty("Value");
- Assert.NotNull(type);
- Assert.NotNull(valueProperty);
-
- ConstructorInfo shortConstructor = type.GetConstructor(new Type[] { typeof(short) });
- object attribute = shortConstructor.Invoke(new object[] { implType });
- Assert.Equal(implType, (int)valueProperty.GetValue(attribute));
- }
- }
-}