CString Convert to LPCTSTR
-
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:)
-
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:)
-
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:)
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
-
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:)
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! ]
-
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:)
rxgmoral wrote:
LPCTSTR lpszStr=Rxg.GetBuffer();
If you aren't going to be modifying the contents of
Rxg
, there's no need to callGetBuffer()
.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
-
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:)
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
-
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:)
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
-
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:)
if you want to use
GetBuffer
then callReleaseBuffer
_**
**_
WhiteSky