I have a working single-threaded MFC app and am now trying to convert the worker portion to a thread. I am having some trouble with understanding some of the automatically-supplied Visual Studio C++ code. My basic problem is that the thread has to be static code, while the dialog has to be dynamic and there are variables that are global to both. Here are the minimal pieces that seem to be the cause of either undefined references or function must be non-static. I have spent several hours trying to find online references, but have not had success. How can I gain access to m_strTree_IN in both my functions (The errors are noted in my code here):
// M_exifierDlg.cpp
#include "pch.h"
#include "framework.h"
#include "M_exifier.h"
#include "M_exifierDlg.h"
#include "afxdialogex.h"
CMexifierDlg::CMexifierDlg(CWnd* pParent /*=nullptr*/)
: CDialogEx(IDD_M_EXIFIER_DIALOG, pParent)
**// I can’t find any guidance to the following syntax (commas after the right paren above)**
, m_strTree_IN("") // variable attached to dialog textbox
, m_strTree_OUT("") // ditto
, m_inst_text("") // ditto
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CMexifierDlg::OnClickedCheck1()
{
AfxBeginThread(MyThreadControllingFunction, 0);
}
unsigned int static MyThreadControllingFunction(LPVOID pParam)
{
doit();
return 0; // thread completed successfully
}
Void doit()
{
CString X=m_strTree_IN **//<< ERROR identifier m_strTree_IN is undefined**
// UpDateData(); **//<< ERROR calls with TRUE and FALSE are undefined**
// but see below
}
// In m_exifier.h
Class cMexifierDlg : public CDialogEx
{.
public:
static void CMexifierDlg::doit();
CString m_strTree_IN; // INPUT from dialog textbox
};