Class ComDispatch
- Namespace
- CsCom.Runtime
- Assembly
- CsCom.Runtime.dll
Resolves and invokes the members of IDispatch interfaces by name and dispatch identifier, and reads their type
information: the late binding that the generated dispinterface wrappers and dynamic objects build on.
public static class ComDispatch
- Inheritance
-
ComDispatch
- Inherited Members
Methods
CreateInvocationException(int, int, string?, DispatchFlags, int, int)
Creates the exception of a failed invocation, as Invoke(IDispatch, int, DispatchFlags, ReadOnlySpan<object?>, ReadOnlySpan<int>, Span<object?>, ReadOnlySpan<DispatchArgumentKind>, string?) throws it: a COMException that names
the member and the argument for the common errors of IDispatch::Invoke, otherwise the exception of the HRESULT.
public static Exception CreateInvocationException(int hr, int dispId, string? memberName, DispatchFlags flags, int argumentCount, int argumentError)
Parameters
hrintThe
HRESULTreturned by TryInvoke(IDispatch, int, DispatchFlags, ReadOnlySpan<object?>, ReadOnlySpan<int>, Span<object?>, ReadOnlySpan<DispatchArgumentKind>, out object?, out int).dispIdintThe dispatch identifier of the member.
memberNamestringThe name of the member, if known.
flagsDispatchFlagsThe kind of the invocation.
argumentCountintThe number of arguments.
argumentErrorintThe index of the argument that caused the error, or -1.
Returns
GetDispIds(IDispatch, ReadOnlySpan<string>, Span<int>)
Maps a member name and, optionally, the names of its parameters to dispatch identifiers (IDispatch::GetIDsOfNames).
public static int GetDispIds(IDispatch dispatch, ReadOnlySpan<string> names, Span<int> ids)
Parameters
dispatchIDispatchThe interface.
namesReadOnlySpan<string>The name of the member, followed by the names of parameters.
idsSpan<int>Receives the dispatch identifiers; Unknown for the unknown names.
Returns
- int
The
HRESULT;DISP_E_UNKNOWNNAMEwhen one of the names is unknown.
GetEventInterfaces(IDispatch)
Gets the source dispinterfaces of the coclass of an object, the default one first: the coclass is given by
IProvideClassInfo, or is the first coclass of the type library whose default interface is the interface of
IDispatch::GetTypeInfo. Dual and vtable source interfaces are not included.
public static IReadOnlyList<EventInterface> GetEventInterfaces(IDispatch dispatch)
Parameters
dispatchIDispatch
Returns
GetMemberKinds(IDispatch, int)
Gets how the type information of an object describes a member: as a method, as a property that can be read, and whether the getter of the property takes arguments. Late-bound callers that read a member can then return something to call or to index rather than invoke it.
public static DispatchMemberKinds GetMemberKinds(IDispatch dispatch, int dispId)
Parameters
Returns
- DispatchMemberKinds
The kinds, or None for an unknown member and if the object provides no type information.
GetMemberName(IDispatch, int)
Gets the name of a member of an object from its type information, e.g. the name of the default member (Value), which GetDispIds(IDispatch, ReadOnlySpan<string>, Span<int>) needs to resolve the names of its parameters.
public static string? GetMemberName(IDispatch dispatch, int dispId)
Parameters
Returns
GetPropertyNames(IDispatch)
Gets the names of the properties of an object that can be read without arguments, including those of the base interfaces, except for restricted and hidden ones.
public static IReadOnlyList<string> GetPropertyNames(IDispatch dispatch)
Parameters
dispatchIDispatch
Returns
- IReadOnlyList<string>
The names, or none if the object provides no type information.
GetTypeName(IDispatch)
Gets the name of the type of an object from its type information (IDispatch::GetTypeInfo), like VB's
TypeName, e.g. the name of the default interface of its class.
public static string? GetTypeName(IDispatch dispatch)
Parameters
dispatchIDispatch
Returns
Invoke(IDispatch, int, DispatchFlags, ReadOnlySpan<object?>, ReadOnlySpan<int>, Span<object?>, ReadOnlySpan<DispatchArgumentKind>, string?)
Invokes a member and throws an exception if the invocation fails.
public static object? Invoke(IDispatch dispatch, int dispId, DispatchFlags flags, ReadOnlySpan<object?> args, ReadOnlySpan<int> namedDispIds = default, Span<object?> output = default, ReadOnlySpan<DispatchArgumentKind> byRef = default, string? memberName = null)
Parameters
dispatchIDispatchThe interface to invoke the member on.
dispIdintThe dispatch identifier of the member.
flagsDispatchFlagsThe kind of the invocation.
argsReadOnlySpan<object>The arguments, in the declaration order; the named arguments follow the positional ones.
namedDispIdsReadOnlySpan<int>The dispatch identifiers of the trailing named arguments. A property put without named arguments passes its last argument, the value, as PropertyPut; with named arguments, the value must be the first of them, with PropertyPut as its identifier.
outputSpan<object>Receives the new values of the by-reference arguments; usually the same span as
args. It must have an element for each argument whenbyRefis not empty.byRefReadOnlySpan<DispatchArgumentKind>For each argument, how it is passed. Empty when all of them are passed by value.
memberNamestringThe name of the member for error messages, if known.
Returns
- object
The result of the invocation.
Exceptions
- COMException
The invocation failed or the COM object raised an exception.
TryInvoke(IDispatch, int, DispatchFlags, ReadOnlySpan<object?>, ReadOnlySpan<int>, Span<object?>, ReadOnlySpan<DispatchArgumentKind>, out object?, out int)
Invokes a member and returns the HRESULT. Exceptions raised by the COM object (DISP_E_EXCEPTION) are still thrown.
public static int TryInvoke(IDispatch dispatch, int dispId, DispatchFlags flags, ReadOnlySpan<object?> args, ReadOnlySpan<int> namedDispIds, Span<object?> output, ReadOnlySpan<DispatchArgumentKind> byRef, out object? result, out int argumentError)
Parameters
dispatchIDispatchThe interface to invoke the member on.
dispIdintThe dispatch identifier of the member.
flagsDispatchFlagsThe kind of the invocation.
argsReadOnlySpan<object>The arguments, in the declaration order; the named arguments follow the positional ones.
namedDispIdsReadOnlySpan<int>The dispatch identifiers of the trailing named arguments.
outputSpan<object>Receives the new values of the by-reference arguments; usually the same span as
args.byRefReadOnlySpan<DispatchArgumentKind>For each argument, how it is passed. Empty when all of them are passed by value.
resultobjectThe result of the invocation.
argumentErrorintThe index in
argsof the argument that caused aDISP_E_TYPEMISMATCHorDISP_E_PARAMNOTFOUNDerror, or -1.
Returns
- int
The
HRESULTreturned byIDispatch::Invoke.
Exceptions
- COMException
The COM object raised an exception.