Skip to content

Commit

Permalink
Remove IDispatchImplAttribute API (#76416)
Browse files Browse the repository at this point in the history
* Remove IDispatchImplAttribute API

This type has never been supported on .NET Core.
Removing all supporting code paths.
  • Loading branch information
AaronRobinsonMSFT committed Oct 1, 2022
1 parent ecf1112 commit 26a91ad
Show file tree
Hide file tree
Showing 12 changed files with 1 addition and 299 deletions.
76 changes: 0 additions & 76 deletions src/coreclr/vm/comcallablewrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,6 @@
#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
Expand Down Expand Up @@ -318,68 +310,6 @@ ComCallMethodDesc* ComMethodTable::ComCallMethodDescFromSlot(unsigned i)
RETURN pCMD;
}

//--------------------------------------------------------------------------
// 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.
Expand Down Expand Up @@ -4733,12 +4663,6 @@ ComCallWrapperTemplate* ComCallWrapperTemplate::CreateTemplate(TypeHandle thClas
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.
Expand Down
8 changes: 1 addition & 7 deletions src/coreclr/vm/comcallablewrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,12 +255,6 @@ class ComCallWrapperTemplate
return (m_flags & enum_RepresentsVariantInterface);
}

BOOL IsUseOleAutDispatchImpl()
{
LIMITED_METHOD_CONTRACT;
return (m_flags & enum_UseOleAutDispatchImpl);
}

BOOL ImplementsIMarshal()
{
LIMITED_METHOD_CONTRACT;
Expand Down Expand Up @@ -327,7 +321,7 @@ class ComCallWrapperTemplate

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

Expand Down
121 changes: 0 additions & 121 deletions src/coreclr/vm/stdinterfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1172,12 +1172,6 @@ Dispatch_GetIDsOfNames(IDispatch* pDisp, REFIID riid, _In_reads_(cNames) OLECHAR
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);
}

Expand Down Expand Up @@ -1212,124 +1206,9 @@ Dispatch_Invoke
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,
Expand Down
28 changes: 0 additions & 28 deletions src/coreclr/vm/stdinterfaces_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,34 +93,6 @@ HRESULT __stdcall Dispatch_Invoke (
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.

Expand Down
3 changes: 0 additions & 3 deletions src/coreclr/vm/wellknownattributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ enum class WellKnownAttribute : DWORD
DefaultDllImportSearchPaths,
Guid,
LCIDConversion,
IDispatchImpl,
ImportedFromTypeLib,
Intrinsic,
IsByRefLike,
Expand Down Expand Up @@ -77,8 +76,6 @@ inline const char *GetWellKnownAttributeName(WellKnownAttribute attribute)
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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
[assembly: ComVisible(true)] // not embed
[assembly: TypeLibVersion(1, 0)] // not embed
// [assembly: SetWin32ContextInIDispatch()]
// [assembly: IDispatchImpl(IDispatchImplType.CompatibleImpl)] // not embed

namespace MockInterop01
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ Compat issues with assembly System.Runtime.InteropServices:
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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
<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" />
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
<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" />
Expand Down
Loading

0 comments on commit 26a91ad

Please sign in to comment.