Click here to Skip to main content
16,010,351 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Questionhow to change the back ground color of Label at runtime Pin
ramnathrn17-Jun-08 8:16
ramnathrn17-Jun-08 8:16 
QuestionRe: how to change the back ground color of Label at runtime Pin
David Crow17-Jun-08 8:51
David Crow17-Jun-08 8:51 
QuestionC program Pin
Subhankar17-Jun-08 7:40
Subhankar17-Jun-08 7:40 
AnswerRe: C program Pin
Alan Balkany17-Jun-08 8:26
Alan Balkany17-Jun-08 8:26 
QuestionRe: C program Pin
David Crow17-Jun-08 8:52
David Crow17-Jun-08 8:52 
AnswerRe: C program Pin
bulg17-Jun-08 13:44
bulg17-Jun-08 13:44 
GeneralRe: C program Pin
Subhankar17-Jun-08 23:11
Subhankar17-Jun-08 23:11 
QuestionMIME Base64 Encoding Pin
hxhl9517-Jun-08 6:03
hxhl9517-Jun-08 6:03 
Hi all,

So, I have an MFC app to encode files in base64 to be sent through email. Here's the code I'm using now :

filename=filename.Right(filename.GetLength()-filename.ReverseFind('\\')-1);
inputfile.Read(filedata.GetBuffer(0),inputfile.GetLength());
filedata.SetAt(inputfile.GetLength(),'\0');

emailbody+="--0000000002230291k492__V\r\nContent-type: "+fileExt+"\r\n";
emailbody+="Content-Transfer-Encoding: base64\r\nContent-Disposition: attachment; ";
emailbody+="filename=\""+filename+"\"\r\n\r\n";
emailbody+=base64_encode(filedata.GetBuffer(0)).c_str();
emailbody+="\r\n\r\n";
inputfile.Close();


I've got no clue of why this code doesn't work properly. It works fine for .txt files and other files that only contain alphanumeric chars, ONLY WHEN the files are smaller than around 5kb. Other files do not work at all, regardless of the size.

here's the base64 encode function I'm using:

inline std::string base64_encode(const std::string &sString) {
	static const std::string sBase64Table(
		// 0000000000111111111122222222223333333333444444444455555555556666
		// 0123456789012345678901234567890123456789012345678901234567890123
		  "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
		);
	static const char cFillChar = '=';
	std::string::size_type   nLength = sString.length();
	std::string              sResult;
	
	// Allocate memory for the converted string
	sResult.reserve(nLength * 8 / 6 + 1);
	
	for(std::string::size_type nPos = 0; nPos < nLength; nPos++) {
		char cCode;
		
		// Encode the first 6 bits
		cCode = (sString[nPos] >> 2) & 0x3f;
		sResult.append(1, sBase64Table[cCode]);
		
		// Encode the remaining 2 bits with the next 4 bits (if present)
		cCode = (sString[nPos] << 4) & 0x3f;
		if(++nPos < nLength)
			cCode |= (sString[nPos] >> 4) & 0x0f;
		sResult.append(1, sBase64Table[cCode]);
		
		if(nPos < nLength) {
			cCode = (sString[nPos] << 2) & 0x3f;
			if(++nPos < nLength)
				cCode |= (sString[nPos] >> 6) & 0x03;
			
			sResult.append(1, sBase64Table[cCode]);
		} else {
			++nPos;
			sResult.append(1, cFillChar);
		}
		
		if(nPos < nLength) {
			cCode = sString[nPos] & 0x3f;
			sResult.append(1, sBase64Table[cCode]);
		} else {
			sResult.append(1, cFillChar);
		}
	}
	return sResult;
}


This function seems to be encoding correctly, while other ones I've found or created don't encode right.

Does anyone have any advice for me? I'm about to give up on this function.
AnswerRe: MIME Base64 Encoding Pin
Michael Dunn17-Jun-08 15:30
sitebuilderMichael Dunn17-Jun-08 15:30 
QuestionHow do I change the shadow color in ShadowVolume Pin
akira3217-Jun-08 5:38
akira3217-Jun-08 5:38 
QuestionHow to serialize STL containers in VC++ 2008? [modified] Pin
followait17-Jun-08 4:10
followait17-Jun-08 4:10 
AnswerRe: How to serialize STL containers in VC++ 2008? Pin
CPallini17-Jun-08 4:31
mveCPallini17-Jun-08 4:31 
QuestionHow can i hide Static Text in MFC ? Pin
sumit.durg17-Jun-08 4:03
sumit.durg17-Jun-08 4:03 
AnswerRe: How can i hide Static Text in MFC ? Pin
toxcct17-Jun-08 4:10
toxcct17-Jun-08 4:10 
AnswerRe: How can i hide Static Text in MFC ? Pin
Jijo.Raj17-Jun-08 8:00
Jijo.Raj17-Jun-08 8:00 
GeneralRe: How can i hide Static Text in MFC ? Pin
ramnathrn17-Jun-08 8:13
ramnathrn17-Jun-08 8:13 
Question[OT] Re: How can i hide Static Text in MFC ? Pin
David Crow17-Jun-08 8:48
David Crow17-Jun-08 8:48 
GeneralRe: How can i hide Static Text in MFC ? Pin
Jijo.Raj17-Jun-08 8:58
Jijo.Raj17-Jun-08 8:58 
QuestionVISTA - CreateFile function returns not good handle. Pin
kkumarpatel17-Jun-08 3:56
kkumarpatel17-Jun-08 3:56 
AnswerRe: VISTA - CreateFile function returns not good handle. Pin
David Crow17-Jun-08 3:59
David Crow17-Jun-08 3:59 
AnswerRe: VISTA - CreateFile function returns not good handle. Pin
Hamid_RT17-Jun-08 7:36
Hamid_RT17-Jun-08 7:36 
Questionerror while running Pin
Mohanraj D17-Jun-08 3:52
Mohanraj D17-Jun-08 3:52 
QuestionRe: error while running Pin
David Crow17-Jun-08 3:56
David Crow17-Jun-08 3:56 
AnswerRe: error while running Pin
Hamid_RT17-Jun-08 7:37
Hamid_RT17-Jun-08 7:37 
GeneralRe: error while running Pin
Mohanraj D17-Jun-08 17:43
Mohanraj D17-Jun-08 17:43 

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.