Click here to Skip to main content
16,016,770 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Customization of defaul buttons provided in PropertyPages Pin
DLChambers24-Mar-07 7:26
DLChambers24-Mar-07 7:26 
QuestionHow do i populate combo box by using RecordSet from database Pin
santoshsan24-Mar-07 0:27
santoshsan24-Mar-07 0:27 
QuestionIssue in UNICODE conversion. Pin
deb12323-Mar-07 23:23
deb12323-Mar-07 23:23 
AnswerRe: Issue in UNICODE conversion. Pin
PJ Arends24-Mar-07 6:35
professionalPJ Arends24-Mar-07 6:35 
Questionsructured storage Pin
deeps_cute23-Mar-07 23:15
deeps_cute23-Mar-07 23:15 
AnswerRe: sructured storage Pin
Christian Graus24-Mar-07 4:41
protectorChristian Graus24-Mar-07 4:41 
Questiongetting a return from a thread... Pin
darkcloud.42o23-Mar-07 23:05
darkcloud.42o23-Mar-07 23:05 
AnswerRe: getting a return from a thread... Pin
Gary R. Wheeler24-Mar-07 2:24
Gary R. Wheeler24-Mar-07 2:24 
The basic approach to this problem is to have a variable that is accessible to both the thread and your program, and then to use one of the thread synchronization primitives to 'protect' the variable from simultaneous access by the program and the thread.

Here's a crude example, using an int as the shared data and a critical section for the thread sync primitive:
static int SharedVariable = 0;
CCriticalSection SharedCS;

static UINT Thread(LPVOID parameter);

int main()
{
  AfxBeginThread(Thread,NULL);
  for (;;<nobr>) {
    // get our shared variable
    SharedCS.Lock();
    int shared_variable = SharedVariable;
    SharedCS.Unlock();
    // do something with our copy
    // ...
  }
}
UINT Thread(LPVOID parameter)
{
  // do stuff
  SharedCS.Lock();
  SharedVariable = 1;
  SharedCS.Unlock();
  // ...
  // do more stuff
  SharedCS.Lock();
  SharedVariable = 2;
  SharedCS.Unlock();
  return 0;
}
Each time either the main program or the thread function need to access the shared variable, they lock the critical section before the access, and unlock it afterward. When locked, a critical section guarantees that only one thread may 'enter' the section at a time. In my example, the main program is only reading the value, using it to monitor the progress of the thread.


Software Zen: delete this;

QuestionError in VC++ Pin
R.S Reddy23-Mar-07 21:15
R.S Reddy23-Mar-07 21:15 
AnswerRe: Error in VC++ Pin
prasad_som23-Mar-07 22:25
prasad_som23-Mar-07 22:25 
QuestionHow to change font of dialog Box inherited by CPropertyPage class ? Pin
Atul2323-Mar-07 20:24
Atul2323-Mar-07 20:24 
AnswerRe: How to change font of dialog Box inherited by CPropertyPage class ? Pin
prasad_som23-Mar-07 20:39
prasad_som23-Mar-07 20:39 
GeneralRe: How to change font of dialog Box inherited by CPropertyPage class ? Pin
Atul2323-Mar-07 21:31
Atul2323-Mar-07 21:31 
AnswerRe: How to change font of dialog Box inherited by CPropertyPage class ? Pin
prasad_som23-Mar-07 22:07
prasad_som23-Mar-07 22:07 
QuestionMessage queue Pin
rushiraj.jhala23-Mar-07 19:13
rushiraj.jhala23-Mar-07 19:13 
AnswerRe: Message queue Pin
PJ Arends23-Mar-07 19:30
professionalPJ Arends23-Mar-07 19:30 
AnswerRe: Message queue Pin
Gary R. Wheeler24-Mar-07 2:34
Gary R. Wheeler24-Mar-07 2:34 
QuestionHWND that *sent* a MSG? Pin
DLChambers23-Mar-07 14:54
DLChambers23-Mar-07 14:54 
AnswerRe: HWND that *sent* a MSG? Pin
peterchen23-Mar-07 23:22
peterchen23-Mar-07 23:22 
GeneralRe: HWND that *sent* a MSG? Pin
DLChambers24-Mar-07 6:56
DLChambers24-Mar-07 6:56 
GeneralRe: HWND that *sent* a MSG? Pin
Mark Salsbery24-Mar-07 8:25
Mark Salsbery24-Mar-07 8:25 
QuestionReAcquire my Source code Pin
stixoffire23-Mar-07 14:16
stixoffire23-Mar-07 14:16 
AnswerRe: ReAcquire my Source code Pin
Mark Salsbery24-Mar-07 6:17
Mark Salsbery24-Mar-07 6:17 
GeneralRe: ReAcquire my Source code Pin
stixoffire25-Mar-07 21:50
stixoffire25-Mar-07 21:50 
GeneralRe: ReAcquire my Source code Pin
Mark Salsbery26-Mar-07 8:13
Mark Salsbery26-Mar-07 8:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.