Click here to Skip to main content
15,920,801 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: determine the menu option selected Pin
David Crow3-Dec-04 8:17
David Crow3-Dec-04 8:17 
GeneralRe: determine the menu option selected Pin
Araj013-Dec-04 8:28
Araj013-Dec-04 8:28 
GeneralRe: determine the menu option selected Pin
David Crow3-Dec-04 9:01
David Crow3-Dec-04 9:01 
GeneralRe: determine the menu option selected Pin
Araj013-Dec-04 9:28
Araj013-Dec-04 9:28 
GeneralRe: determine the menu option selected Pin
David Crow3-Dec-04 9:31
David Crow3-Dec-04 9:31 
Generaldsp-file for Visual Studio 6.0 Pin
Reinhold442-Dec-04 11:01
Reinhold442-Dec-04 11:01 
Generalkilled for free std::string, Help please. I will give rate Pin
LongIsland2-Dec-04 10:48
LongIsland2-Dec-04 10:48 
GeneralRe: killed for free std::string, Help please. I will give rate Pin
John R. Shaw2-Dec-04 15:08
John R. Shaw2-Dec-04 15:08 
You do not need to free the string, because std::string is a class, it will handle the freeing when caller() returns. Of course it you want to do it yourself, then just call str.clear().

std::string myfunc()
{
    // allocate buffer etc...
    ...
    // get data etc...
    ...
    // ok, if pData holds a null terminate c-str
    std::string strRet = (const char*)pData;
    // finished with pData, now free it
    ...
    return strRet;
}
//
// Problem with above: To many constructor calls.
// 1) std::string strRet = (const char*)pData;
// 2) std::string str = myfunc();
// In 2 you are copying from the string returned
// by myfunc() to the string in caller and then
// the string created in myfunc() is destroyed.
//
// Better myfunc() with 1 constructor call
bool myfunc(std::string& strRet)
{
    // allocate buffer etc...
    ...
    // get data etc...
    ...
    // ok, if pData holds a null terminate c-str
    strRet = (const char*)pData;
    // finished with pData, now free it
    ...
    // if we made it here, every thing is ok
    return true;
}



INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
GeneralRe: killed for free std::string, Help please. I will give rate Pin
Maximilien2-Dec-04 16:19
Maximilien2-Dec-04 16:19 
Generalremoving the Main Frame title bar in a SDI Pin
kdehairy2-Dec-04 10:42
kdehairy2-Dec-04 10:42 
GeneralRe: removing the Main Frame title bar in a SDI Pin
David Crow2-Dec-04 10:45
David Crow2-Dec-04 10:45 
GeneralRe: removing the Main Frame title bar in a SDI Pin
kdehairy2-Dec-04 10:54
kdehairy2-Dec-04 10:54 
GeneralRe: removing the Main Frame title bar in a SDI Pin
Graham Bradshaw2-Dec-04 11:03
Graham Bradshaw2-Dec-04 11:03 
GeneralRe: removing the Main Frame title bar in a SDI Pin
kdehairy2-Dec-04 22:08
kdehairy2-Dec-04 22:08 
GeneralWhy this code alway crash my app?Need help. Pin
Teerayoot2-Dec-04 9:47
Teerayoot2-Dec-04 9:47 
GeneralRe: Why this code alway crash my app?Need help. Pin
David Crow2-Dec-04 10:26
David Crow2-Dec-04 10:26 
GeneralRe: Why this code alway crash my app?Need help. Pin
Teerayoot3-Dec-04 2:26
Teerayoot3-Dec-04 2:26 
GeneralRe: Why this code alway crash my app?Need help. Pin
David Crow3-Dec-04 3:25
David Crow3-Dec-04 3:25 
GeneralRe: Why this code alway crash my app?Need help. Pin
Teerayoot3-Dec-04 4:48
Teerayoot3-Dec-04 4:48 
GeneralCompilation Times in VS C++ .NET Pin
haggersr2-Dec-04 8:17
haggersr2-Dec-04 8:17 
Generalresizing dialog box Pin
haseeb_saeed2-Dec-04 8:05
haseeb_saeed2-Dec-04 8:05 
GeneralRe: resizing dialog box Pin
kdehairy2-Dec-04 10:37
kdehairy2-Dec-04 10:37 
GeneralRe: resizing dialog box Pin
haseeb_saeed3-Dec-04 3:01
haseeb_saeed3-Dec-04 3:01 
GeneralRe: resizing dialog box Pin
John R. Shaw2-Dec-04 16:06
John R. Shaw2-Dec-04 16:06 
GeneralRe: resizing dialog box Pin
haseeb_saeed3-Dec-04 3:03
haseeb_saeed3-Dec-04 3:03 

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.