Class ComWrapper<T>
Wrapper over COM interop for marshaling objects. It is used to give access to COM objects from any thread
Inheritance
ComWrapper<T>
Assembly: CAMAPI.DotnetHelper.dll
Syntax
public class ComWrapper<T> : IDisposable
Type Parameters
| Name |
Description |
| T |
Any COM object
|
Constructors
ComWrapper(nint)
Create wrapper for COM object
Declaration
public ComWrapper(nint objPointer)
Parameters
| Type |
Name |
Description |
| nint |
objPointer |
Pointer to COM object
|
ComWrapper(T?)
Create wrapper for COM object
Declaration
public ComWrapper(T? comObject)
Parameters
| Type |
Name |
Description |
| T |
comObject |
Object that implements COM interface
|
Properties
Instance
Copy of COM-object, which is accessible from any thread. It is thread-safe, but
requires additional resources to store objects for each thread
Declaration
public T? Instance { get; }
Property Value
IsNull
Wrapped COM-object is null
Declaration
public bool IsNull { get; }
Property Value
It
Instance but with additional null reference check.
Declaration
Property Value
Methods
AsInstanceOf<TTarget>()
Checks whether the wrapped COM object implements the specified interface,
and if so, returns a wrapper for that interface.
Declaration
public ComWrapper<TTarget>? AsInstanceOf<TTarget>() where TTarget : class
Returns
Type Parameters
Dispose()
Declaration
Equals(object?)
Compares two wrappers by reference
Declaration
public override bool Equals(object? obj)
Parameters
| Type |
Name |
Description |
| object |
obj |
|
Returns
Overrides
Invoke(Action<T>)
Code to executed with current COM-object. Code will be executed in sub thread with
MTA apartment state - this will work for all COM-objects, but it should be
created also from thread with MTA apartment state
Declaration
public void Invoke(Action<T> action)
Parameters
| Type |
Name |
Description |
| Action<T> |
action |
|
Invoke(Func<T, TResultStatus>)
Code to executed with current COM-object. Code will be executed in sub thread with
MTA apartment state - this will work for all COM-objects, but it should be
created also from thread with MTA apartment state
Declaration
public void Invoke(Func<T, TResultStatus> actionWithStatus)
Parameters
InvokeAndWrap<TResult>(Func<T, (TResult ComObject, TResultStatus Status)>)
Code to executed with current COM-object. Code will be executed in sub thread with
MTA apartment state - this will work for all COM-objects, but it should be
created also from thread with MTA apartment state.
Controls if the result of action is successful or not to throw it. Create COM wrapper
for a result of action
Declaration
public ComWrapper<TResult> InvokeAndWrap<TResult>(Func<T, (TResult ComObject, TResultStatus Status)> func) where TResult : class
Parameters
Returns
Type Parameters
InvokeAndWrap<TResult>(Func<T, TResult?>)
Code to executed with current COM-object. Code will be executed in sub thread with
MTA apartment state - this will work for all COM-objects, but it should be
created also from thread with MTA apartment state.
Create COM wrapper for the result of action
Declaration
public ComWrapper<TResult> InvokeAndWrap<TResult>(Func<T, TResult?> func) where TResult : class
Parameters
| Type |
Name |
Description |
| Func<T, TResult> |
func |
|
Returns
Type Parameters
Invoke<TReturn>(Func<T, (TReturn Result, TResultStatus Status)>)
Code to executed with current COM-object. Code will be executed in sub thread with
MTA apartment state - this will work for all COM-objects, but it should be
created also from thread with MTA apartment state.
Controls if the result of action is successful or not to throw it
Declaration
public TReturn Invoke<TReturn>(Func<T, (TReturn Result, TResultStatus Status)> func)
Parameters
Returns
Type Parameters
Invoke<T1>(Func<T, T1?>)
Code to executed with current COM-object. Code will be executed in sub thread with
MTA apartment state - this will work for all COM-objects, but it should be
created also from thread with MTA apartment state.
Special method to return the result of action
Declaration
public T1 Invoke<T1>(Func<T, T1?> func)
Parameters
| Type |
Name |
Description |
| Func<T, T1> |
func |
|
Returns
Type Parameters
TransferOwnership()
Transfers internal ownership of COM pointers and cached per-thread objects to a new ComWrapper instance.
After transfer, the current wrapper becomes empty (its pointers are set to zero and caches cleared)
and is marked as disposed so its Dispose() will not release transferred resources.
Use this to move a freshly created local wrapper (for example, created with ComWrapper.Create(...))
into a long-lived variable without leaking or double-releasing COM handles.
Declaration
public ComWrapper<T> TransferOwnership()
Returns
TransferOwnership(ComWrapper<T>)
Transfers ownership from another ComWrapper to the current one. Use this to work variables, created inside
some loops, so there lifecycle is too short
Declaration
public void TransferOwnership(ComWrapper<T> source)
Parameters
Implements