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. Calculate the size of CString object

Calculate the size of CString object

Scheduled Pinned Locked Moved C / C++ / MFC
question
12 Posts 6 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.
  • X Offline
    X Offline
    X2040
    wrote on last edited by
    #1

    how can i calculate the acctuale size of a certain CString object in bytes

    B A P A 4 Replies Last reply
    0
    • X X2040

      how can i calculate the acctuale size of a certain CString object in bytes

      B Offline
      B Offline
      bikram singh
      wrote on last edited by
      #2

      ?? Is this kinda what u mean: CString m = "a"; int size = sizeof(m) + m.GetLength() + 1; //1 for null size will contain '6' bytes... (4 for the internal pointer it maintains, + 1 for the "a", plus 1 for the null byte...) Bikram Singh

      R 1 Reply Last reply
      0
      • B bikram singh

        ?? Is this kinda what u mean: CString m = "a"; int size = sizeof(m) + m.GetLength() + 1; //1 for null size will contain '6' bytes... (4 for the internal pointer it maintains, + 1 for the "a", plus 1 for the null byte...) Bikram Singh

        R Offline
        R Offline
        Ravi Bhavnani
        wrote on last edited by
        #3

        CStrings are unicode objects (each character occupied 2 bytes). Also, as I understand it, the size of a CString object is fixed, regardless of the length of the string, since memory required to store the string is obtained from the heap. /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com

        B 1 Reply Last reply
        0
        • X X2040

          how can i calculate the acctuale size of a certain CString object in bytes

          A Offline
          A Offline
          Anonymous
          wrote on last edited by
          #4

          Works for both ansi, unicode. CString s = _T("Hello"); int bytes = (s.GetLength() + 1) * sizeof(TCHAR);

          1 Reply Last reply
          0
          • X X2040

            how can i calculate the acctuale size of a certain CString object in bytes

            P Offline
            P Offline
            peterchen
            wrote on last edited by
            #5

            What do you need the size for?


            we are here to help each other get through this thing, whatever it is Vonnegut jr.
            sighist || Agile Programming | doxygen

            X 1 Reply Last reply
            0
            • P peterchen

              What do you need the size for?


              we are here to help each other get through this thing, whatever it is Vonnegut jr.
              sighist || Agile Programming | doxygen

              X Offline
              X Offline
              X2040
              wrote on last edited by
              #6

              iam making a program like Norton ghost i want to save the files and their paths on another partition as a backup do you have any better idea to make a program like Norton Ghost? do know any function that copy a complete partition into backup disk?

              P 1 Reply Last reply
              0
              • X X2040

                iam making a program like Norton ghost i want to save the files and their paths on another partition as a backup do you have any better idea to make a program like Norton Ghost? do know any function that copy a complete partition into backup disk?

                P Offline
                P Offline
                peterchen
                wrote on last edited by
                #7

                For your purpose, the others said it already, it's (s.GetLength()+1)*sizeof(TCHAR). (however, you cannot simply pass the address of CString itself to a binary reader/writer)


                we are here to help each other get through this thing, whatever it is Vonnegut jr.
                sighist || Agile Programming | doxygen

                X 1 Reply Last reply
                0
                • P peterchen

                  For your purpose, the others said it already, it's (s.GetLength()+1)*sizeof(TCHAR). (however, you cannot simply pass the address of CString itself to a binary reader/writer)


                  we are here to help each other get through this thing, whatever it is Vonnegut jr.
                  sighist || Agile Programming | doxygen

                  X Offline
                  X Offline
                  X2040
                  wrote on last edited by
                  #8

                  is there any way or functions that can copy data as a low level binary from the drive to another location or drive (Norton Ghost like) . ex: copy files and directories with out getting the path of each file and copy it to the new location i mean to get binary data from the drive direct and copy it

                  B 1 Reply Last reply
                  0
                  • R Ravi Bhavnani

                    CStrings are unicode objects (each character occupied 2 bytes). Also, as I understand it, the size of a CString object is fixed, regardless of the length of the string, since memory required to store the string is obtained from the heap. /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com

                    B Offline
                    B Offline
                    bikram singh
                    wrote on last edited by
                    #9

                    Ravi Bhavnani wrote: CStrings are unicode objects (each character occupied 2 bytes). Possibly, but only with the UNICODE directive turned on i should think.. Ravi Bhavnani wrote: Also, as I understand it, the size of a CString object is fixed, regardless of the length of the string True, since CString contains only one pointer data member. But, Abdu's question was a bit vague ("actual size" was unclear to me, so i took a wild guess). Bikram Singh

                    R 1 Reply Last reply
                    0
                    • B bikram singh

                      Ravi Bhavnani wrote: CStrings are unicode objects (each character occupied 2 bytes). Possibly, but only with the UNICODE directive turned on i should think.. Ravi Bhavnani wrote: Also, as I understand it, the size of a CString object is fixed, regardless of the length of the string True, since CString contains only one pointer data member. But, Abdu's question was a bit vague ("actual size" was unclear to me, so i took a wild guess). Bikram Singh

                      R Offline
                      R Offline
                      Ravi Bhavnani
                      wrote on last edited by
                      #10

                      bikram singh wrote: Possibly, but only with the UNICODE directive turned on i should think.. Yes, you're quite correct. I was hasty in replying and am also guilty (?) of always supporting Unicode. /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com

                      1 Reply Last reply
                      0
                      • X X2040

                        is there any way or functions that can copy data as a low level binary from the drive to another location or drive (Norton Ghost like) . ex: copy files and directories with out getting the path of each file and copy it to the new location i mean to get binary data from the drive direct and copy it

                        B Offline
                        B Offline
                        bikram singh
                        wrote on last edited by
                        #11

                        Under WinNT+, you can use CreateFile("\\\\.\\C:") to open read-only access to any disk drive (hdd or fdd), and if you know the FAT/other file system format, you can easily read data using ReadFile(). On Win9x, you can read floppies using VxD services (it's there in MSDN as an example, but i dont remember where). For reading HDD's you need to either use 16-bit code (to call BIOS functions), or write a VxD. Bikram Singh

                        1 Reply Last reply
                        0
                        • X X2040

                          how can i calculate the acctuale size of a certain CString object in bytes

                          A Offline
                          A Offline
                          Archer282
                          wrote on last edited by
                          #12

                          I think what you want to know is how to calculate the size in pixels the string is going to occupy on the screen to do this just find the font's width ( i think there is a function like GetFont you could use to find it ) then multiply the font width by the number of characters in the string

                          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