Click here to Skip to main content
15,918,889 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: app fails to load double-clicked file Pin
jmkhael13-Aug-02 13:48
jmkhael13-Aug-02 13:48 
GeneralRe: app fails to load double-clicked file Pin
Jake Palmer13-Aug-02 14:01
Jake Palmer13-Aug-02 14:01 
GeneralRe: app fails to load double-clicked file Pin
jmkhael13-Aug-02 14:11
jmkhael13-Aug-02 14:11 
GeneralExporting Data Pin
Peter Liddle13-Aug-02 13:06
Peter Liddle13-Aug-02 13:06 
GeneralRe: Exporting Data Pin
Ancient Dragon13-Aug-02 14:39
Ancient Dragon13-Aug-02 14:39 
GeneralRe: Exporting Data Pin
Peter Liddle13-Aug-02 22:32
Peter Liddle13-Aug-02 22:32 
GeneralRe: Exporting Data Pin
Ancient Dragon14-Aug-02 0:26
Ancient Dragon14-Aug-02 0:26 
GeneralDynamic memory allocation - Best Practices. Pin
djrisc13-Aug-02 12:43
djrisc13-Aug-02 12:43 
Trying not to make any assumptions, I have been making my code so that strings retrieved from edit controls, the registry, etc dynamically allocate the space needed.

In my code I have been doing things such as this all over the place:


<br />
_TCHAR* pszString = NULL;<br />
int iLen = 0;<br />
<br />
iLen = SendDlgItemMessage(hWnd, IDC_EDITCNTRL, EM_LINELENGTH, (WPARAM)0, (LPARAM)0); // Get length of the string.<br />
iLen++; // Add space for null termination.<br />
pszString = new _TCHAR[iLen]; // Allocate the space needed.<br />
ZeroMemory(pszString, iLen); // Clean out the buffer.<br />
*(WORD *)pszString = iLen;  // Set the first Word to the size of the buffer.<br />
SendDlgItemMessage(hWnd, IDC_EDITCNTRL, EM_GETLINE, (WPARAM 0, (LPARAM)pszString); // Fill the buffer.<br />
<br />
// use our new string pointer for whatever..<br />
<br />
delete []pszString; // Nuke the buffer.<br />
<br />


This is of course just example code, but is the most optimized way to go about allocating the space for strings dynamically? I'm just curious how most people go about this in Windows.

Thanks!



. djrisc .
GeneralRe: Dynamic memory allocation - Best Practices. Pin
Bill Wilson13-Aug-02 13:03
Bill Wilson13-Aug-02 13:03 
GeneralRe: Dynamic memory allocation - Best Practices. Pin
Christian Graus13-Aug-02 13:12
protectorChristian Graus13-Aug-02 13:12 
GeneralRe: Dynamic memory allocation - Best Practices. Pin
Todd Smith13-Aug-02 19:01
Todd Smith13-Aug-02 19:01 
GeneralMS Q167296 Pin
Rainer Mangold13-Aug-02 11:47
Rainer Mangold13-Aug-02 11:47 
GeneralRe: MS Q167296 Pin
Chris Losinger13-Aug-02 11:58
professionalChris Losinger13-Aug-02 11:58 
GeneralRe: MS Q167296 Pin
Rainer Mangold13-Aug-02 12:45
Rainer Mangold13-Aug-02 12:45 
GeneralpeekMessage and Getmessage relatedquestion Pin
imran_rafique13-Aug-02 11:19
imran_rafique13-Aug-02 11:19 
GeneralRe: peekMessage and Getmessage relatedquestion Pin
Peter Occil13-Aug-02 11:28
Peter Occil13-Aug-02 11:28 
GeneralRe: peekMessage and Getmessage relatedquestion Pin
Tim Smith13-Aug-02 11:42
Tim Smith13-Aug-02 11:42 
QuestionHow to retrieve attachments from a POP3 server? Pin
Rickard Andersson2013-Aug-02 11:12
Rickard Andersson2013-Aug-02 11:12 
GeneralImage List and List control Pin
krisn13-Aug-02 10:58
krisn13-Aug-02 10:58 
GeneralRe: Image List and List control Pin
Bill Wilson13-Aug-02 13:06
Bill Wilson13-Aug-02 13:06 
GeneralRe: Image List and List control Pin
krisn13-Aug-02 23:48
krisn13-Aug-02 23:48 
GeneralRe: Image List and List control Pin
Bill Wilson14-Aug-02 6:52
Bill Wilson14-Aug-02 6:52 
GeneralRe: Image List and List control Pin
krisn14-Aug-02 7:40
krisn14-Aug-02 7:40 
GeneralDocument telling DialogBar to Update Pin
JennyP13-Aug-02 10:05
JennyP13-Aug-02 10:05 
GeneralRe: Document telling DialogBar to Update Pin
Tomasz Sowinski13-Aug-02 10:09
Tomasz Sowinski13-Aug-02 10:09 

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.