Click here to Skip to main content
16,011,680 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: couldn't install vc++ 2008? Pin
led mike12-Jun-08 6:48
led mike12-Jun-08 6:48 
QuestionHow to search and delete a file Pin
Shirani12-Jun-08 1:18
Shirani12-Jun-08 1:18 
AnswerRe: How to search and delete a file Pin
_AnsHUMAN_ 12-Jun-08 1:44
_AnsHUMAN_ 12-Jun-08 1:44 
AnswerRe: How to search and delete a file Pin
vijay_aroli12-Jun-08 2:36
vijay_aroli12-Jun-08 2:36 
GeneralRe: How to search and delete a file Pin
Shirani12-Jun-08 6:39
Shirani12-Jun-08 6:39 
GeneralRe: How to search and delete a file Pin
Eytukan12-Jun-08 7:52
Eytukan12-Jun-08 7:52 
QuestionAfxCallWndProc and custom control development Pin
sawerr12-Jun-08 1:11
sawerr12-Jun-08 1:11 
QuestionHow can I get byte pointers to give CString values ? Pin
SherTeks12-Jun-08 0:56
SherTeks12-Jun-08 0:56 
I have this code snippet which writes an encrypted value of a string into a file
(KEY_FILE -- #defined as C:\xyz.txt) ;

BYTE *pbBlob;
DWORD cbBlob;


	:
	:
	:



if (!CryptExportKey(hSessionKey, hKey, SIMPLEBLOB, 0, NULL, &cbBlob))
{
	dwResult = GetLastError();
	MessageBox("Error CryptExportKey() failed.", "Information", MB_OK);
	return;
}
if (!CryptExportKey(hSessionKey, hKey, SIMPLEBLOB, 0, NULL, &cbBlob))
{
	dwResult = GetLastError();
	MessageBox("Error CryptExportKey() failed.", "Information", MB_OK);
	return;
}
if ((pbBlob = (BYTE *) LocalAlloc(LMEM_ZEROINIT,cbBlob)) == NULL)
{
	dwResult = ERROR_NOT_ENOUGH_MEMORY;
	MessageBox("Error LocalAlloc() failed.", "Information", MB_OK);
	return;
}
if (!CryptExportKey(hSessionKey, hKey, SIMPLEBLOB, 0, pbBlob, &cbBlob))
{
	dwResult = GetLastError();
	MessageBox("Error CryptExportKey() failed.", "Information", MB_OK);
	return;
}

if(hSessionKey != 0) 
CryptDestroyKey(hSessionKey);

hSessionKey = 0;


FILE *fp = fopen(KEY_FILE, "w+b");
if (fp) {
	fwrite(pbBlob, 1, cbBlob, fp);
	fclose(fp);
}



I find a junk value written by the above code in "C:\xyz.txt" which is like :

 h ¤ zÛ³Wp <ø®lŒoWP¸"Ç^1i M€ÌygUjŽæ#Eì}ÔKËëü’²ô â  äÃr[X>¾U

Since, the file contained

 h ¤ zÛ³Wp <ø®lŒoWP¸"Ç^1i M€ÌygUjŽæ#Eì}ÔKËëü’²ô â  äÃr[X>¾U string,

I was expecting pbBlob to point to the above content ie.

 h ¤ zÛ³Wp <ø®lŒoWP¸"Ç^1i M€ÌygUjŽæ#Eì}ÔKËëü’²ô â  äÃr[X>¾U

But when I debug, the following line

fwrite(pbBlob, 1, cbBlob, fp)

shows me the value of pbBlob = "||" and cbBlob = 76

What is the problem here. How can I get the junk value in a CString ?
Will some kind of casting help ?
AnswerRe: How can I get byte pointers to give CString values ? Pin
SandipG 12-Jun-08 2:09
SandipG 12-Jun-08 2:09 
GeneralRe: How can I get byte pointers to give CString values ? Pin
RockyJames12-Jun-08 2:12
RockyJames12-Jun-08 2:12 
GeneralRe: How can I get byte pointers to give CString values ? Pin
SandipG 12-Jun-08 2:16
SandipG 12-Jun-08 2:16 
GeneralRe: How can I get byte pointers to give CString values ? Pin
RockyJames12-Jun-08 3:11
RockyJames12-Jun-08 3:11 
AnswerRe: How can I get byte pointers to give CString values ? Pin
SherTeks12-Jun-08 21:26
SherTeks12-Jun-08 21:26 
QuestionLogin& Logout Time Pin
leonigah12-Jun-08 0:53
leonigah12-Jun-08 0:53 
AnswerRe: Login& Logout Time Pin
Nibu babu thomas12-Jun-08 3:04
Nibu babu thomas12-Jun-08 3:04 
GeneralRe: Login& Logout Time Pin
leonigah12-Jun-08 20:28
leonigah12-Jun-08 20:28 
GeneralRe: Login& Logout Time Pin
leonigah12-Jun-08 20:28
leonigah12-Jun-08 20:28 
QuestionRe: Login& Logout Time Pin
Nibu babu thomas12-Jun-08 20:49
Nibu babu thomas12-Jun-08 20:49 
AnswerRe: Login& Logout Time Pin
David Crow12-Jun-08 4:03
David Crow12-Jun-08 4:03 
AnswerRe: Login& Logout Time Pin
leonigah12-Jun-08 23:51
leonigah12-Jun-08 23:51 
QuestionHow can get value of keyboard pressed key? Pin
Le@rner11-Jun-08 23:59
Le@rner11-Jun-08 23:59 
AnswerRe: How can get value of keyboard pressed key? Pin
CPallini12-Jun-08 0:24
mveCPallini12-Jun-08 0:24 
QuestionRe: How can get value of keyboard pressed key? Pin
Rajesh R Subramanian12-Jun-08 0:27
professionalRajesh R Subramanian12-Jun-08 0:27 
AnswerRe: How can get value of keyboard pressed key? Pin
Le@rner12-Jun-08 0:40
Le@rner12-Jun-08 0:40 
AnswerRe: How can get value of keyboard pressed key? Pin
Rajesh R Subramanian12-Jun-08 0:33
professionalRajesh R Subramanian12-Jun-08 0:33 

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.