Oh yes. I almost forgot:
If you are going to use the DataSocket from multiple threads, you cannot just pass the pointer to the object from one thread to another. Each thread needs to have its own special COM-marshalled pointer. To accomplish this, you need to create an instance of the
IGlobalInterfaceTable object in the thread that creates the DataSocket as well as each thread that uses it. See the MSDN Library documentation for IGlobalInterfaceTable for info on how to do this.
In the thread that created the DataSocket, you register your DataSocket object in the global interface table (GIT) with
IGlobalInterfaceTable::RegisterInterfaceInGlobal. In other threads that you will be using the DataSocket object,
you retrieve a pointer to the DataSocket object using the cookie that was returned from RegisterInterfaceInGlobal and passing it to
IGlobalInterfaceTable::GetInterfaceFromGlobal. Then when all is done, free the cookie with
IGlobalInterfaceTable::RevokeInterfaceFromGlobal.
See the MSDN documentation (available on the web at
http://msdn.microsoft.com if you don't have it) for more information on all of these functions.
- Tony