Click here to Skip to main content
16,004,887 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Dll used by app Pin
David Crow5-Jun-07 5:39
David Crow5-Jun-07 5:39 
GeneralRe: Dll used by app Pin
garfield1855-Jun-07 6:20
garfield1855-Jun-07 6:20 
QuestionCasts Pin
tom groezer5-Jun-07 2:18
tom groezer5-Jun-07 2:18 
AnswerRe: Casts Pin
Nibu babu thomas5-Jun-07 2:35
Nibu babu thomas5-Jun-07 2:35 
AnswerRe: Casts Pin
Rajkumar R5-Jun-07 2:37
Rajkumar R5-Jun-07 2:37 
AnswerRe: Casts Pin
jhwurmbach5-Jun-07 2:42
jhwurmbach5-Jun-07 2:42 
AnswerRe: Casts Pin
Matthew Faithfull5-Jun-07 2:42
Matthew Faithfull5-Jun-07 2:42 
AnswerRe: Casts Pin
CPallini5-Jun-07 2:42
mveCPallini5-Jun-07 2:42 
tom groezer wrote:
How do u pass a Cstring into a function that accepts LPSTR?


Usually the above is NOT a good idea, unless yoou know that the function doesn't change the passed buffer. Typically there are the following scenarios:
(1) The function doesn't change the buffer.
(2) The function changes the buffer and it accepts the size of the buffer as parameter


The better way to handle point (1) is rewriting the function prototype in order to accept a LPCSTR argument instead of a LPSTR one, then passing to the function directly the CString object (CString implements a LPCSTR cast operator). If you cannot change the function prototype, but ARE SURE that function doesn't change the buffer, then use the CString::GetBuffer method).

To handle scenario (2), use CString::GetBuffer in a consistent way, for instance:
void fillBuffer(LPSTR lpszBuffer, INT nBufferSize);
void myFunction()
{
  const int nSize = 10;
  CString myString;
  
  fillBuffer( myString.GetBuffer(nSize), nSize);
  myString.ReleaseBuffer();
}


If you hve any doubts, see GetBuffer documentation here [^].

Smile | :)


If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.

AnswerRe: Casts Pin
Paresh Chitte5-Jun-07 2:58
Paresh Chitte5-Jun-07 2:58 
QuestionRe: Casts Pin
David Crow5-Jun-07 3:12
David Crow5-Jun-07 3:12 
AnswerRe: Casts Pin
Nelek5-Jun-07 2:59
protectorNelek5-Jun-07 2:59 
GeneralRe: Casts Pin
CPallini5-Jun-07 3:14
mveCPallini5-Jun-07 3:14 
GeneralRe: Casts Pin
Nelek6-Jun-07 6:57
protectorNelek6-Jun-07 6:57 
GeneralRe: Casts Pin
jhwurmbach6-Jun-07 7:08
jhwurmbach6-Jun-07 7:08 
GeneralRe: Casts Pin
CPallini6-Jun-07 9:59
mveCPallini6-Jun-07 9:59 
GeneralRe: Casts Pin
Nelek8-Jun-07 6:20
protectorNelek8-Jun-07 6:20 
GeneralRe: Casts Pin
jhwurmbach5-Jun-07 23:27
jhwurmbach5-Jun-07 23:27 
GeneralRe: Casts Pin
Nelek6-Jun-07 6:59
protectorNelek6-Jun-07 6:59 
GeneralRe: Casts Pin
jhwurmbach6-Jun-07 7:02
jhwurmbach6-Jun-07 7:02 
AnswerRe: Casts Pin
Paresh Chitte5-Jun-07 3:01
Paresh Chitte5-Jun-07 3:01 
JokeRe: Casts Pin
CPallini5-Jun-07 3:15
mveCPallini5-Jun-07 3:15 
GeneralRe: Casts Pin
#realJSOP5-Jun-07 3:59
professional#realJSOP5-Jun-07 3:59 
GeneralRe: Casts Pin
Stephen Hewitt5-Jun-07 14:38
Stephen Hewitt5-Jun-07 14:38 
GeneralRe: Casts Pin
jhwurmbach5-Jun-07 23:31
jhwurmbach5-Jun-07 23:31 
AnswerRe: Casts Pin
Rajesh R Subramanian5-Jun-07 4:21
professionalRajesh R Subramanian5-Jun-07 4:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.