Beginner Question
-
Can anyone tell me how to convert a: BYTE *btArray ==> CStringArray I would really appreciate it. Thanks in advance, Dan
-
Can anyone tell me how to convert a: BYTE *btArray ==> CStringArray I would really appreciate it. Thanks in advance, Dan
Hmm. I believe you need to convert it to a CString, not to a CStringArray. CString is a string class (like the STL 'string'), while CStringArray is an array of strings (like an STL 'vector'). I guess btArray is a pointer to an array of characters (a 'C' string). To convert it to a CString, this should be enough: CString s = btArray; CStringArray can hold many CStrings, and it resizes dynamically. You can, for example: CStringArray sa; sa.Add(s); sa.Add("Hello"); After this, sa[0] is a CString and you can do: sa[0] = "SomeString"; printf("My String is: %s\n", (LPCTSTR)sa[0]); Hope this helps, Pavlos
-
Hmm. I believe you need to convert it to a CString, not to a CStringArray. CString is a string class (like the STL 'string'), while CStringArray is an array of strings (like an STL 'vector'). I guess btArray is a pointer to an array of characters (a 'C' string). To convert it to a CString, this should be enough: CString s = btArray; CStringArray can hold many CStrings, and it resizes dynamically. You can, for example: CStringArray sa; sa.Add(s); sa.Add("Hello"); After this, sa[0] is a CString and you can do: sa[0] = "SomeString"; printf("My String is: %s\n", (LPCTSTR)sa[0]); Hope this helps, Pavlos
Doesn't work...I get: const CString& CString::operator=(LPCTSTR lpsz) { ASSERT(lpsz == NULL || AfxIsValidString(lpsz)); <=========== Error is here! AssignCopy(SafeStrlen(lpsz), lpsz); return *this; } HERE is an example of the code: //BYTE btArr[3] = {67,245,67}; <========= I can see this! BYTE *btArr = lpVal[3].Value.bin.lpb; CString s = _T(""); s = btArr; <=========================== Error! s = lpVal[3].Value.bin.lpb[0]; <======== Error! MessageBox(0,s,"",0); Thanks in advance, Dan
-
Doesn't work...I get: const CString& CString::operator=(LPCTSTR lpsz) { ASSERT(lpsz == NULL || AfxIsValidString(lpsz)); <=========== Error is here! AssignCopy(SafeStrlen(lpsz), lpsz); return *this; } HERE is an example of the code: //BYTE btArr[3] = {67,245,67}; <========= I can see this! BYTE *btArr = lpVal[3].Value.bin.lpb; CString s = _T(""); s = btArr; <=========================== Error! s = lpVal[3].Value.bin.lpb[0]; <======== Error! MessageBox(0,s,"",0); Thanks in advance, Dan
>> AfxIsValidString(lpsz) This function checks if the address you have passed in points to memory that your program has 'read' access to. This routine looks for a terminating NULL char, since all valid 'C' and windows strings must have terminating NULL. All characters between the starting address and the terminating NULL must be in valid 'read' access memory. Looking at your samp,e code, you appear to be passing the address of an array that has no terminating NULL, so this is why the attempt to load the CString from this memory is failing. The bigger question is why you want to load and array 'byte' data, which does not appear to be a valid string value, into a CString ??
-
>> AfxIsValidString(lpsz) This function checks if the address you have passed in points to memory that your program has 'read' access to. This routine looks for a terminating NULL char, since all valid 'C' and windows strings must have terminating NULL. All characters between the starting address and the terminating NULL must be in valid 'read' access memory. Looking at your samp,e code, you appear to be passing the address of an array that has no terminating NULL, so this is why the attempt to load the CString from this memory is failing. The bigger question is why you want to load and array 'byte' data, which does not appear to be a valid string value, into a CString ??
I have written a program that processes mails from Outlook into a Database. I noticed that the Messages are being cut off after 255 characters. When reading the message text I am using: "CString csBody = lpVal[3].Value.lpszA;" which gives be only 255. another value is: "lpVal[3].Value.bin.lpb;" which returns a LPBYTE...see below (from MSDN). I have also looked at "lpVal[3].Value.bin.cb;" which returns "8792808"?? I am basically really confused! typedef struct _SBinary { ULONG cb; LPBYTE lpb; } SBinary, FAR *LPSBinary; Members cb Count of bytes in the lpb member. lpb Pointer to the PT_BINARY property value. Thanks in advance, Dan
-
I have written a program that processes mails from Outlook into a Database. I noticed that the Messages are being cut off after 255 characters. When reading the message text I am using: "CString csBody = lpVal[3].Value.lpszA;" which gives be only 255. another value is: "lpVal[3].Value.bin.lpb;" which returns a LPBYTE...see below (from MSDN). I have also looked at "lpVal[3].Value.bin.cb;" which returns "8792808"?? I am basically really confused! typedef struct _SBinary { ULONG cb; LPBYTE lpb; } SBinary, FAR *LPSBinary; Members cb Count of bytes in the lpb member. lpb Pointer to the PT_BINARY property value. Thanks in advance, Dan
Ok. You will need to rethink this, or approach things fromn another angle. The "lpVal[3].Value.bin.lpb" variable is NOT a suitable pointer to initialize a CString with. By definition, a CString is useful for holding NULL terminated plain text. It IS possible to make a CString hold binary info, but that's a topic for another day (and a much longer discussion!) What you need to do first is find out why you only get 255 chars from the "lpVal[3].Value.lpszA" pointer. I don't knowe the Outlook format at all, but this sounds like the data you want - yet it's being truncated. Chase that down first. If you find that you really do need to process the binary data in order to get the full body of text (sounds strange, but might be true), then I'd suggest the STL vector (or perhaps stringstream) as a better container for working with the binary data you want to process.
-
Ok. You will need to rethink this, or approach things fromn another angle. The "lpVal[3].Value.bin.lpb" variable is NOT a suitable pointer to initialize a CString with. By definition, a CString is useful for holding NULL terminated plain text. It IS possible to make a CString hold binary info, but that's a topic for another day (and a much longer discussion!) What you need to do first is find out why you only get 255 chars from the "lpVal[3].Value.lpszA" pointer. I don't knowe the Outlook format at all, but this sounds like the data you want - yet it's being truncated. Chase that down first. If you find that you really do need to process the binary data in order to get the full body of text (sounds strange, but might be true), then I'd suggest the STL vector (or perhaps stringstream) as a better container for working with the binary data you want to process.
Thanks for you help...because I took a look from a far, I can now read the entire body of the message. The way I did this was first of all, I "Read the ____ing Manual". MAPI says that if you have a large message to read, you should do the following (I felt you deserved how I got it to work!: hr = pmsgRoute->OpenProperty(PR_BODY, STGM_READ, (LPUNKNOWN FAR *) &lpstreamBody); if(S_OK != GetScode(hr)) { DebugTraceResult(OpenProperty, hr); goto err; } hr = lpstreamBody->Stat(&statstg, STATFLAG_NONAME); if(S_OK != GetScode(hr)) { DebugTrace("IStream::Stat failed"); goto err; } Assert(statstg.cbSize.HighPart == 0); if(MAPIAllocateBuffer(statstg.cbSize.LowPart + 1, (LPVOID FAR *) &lpszNoteText)) { goto err; } hr = lpstreamBody->Read(lpszNoteText, statstg.cbSize.LowPart, &cb); if(S_OK != GetScode(hr)) { DebugTrace("IStream::Read failed"); goto err; } lpszNoteText[statstg.cbSize.LowPart] = '\0'; SetDlgItemText(hDlg, IDC_RTNOTE, lpszNoteText); MAPIFreeBuffer(lpszNoteText); lpszNoteText = NULL; lpstreamBody->Release(); lpstreamBody = NULL; Thanks in advance, Dan