Click here to Skip to main content
15,900,461 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionHelp me! Pin
nhenden6700020-May-09 16:11
nhenden6700020-May-09 16:11 
AnswerRe: Help me! Pin
Hamid_RT20-May-09 19:22
Hamid_RT20-May-09 19:22 
AnswerRe: Help me! Pin
ThatsAlok20-May-09 21:38
ThatsAlok20-May-09 21:38 
Questionpointer and address? Pin
dec8220-May-09 15:45
dec8220-May-09 15:45 
AnswerRe: pointer and address? Pin
Chris Losinger20-May-09 16:33
professionalChris Losinger20-May-09 16:33 
AnswerRe: pointer and address? Pin
ThatsAlok20-May-09 21:39
ThatsAlok20-May-09 21:39 
AnswerRe: pointer and address? Pin
CPallini21-May-09 0:12
mveCPallini21-May-09 0:12 
QuestionUsing Multithreading to encrypt a file Pin
Sh_oK20-May-09 14:16
Sh_oK20-May-09 14:16 
My problem sounds like this:

I have to create a program that encrypts a file by taking each byte and increment it.
The problem is that the program should use multithreading to do the actual encrypting. The number of threads is variable, the user enters them in a Edit Control, and those “x” number of threads, simultaneously must encrypt the file.

What I’ve done so far is that I opened the file in binary mode and encrypt it by incrementing each byte in the file. So far so good, but now I can’t figure out how to create those threads and how should they encrypt the file simultaneously … a little help would be awesome.

Here is the code I done so far: when the user pushes the Ok button (the file has been selected by the user in a previous step), the selected file is encrypted

void CEncryptorView::OnBnClickedOk()
{ 
  	CString strControlText;    
	CWnd* pWnd = GetDlgItem(IDC_FILE);
	pWnd->GetWindowText(_T(strControlText));  

	char buf[255];
	
	//open the selected file for encryption
	ifstream fp_in(strControlText, ios_base::binary | ios_base::in);

	unsigned int cntr = 0; //defining a controll variable;
	if(!fp_in)
	{
		++cntr;
		MessageBox("The selected file couldn't be open for reading");
	}
	ofstream fp_out("temp.txt",	ios_base::binary | ios_base::out);
	if(!fp_out)
	{
		++cntr;
		MessageBox("\tThe temp file couldn't be created \n(check you access privileges for default destination!)");
	}

	//encrypting the file, taking each byte in the file and increment it
	if ( fp_in && fp_out )
	{
		char ch;
		while ( fp_in.get ( ch ) )
		  fp_out.put ( ++ch );
	}
	else
		++cntr;

	fp_in.close();
	fp_in.clear();
	fp_out.close();
	fp_out.clear();

	//copying (replacing) the encrypted temp file into the original file, and deleting the tempoarary one
	ifstream fs_in("temp.txt", ios_base::binary | ios_base::in);
	if(!fs_in)
	{
		++cntr;
		MessageBox("An error occured and the encryption failed");
	}
	ofstream fs_out(strControlText,	ios_base::binary | ios_base::out);
	if(!fs_out)
	{
		++cntr;
		MessageBox("An error occured and the encryption failed");
	}

	if ( fs_in && fs_out )
	{
		char ch;
		while ( fs_in.get ( ch ) )
		  fs_out.put ( ch );
	}
	else
		++cntr;

	fs_in.close();
	fs_in.clear();
	fs_out.close();
	fs_out.clear();

	//delete the temp file
	CString fileToDelete("temp.txt");
	if(remove(fileToDelete) == 0 && cntr == 0)
		MessageBox("The file has ben encrypted successfully");
	else
		MessageBox("An error occured and the encryption failed");
}


Thank you
AnswerRe: Using Multithreading to encrypt a file Pin
Chris Losinger20-May-09 15:19
professionalChris Losinger20-May-09 15:19 
GeneralRe: Using Multithreading to encrypt a file Pin
Sh_oK25-May-09 13:02
Sh_oK25-May-09 13:02 
QuestionGetting a disabled CView to give a strong visual cue of being disabled, so that the user understands that it isn't a bug that it's disabled. Pin
Sternocera20-May-09 9:58
Sternocera20-May-09 9:58 
GeneralRe: Getting a disabled CView to give a strong visual cue of being disabled, so that the user understands that it isn't a bug that it's disabled. Pin
Michael Dunn20-May-09 10:43
sitebuilderMichael Dunn20-May-09 10:43 
GeneralRe: Getting a disabled CView to give a strong visual cue of being disabled, so that the user understands that it isn't a bug that it's disabled. Pin
Sternocera20-May-09 11:32
Sternocera20-May-09 11:32 
GeneralRe: Getting a disabled CView to give a strong visual cue of being disabled, so that the user understands that it isn't a bug that it's disabled. Pin
Sternocera20-May-09 11:56
Sternocera20-May-09 11:56 
AnswerRe: Getting a disabled CView to give a strong visual cue of being disabled, so that the user understands that it isn't a bug that it's disabled. Pin
Stuart Dootson20-May-09 11:39
professionalStuart Dootson20-May-09 11:39 
GeneralRe: Getting a disabled CView to give a strong visual cue of being disabled, so that the user understands that it isn't a bug that it's disabled. Pin
Sternocera20-May-09 12:10
Sternocera20-May-09 12:10 
GeneralRe: Getting a disabled CView to give a strong visual cue of being disabled, so that the user understands that it isn't a bug that it's disabled. Pin
Stuart Dootson20-May-09 13:22
professionalStuart Dootson20-May-09 13:22 
GeneralRe: Getting a disabled CView to give a strong visual cue of being disabled, so that the user understands that it isn't a bug that it's disabled. Pin
Sternocera20-May-09 22:58
Sternocera20-May-09 22:58 
GeneralRe: Getting a disabled CView to give a strong visual cue of being disabled, so that the user understands that it isn't a bug that it's disabled. Pin
Stuart Dootson21-May-09 0:56
professionalStuart Dootson21-May-09 0:56 
GeneralRe: Getting a disabled CView to give a strong visual cue of being disabled, so that the user understands that it isn't a bug that it's disabled. Pin
Sternocera21-May-09 3:35
Sternocera21-May-09 3:35 
QuestionHow to manipulate with processes from your app? Any help is appreciated Pin
Oshtri Deka20-May-09 7:55
professionalOshtri Deka20-May-09 7:55 
AnswerRe: How to manipulate with processes from your app? Any help is appreciated Pin
Stuart Dootson20-May-09 8:16
professionalStuart Dootson20-May-09 8:16 
GeneralRe: How to manipulate with processes from your app? Any help is appreciated Pin
Oshtri Deka20-May-09 22:38
professionalOshtri Deka20-May-09 22:38 
AnswerRe: How to manipulate with processes from your app? Any help is appreciated Pin
ThatsAlok20-May-09 21:42
ThatsAlok20-May-09 21:42 
GeneralRe: How to manipulate with processes from your app? Any help is appreciated Pin
Oshtri Deka20-May-09 22:41
professionalOshtri Deka20-May-09 22:41 

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.