Note:
- Using raw Win32 CreateTheard() API
- No MFC
- An interface is simply a pointer to a vtable
Question:
- How to pass an interface pointer to a thread?
Illustration:
IS8Simulation *pis8 = NULL; ... CoCreateInstance( clsid, NULL, CLSCTX_LOCAL_SERVER, __uuidof(IS8Simulation), (void **) &pis8); ... hThread = CreateThread( NULL, 0, SecondaryThread, //interface pointer pis8 0, &dwGenericThreadID); ... DWORD WINAPI SecondaryThread(LPVOID iValue) { //using iValue accordingly //E.g.: iValue->Open
Regards
As was stated below, passing a
COMinterface pointer between threads in not safe.Assuming you know what you are doing:
Thread safe version: