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. Can I use CString in a Win32 application ?

Can I use CString in a Win32 application ?

Scheduled Pinned Locked Moved C / C++ / MFC
c++csharpcomhelpquestion
9 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.
  • D Offline
    D Offline
    dlhson
    wrote on last edited by
    #1

    I developed a program as a Win 32 application (non-MFC) But I found it very difficult to work with string but without CString (MFC). Ex: I can't find a function to cut string from 1 to m (Left()) , a function to cut string from n to m (Mid())... Can I use this MFC class in my program without rewriting in MFC. Can I include this MFC class (.h, .cpp) like a normal class ? Help me !!! Hung Son A Vietnamese student i-g.hypermart.net dlhson2001@yahoo.com

    H J C M 5 Replies Last reply
    0
    • D dlhson

      I developed a program as a Win 32 application (non-MFC) But I found it very difficult to work with string but without CString (MFC). Ex: I can't find a function to cut string from 1 to m (Left()) , a function to cut string from n to m (Mid())... Can I use this MFC class in my program without rewriting in MFC. Can I include this MFC class (.h, .cpp) like a normal class ? Help me !!! Hung Son A Vietnamese student i-g.hypermart.net dlhson2001@yahoo.com

      H Offline
      H Offline
      Hans Ruck
      wrote on last edited by
      #2

      In Settings/General choose "Use MFC in a static library" rechi

      1 Reply Last reply
      0
      • D dlhson

        I developed a program as a Win 32 application (non-MFC) But I found it very difficult to work with string but without CString (MFC). Ex: I can't find a function to cut string from 1 to m (Left()) , a function to cut string from n to m (Mid())... Can I use this MFC class in my program without rewriting in MFC. Can I include this MFC class (.h, .cpp) like a normal class ? Help me !!! Hung Son A Vietnamese student i-g.hypermart.net dlhson2001@yahoo.com

        H Offline
        H Offline
        Hans Ruck
        wrote on last edited by
        #3

        And... In stdafx.h replace #include <windows.h> with #include <afx.h> rechi

        1 Reply Last reply
        0
        • D dlhson

          I developed a program as a Win 32 application (non-MFC) But I found it very difficult to work with string but without CString (MFC). Ex: I can't find a function to cut string from 1 to m (Left()) , a function to cut string from n to m (Mid())... Can I use this MFC class in my program without rewriting in MFC. Can I include this MFC class (.h, .cpp) like a normal class ? Help me !!! Hung Son A Vietnamese student i-g.hypermart.net dlhson2001@yahoo.com

          J Offline
          J Offline
          Joaquin M Lopez Munoz
          wrote on last edited by
          #4

          I'd suggest you consider it twice and try to stick with std::strings. As for the functions you need, it's simple to write them:

          std::string mid(const std::string& str,std::string::size_type n,std::string::size_type m)
          // extract chars from the n-th position up to the (m-1)-th, indexes are 0-based
          {
          std::string::size_type count=m<=str.size()?m-n:std::string::npos;
          return str.substr(n,count);
          }
           
          std::string left(const std::string& str,std::string::size_type n)
          // extracts n first leftmost chars
          {
          std::string::size_type count=n<=str.size()?n:str.size();
          return str.substr(0,count);
          }
           
          std::string right(const std::string& str,std::string::size_type n)
          // extracts n first rightmost chars
          {
          std::string::size_type count=n<=str.size()?n:str.size();
          return str.substr(str.size()-count,count);
          }

          Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

          H 1 Reply Last reply
          0
          • J Joaquin M Lopez Munoz

            I'd suggest you consider it twice and try to stick with std::strings. As for the functions you need, it's simple to write them:

            std::string mid(const std::string& str,std::string::size_type n,std::string::size_type m)
            // extract chars from the n-th position up to the (m-1)-th, indexes are 0-based
            {
            std::string::size_type count=m<=str.size()?m-n:std::string::npos;
            return str.substr(n,count);
            }
             
            std::string left(const std::string& str,std::string::size_type n)
            // extracts n first leftmost chars
            {
            std::string::size_type count=n<=str.size()?n:str.size();
            return str.substr(0,count);
            }
             
            std::string right(const std::string& str,std::string::size_type n)
            // extracts n first rightmost chars
            {
            std::string::size_type count=n<=str.size()?n:str.size();
            return str.substr(str.size()-count,count);
            }

            Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

            H Offline
            H Offline
            Hans Ruck
            wrote on last edited by
            #5

            Is it about the large amount of resources MFC is using? rechi

            J 1 Reply Last reply
            0
            • H Hans Ruck

              Is it about the large amount of resources MFC is using? rechi

              J Offline
              J Offline
              Joaquin M Lopez Munoz
              wrote on last edited by
              #6

              The resource issue is one reason. The most important objection, though, is of a more profound nature. Adhering to a huge framework for the sake of a tiny utility class like CString can cause more harm than good: if you for instance need to port your app to a non-Win32 platform, you'll be regretting you're locked into MFC for such a minute reason. My advice is one should use MFC for what is worth --doing GUI stuff for Windows. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

              C 1 Reply Last reply
              0
              • J Joaquin M Lopez Munoz

                The resource issue is one reason. The most important objection, though, is of a more profound nature. Adhering to a huge framework for the sake of a tiny utility class like CString can cause more harm than good: if you for instance need to port your app to a non-Win32 platform, you'll be regretting you're locked into MFC for such a minute reason. My advice is one should use MFC for what is worth --doing GUI stuff for Windows. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

                C Offline
                C Offline
                Chris Losinger
                wrote on last edited by
                #7

                that...and the fact that the original poster said "non-MFC". -c


                Cheap oil. It's worth it!

                Image Processing - just like mom used to make.

                1 Reply Last reply
                0
                • D dlhson

                  I developed a program as a Win 32 application (non-MFC) But I found it very difficult to work with string but without CString (MFC). Ex: I can't find a function to cut string from 1 to m (Left()) , a function to cut string from n to m (Mid())... Can I use this MFC class in my program without rewriting in MFC. Can I include this MFC class (.h, .cpp) like a normal class ? Help me !!! Hung Son A Vietnamese student i-g.hypermart.net dlhson2001@yahoo.com

                  C Offline
                  C Offline
                  Christian Graus
                  wrote on last edited by
                  #8

                  Instead of adding MFC, use std::string. It has a substr method which does what you're looking for. Christian I am completely intolerant of stupidity. Stupidity is, of course, anything that doesn't conform to my way of thinking. - Jamie Hale - 29/05/2002 Half the reason people switch away from VB is to find out what actually goes on.. and then like me they find out that they weren't quite as good as they thought - they've been nannied. - Alex, 13 June 2002

                  1 Reply Last reply
                  0
                  • D dlhson

                    I developed a program as a Win 32 application (non-MFC) But I found it very difficult to work with string but without CString (MFC). Ex: I can't find a function to cut string from 1 to m (Left()) , a function to cut string from n to m (Mid())... Can I use this MFC class in my program without rewriting in MFC. Can I include this MFC class (.h, .cpp) like a normal class ? Help me !!! Hung Son A Vietnamese student i-g.hypermart.net dlhson2001@yahoo.com

                    M Offline
                    M Offline
                    Michael Dunn
                    wrote on last edited by
                    #9

                    If you don't want to use std::string, use WTL which has a CString that works just like MFC's. --Mike-- Just released - RightClick-Encrypt - Adds fast & easy file encryption to Explorer My really out-of-date homepage Sonork-100.19012 Acid_Helm

                    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