Programming Tips - MFC: AfxGetThread() returning NULL (solved)

Date: 2023jan19 OS: Windows Framework: MFC Language: C/C++ Q. MFC: AfxGetThread() returning NULL (solved) A. This will occur when you're trying to do OLE in a thread that wasn't started with AfxBeginThread() So change
HANDLE h = (HANDLE) _beginthread(MyThreadMain, 0, arg);
To
CWinThread *pThread = AfxBeginThread(MyThreadMain, NULL);