Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Beginner Question

Beginner Question

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestionlearning
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dan Madden
    wrote on last edited by
    #1

    Can anyone tell me how to convert a: BYTE *btArray ==> CStringArray I would really appreciate it. Thanks in advance, Dan

    P 1 Reply Last reply
    0
    • D Dan Madden

      Can anyone tell me how to convert a: BYTE *btArray ==> CStringArray I would really appreciate it. Thanks in advance, Dan

      P Offline
      P Offline
      Pavlos Touboulidis
      wrote on last edited by
      #2

      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

      D 1 Reply Last reply
      0
      • P Pavlos Touboulidis

        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

        D Offline
        D Offline
        Dan Madden
        wrote on last edited by
        #3

        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

        M 1 Reply Last reply
        0
        • D Dan Madden

          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

          M Offline
          M Offline
          Mike Burston
          wrote on last edited by
          #4

          >> 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 ??

          D 1 Reply Last reply
          0
          • M Mike Burston

            >> 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 ??

            D Offline
            D Offline
            Dan Madden
            wrote on last edited by
            #5

            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

            M 1 Reply Last reply
            0
            • D Dan Madden

              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

              M Offline
              M Offline
              Mike Burston
              wrote on last edited by
              #6

              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.

              D 1 Reply Last reply
              0
              • M Mike Burston

                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.

                D Offline
                D Offline
                Dan Madden
                wrote on last edited by
                #7

                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

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups