The explanation is already in your post: pFrame 0x00000000
Reading the documentation is always a good idea. In the text of
AfxGetMainWnd you may
had read
"If the function is called from a secondary thread in the application, the function returns the main window associated with the thread that made the call."
And your created threads have NO main window.
You must make the needed values from the primary thread as input parameters of your threading function. Windows is an operating system as iOS too) that run primary in the main thread. So it is
never a good idea to access system elements from other threads. This ALWAYS needs excellent implementation.