This is more of a code architecture question. I'll try my best to explain what I'm trying to do.
I need to create a function that have access to a secondary thread, process it, and returns back to the primary thread.
Let say class B has FunctionX.
bool B::FunctionX(LPCTSTR lpszValue, CString& strResponse)
//Access the secondary thread to process lpszValue and assign strResponse;
//Returns true if process successful and false if process fail
I think you didn't really understand how threading works. You can't "call" a thread, a thread is running in parallel of your main thread and you cannot call it.
From your example, it looks like you want to do some processing, get the results of the processing when done and display that result, all of that WITHOUT freezing the UI (that's why you want a thread, right) ? Am I correct ?
If yes, then this is not the way to do it: in your Foo function, you are anyway waiting for the result of your thread (thus blocking the main thread), which means that the UI messages won't be processed anymore.
The best way to solve your problem is to start the thread (in your FunctionX for instance) and then post a user defined message containing the result to the UI. I suggest you read this very good article[^] for more information.
i m trying to sending Long SMS by AT command in PDU mode.
Here is a complete set of AT commands to send a message consisting of 2 parts:<br />
I have read through www.flounder.com Asynchronous Process Notification/Worker Thread and Arjay thread articles but I can't figure out how to get the two work together
From Asynchronous Process Notification, I understand to use Afxbeginthread to create a thread to wait for the process to end and post a message.
From Worker Thread and Arjay thread articles, I understand that I can use SuspendThread() and ResumeThread().
Press Pause wouldn't do anything. I am guessing WaitForSingleObject is preventing the thread from receiving suspend or resume(which would explain why TerminateThread and PostMessage(WM_QUIT) do not work either). So how would I go about suspending a thread that needs to waitforsingleobject on external process?
I forgot to mention that if you want to start the external process in a suspended state, you can call CreateProcess() with a special flag called CREATE_SUSPENDED, and the process will be loaded, but will not run until you resume each of its threads.
I have to look into that. With Pause and Resume I noticed how much I could have used PROCESS_INFORMATION. I could have skipped thread list traverse with SuspendThread(pi.dwThreadId),if I am not mistaken
You know while I was investigating this I have thought about switching back to CreateProcess base on what I read. Before, I had gone back and forth between CreateProcess and ShellExecuteEx (at one point I had two launch functions). But ultimately I stuck with the one that allows me to use lpOperation, open associated program automatically and open url using default application. Also I was influence by An Introduction to Processes: Asynchronous Process Notification[^], where Microsoft recommend the use of ShellExecute.
Now if there is someway for CreateProcess to use lpOperation that would be nice. OR have ShellExecuteEx populate PROCESS_INFORMATION.
I always wonder why there isn't a function that encapsulate both strengths.