Click here to Skip to main content
15,887,214 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: How do you get type from format? Pin
Richard MacCutchan26-Sep-16 5:18
mveRichard MacCutchan26-Sep-16 5:18 
GeneralRe: How do you get type from format? Pin
Vaclav_26-Sep-16 6:12
Vaclav_26-Sep-16 6:12 
GeneralRe: How do you get type from format? Pin
Richard MacCutchan26-Sep-16 6:15
mveRichard MacCutchan26-Sep-16 6:15 
GeneralRe: How do you get type from format? Pin
leon de boer27-Sep-16 2:24
leon de boer27-Sep-16 2:24 
GeneralRe: How do you get type from format? Pin
Vaclav_2-Oct-16 5:30
Vaclav_2-Oct-16 5:30 
Questionhow to create thread on windows? Pin
Member 1118935723-Sep-16 19:49
Member 1118935723-Sep-16 19:49 
AnswerRe: how to create thread on windows? Pin
Richard MacCutchan23-Sep-16 22:46
mveRichard MacCutchan23-Sep-16 22:46 
AnswerHere's how! Pin
Software_Developer24-Sep-16 0:49
Software_Developer24-Sep-16 0:49 
Try this:


C++
#include "stdafx.h"

#define _MT
#include <windows.h>
#include <process.h>    /* _beginthread, _endthread */
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>

#pragma comment(lib, "user32.lib")
#pragma comment(lib, "libcmt.lib")
#pragma comment(linker, "/NODEFAULTLIB:libcd.lib")



void ThreadFunction1(void *ch);
void ThreadFunction2(void *dummy);



BOOL repeat = TRUE;     /* Global repeat flag  */

int main(){
	printf("\nMultithreading with two threads.\n\n");
	printf("Thread Function 2  listens for key strokes. \n");
	printf("Thread Function 1  does all the other work \n");
	printf("  \n");
	CHAR    ch = 'A';


	/* Launch ThreadFunction2 thread to check for terminating keystroke. */
	_beginthread(ThreadFunction2, 0, NULL);

	/* Loop until ThreadFunction2 terminates program. */
	while (repeat){
		/* On first loops, launch character threads. */
		_beginthread(ThreadFunction1, 0, (void *)(ch++));

		/* Wait one second between loops. */
		Sleep(1000L);
	}

	printf("  \n");
	return 0;
}

/* ThreadFunction2 - Thread to wait for a keystroke, then end program. */
void ThreadFunction2(void *dummy){
	_getch();
	repeat = 0;    /* _endthread implied */

}


/* ThreadFunction2 - Thread to do work */
void ThreadFunction1(void *ch){

	while (repeat){

		/* Pause between loops. */
		Sleep(100L);

	}
	/* _endthread given to terminate */
	_endthread();
}

GeneralRe: Here's how! Pin
Member 1118935724-Sep-16 1:16
Member 1118935724-Sep-16 1:16 
GeneralRe: Here's how! Pin
Richard MacCutchan24-Sep-16 3:46
mveRichard MacCutchan24-Sep-16 3:46 
GeneralRe: Here's how! Pin
Member 1118935724-Sep-16 3:55
Member 1118935724-Sep-16 3:55 
GeneralRe: Here's how! Pin
Richard MacCutchan24-Sep-16 4:05
mveRichard MacCutchan24-Sep-16 4:05 
GeneralRe: Here's how! Pin
Member 1118935724-Sep-16 4:19
Member 1118935724-Sep-16 4:19 
GeneralRe: Here's how! Pin
leon de boer24-Sep-16 7:37
leon de boer24-Sep-16 7:37 
GeneralRe: Here's how! Pin
Member 1118935724-Sep-16 10:52
Member 1118935724-Sep-16 10:52 
GeneralRe: Here's how! Pin
leon de boer24-Sep-16 16:43
leon de boer24-Sep-16 16:43 
GeneralRe: Here's how! Pin
Member 1118935724-Sep-16 19:55
Member 1118935724-Sep-16 19:55 
GeneralRe: Here's how! Pin
Richard MacCutchan24-Sep-16 20:36
mveRichard MacCutchan24-Sep-16 20:36 
QuestionRe: Here's how! Pin
David Crow25-Sep-16 17:10
David Crow25-Sep-16 17:10 
GeneralRe: Here's how! Pin
Joe Woodbury24-Oct-16 14:40
professionalJoe Woodbury24-Oct-16 14:40 
Questionwhy "Invalid Gender!"? Pin
Ambus Dondon22-Sep-16 17:56
Ambus Dondon22-Sep-16 17:56 
AnswerRe: why "Invalid Gender!"? Pin
Richard MacCutchan22-Sep-16 20:41
mveRichard MacCutchan22-Sep-16 20:41 
AnswerRe: why "Invalid Gender!"? Pin
Jochen Arndt22-Sep-16 20:47
professionalJochen Arndt22-Sep-16 20:47 
GeneralRe: why "Invalid Gender!"? Pin
Ambus Dondon23-Sep-16 16:15
Ambus Dondon23-Sep-16 16:15 
AnswerRe: why "Invalid Gender!"? Pin
Victor Nijegorodov23-Sep-16 7:46
Victor Nijegorodov23-Sep-16 7:46 

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.