Interface Token Class
COtlInterfaceToken template class encapsulates an interface pointer for stream based marshaling to a worker thread. Just declare the thread procedure to accept COtlInterfaceToken<InterfaceType> as a parameter, and then use the parameter like a regular interface pointer in the worker thread. Any number of interface pointers can be passed to a thread procedure in this manner without explicit calls to marshaling APIs. The following code from the InterfaceToken sample is of a global function receiving an interface token as a parameter:
void fworker( LPWSTR strTitle, COtlInterfaceToken<IMarshalThis> pimt)
// use the token just like an interface pointer
short s;
HRESULT hr = pimt->Method1(34, &s);
While the token can be used any number of times in the receiving function, it is only unmarshaled once.
Because it can only be used in the context of a single function call, construct the interface token in the calling parameter list. The constructor takes an interface pointer as its only argument. You can use a smart pointer or standard interface pointer in the constructor parameter, as shown here:
CComPtr<IMarshalThis> spimt;
fworker(L"Hello", COtlInterfaceToken<IMarshalThis>(spimt) );
This code does not really do any threading, but shows how the parameters must be declared to accept an interface token object. The next section shows you how to encapsulate the entire function call with parameters in a functor object.
As an alternative to interface tokens, Objective Toolkit also includes a Global Interface Table class that you can use to marshal interface pointers: OtlGIT. For more information about OtIGIT, please see the OtlGIT online documentation.