strange question
-
I have a dll with a dialog box that gets run when the function is called. This uses MFC. I want to spawn a new thread that the dialog box runs in. Here's the exported function: extern "C" __declspec(dllexport) void XducerSpecDialog(int px, int patxrx, int cred, int tfmid, void (*TimerCallBack)(), int (*callbackFunc)(int tfmid)) I thought I could just use _beginthread, but I'm not quite sure what to do becuase I'm using MFC and I have an instance of the class object that I use to call: theApp.RunDialog Can I just call the _beginthread(theApp.RunDialog,0,my_arguements)??? Thanks!
-
I have a dll with a dialog box that gets run when the function is called. This uses MFC. I want to spawn a new thread that the dialog box runs in. Here's the exported function: extern "C" __declspec(dllexport) void XducerSpecDialog(int px, int patxrx, int cred, int tfmid, void (*TimerCallBack)(), int (*callbackFunc)(int tfmid)) I thought I could just use _beginthread, but I'm not quite sure what to do becuase I'm using MFC and I have an instance of the class object that I use to call: theApp.RunDialog Can I just call the _beginthread(theApp.RunDialog,0,my_arguements)??? Thanks!
I think you need to use the MFC thread functions within MFC, AfxBeginThread(). Unless theApp.RunDialog has a function signature of a worker thread, you might want to take a different approach. Define a worker thread with a signature like UINT MyControllingFunction( LPVOID pParam ); and use that as the first parameter to AfxBeginThread. Pass theApp as a second parameter and from inside your worker thread, call RunDialog. Here's a sample from MSDN using a CMyObject instead of theApp... UINT MyThreadProc( LPVOID pParam ) { CMyObject* pObject = (CMyObject*)pParam; if (pObject == NULL || !pObject->IsKindOf(RUNTIME_CLASS(CMyObject))) return 1; // if pObject is not valid // do something with 'pObject' return 0; // thread completed successfully } // inside a different function in the program . . . pNewObject = new CMyObject; AfxBeginThread(MyThreadProc, pNewObject); . . .