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. CString Convert to LPCTSTR

CString Convert to LPCTSTR

Scheduled Pinned Locked Moved C / C++ / MFC
help
8 Posts 8 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.
  • R Offline
    R Offline
    rxgmoral
    wrote on last edited by
    #1

    CString Convert to LPCTSTR i write DLL file,it is static dll i want CString type Convert to LPCTSTR but error Code: <<<<<<<<<<>>>>>>>> <<<<<<>>>>>> class AFX_NOVTABLE dll { public: __declspec(dllexport) LPCTSTR Fun(); }; <<<<<<>>>>> LPCTSTR dll::Fun() { CString Rxg=_T("rxg"); LPCTSTR lpszStr=Rxg.GetBuffer(); return lpszStr; } <<<<<<<>>>>>>>> #pragma comment(lib,"dll.lib") #include "A.h" .................. dll d; LPCTSTR b=d.Fun(); error,why thank:)

    P Z T D S 7 Replies Last reply
    0
    • R rxgmoral

      CString Convert to LPCTSTR i write DLL file,it is static dll i want CString type Convert to LPCTSTR but error Code: <<<<<<<<<<>>>>>>>> <<<<<<>>>>>> class AFX_NOVTABLE dll { public: __declspec(dllexport) LPCTSTR Fun(); }; <<<<<<>>>>> LPCTSTR dll::Fun() { CString Rxg=_T("rxg"); LPCTSTR lpszStr=Rxg.GetBuffer(); return lpszStr; } <<<<<<<>>>>>>>> #pragma comment(lib,"dll.lib") #include "A.h" .................. dll d; LPCTSTR b=d.Fun(); error,why thank:)

      P Offline
      P Offline
      prasad_som
      wrote on last edited by
      #2

      rxgmoral wrote:

      error,

      what it states ?

      Prasad Notifier using ATL

      1 Reply Last reply
      0
      • R rxgmoral

        CString Convert to LPCTSTR i write DLL file,it is static dll i want CString type Convert to LPCTSTR but error Code: <<<<<<<<<<>>>>>>>> <<<<<<>>>>>> class AFX_NOVTABLE dll { public: __declspec(dllexport) LPCTSTR Fun(); }; <<<<<<>>>>> LPCTSTR dll::Fun() { CString Rxg=_T("rxg"); LPCTSTR lpszStr=Rxg.GetBuffer(); return lpszStr; } <<<<<<<>>>>>>>> #pragma comment(lib,"dll.lib") #include "A.h" .................. dll d; LPCTSTR b=d.Fun(); error,why thank:)

        Z Offline
        Z Offline
        Zac Howland
        wrote on last edited by
        #3

        CString has an operator for casting to LPCTSTR. There is no need to write code to do it, it is already done for you. On top of all that, you are creating a memory leak while trying to duplicate code that is written for you.

        If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

        1 Reply Last reply
        0
        • R rxgmoral

          CString Convert to LPCTSTR i write DLL file,it is static dll i want CString type Convert to LPCTSTR but error Code: <<<<<<<<<<>>>>>>>> <<<<<<>>>>>> class AFX_NOVTABLE dll { public: __declspec(dllexport) LPCTSTR Fun(); }; <<<<<<>>>>> LPCTSTR dll::Fun() { CString Rxg=_T("rxg"); LPCTSTR lpszStr=Rxg.GetBuffer(); return lpszStr; } <<<<<<<>>>>>>>> #pragma comment(lib,"dll.lib") #include "A.h" .................. dll d; LPCTSTR b=d.Fun(); error,why thank:)

          T Offline
          T Offline
          toxcct
          wrote on last edited by
          #4

          rxgmoral wrote:

          LPCTSTR dll::Fun() { CString Rxg=_T("rxg"); LPCTSTR lpszStr=Rxg.GetBuffer(); return lpszStr; }

          you return a local pointer...


          TOXCCT >>> GEII power

          [VisualCalc 3.0  updated ][Flags Beginner's Guide  new! ]

          1 Reply Last reply
          0
          • R rxgmoral

            CString Convert to LPCTSTR i write DLL file,it is static dll i want CString type Convert to LPCTSTR but error Code: <<<<<<<<<<>>>>>>>> <<<<<<>>>>>> class AFX_NOVTABLE dll { public: __declspec(dllexport) LPCTSTR Fun(); }; <<<<<<>>>>> LPCTSTR dll::Fun() { CString Rxg=_T("rxg"); LPCTSTR lpszStr=Rxg.GetBuffer(); return lpszStr; } <<<<<<<>>>>>>>> #pragma comment(lib,"dll.lib") #include "A.h" .................. dll d; LPCTSTR b=d.Fun(); error,why thank:)

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #5

            rxgmoral wrote:

            LPCTSTR lpszStr=Rxg.GetBuffer();

            If you aren't going to be modifying the contents of Rxg, there's no need to call GetBuffer().

            rxgmoral wrote:

            error,why

            Don't know.


            "Talent without discipline is like an octopus on roller skates. There's plenty of movement, but you never know if it's going to be forward, backwards, or sideways." - H. Jackson Brown, Jr.

            "Judge not by the eye but by the heart." - Native American Proverb

            1 Reply Last reply
            0
            • R rxgmoral

              CString Convert to LPCTSTR i write DLL file,it is static dll i want CString type Convert to LPCTSTR but error Code: <<<<<<<<<<>>>>>>>> <<<<<<>>>>>> class AFX_NOVTABLE dll { public: __declspec(dllexport) LPCTSTR Fun(); }; <<<<<<>>>>> LPCTSTR dll::Fun() { CString Rxg=_T("rxg"); LPCTSTR lpszStr=Rxg.GetBuffer(); return lpszStr; } <<<<<<<>>>>>>>> #pragma comment(lib,"dll.lib") #include "A.h" .................. dll d; LPCTSTR b=d.Fun(); error,why thank:)

              S Offline
              S Offline
              Steve S
              wrote on last edited by
              #6

              1. First, you have a CString which is only temporary. When Fun() ends, the CString object will be destructed. 2. As has been pointed out, GetBuffer() isn't needed, since there's a perfectly good cast operator for LPCTSTR. 3. As written, the temporary CString (Rxg) will get locked by GetBuffer(). This will no doubt cause problems when the temporary is destructed, since the CString data is now locked. To get string data back from the DLL function, you could pass in a destination buffer and size as parameters, and after checking size, you can then fill in the string. To retain the semantics of Fun(), have it return the address of the destination buffer (although the parameter should be LPTSTR, not LPCTSTR).

              Steve S Developer for hire

              1 Reply Last reply
              0
              • R rxgmoral

                CString Convert to LPCTSTR i write DLL file,it is static dll i want CString type Convert to LPCTSTR but error Code: <<<<<<<<<<>>>>>>>> <<<<<<>>>>>> class AFX_NOVTABLE dll { public: __declspec(dllexport) LPCTSTR Fun(); }; <<<<<<>>>>> LPCTSTR dll::Fun() { CString Rxg=_T("rxg"); LPCTSTR lpszStr=Rxg.GetBuffer(); return lpszStr; } <<<<<<<>>>>>>>> #pragma comment(lib,"dll.lib") #include "A.h" .................. dll d; LPCTSTR b=d.Fun(); error,why thank:)

                T Offline
                T Offline
                ThatsAlok
                wrote on last edited by
                #7

                rxgmoral wrote:

                LPCTSTR dll::Fun() { CString Rxg=_T("rxg"); LPCTSTR lpszStr=Rxg.GetBuffer(); return lpszStr; }

                better you make memory in heap before sending it outside of function.. though getbuffer create the  memory in heap.. but it need subsequent call of releasebuffer for releasing the memory.. which is rather difficult from out side better would be....  LPTSTR lpszStr=new TCHAR[Rxg.GetLength()+1];   lstrcpy(lpszStr,Rxg);  return lpszStr;

                "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief and You

                1 Reply Last reply
                0
                • R rxgmoral

                  CString Convert to LPCTSTR i write DLL file,it is static dll i want CString type Convert to LPCTSTR but error Code: <<<<<<<<<<>>>>>>>> <<<<<<>>>>>> class AFX_NOVTABLE dll { public: __declspec(dllexport) LPCTSTR Fun(); }; <<<<<<>>>>> LPCTSTR dll::Fun() { CString Rxg=_T("rxg"); LPCTSTR lpszStr=Rxg.GetBuffer(); return lpszStr; } <<<<<<<>>>>>>>> #pragma comment(lib,"dll.lib") #include "A.h" .................. dll d; LPCTSTR b=d.Fun(); error,why thank:)

                  H Offline
                  H Offline
                  Hamid Taebi
                  wrote on last edited by
                  #8

                  if you want to use GetBuffer then call ReleaseBuffer

                  _**


                  **_

                  WhiteSky


                  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