Click here to Skip to main content
16,005,141 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralBurn CD Data Pin
ColinDavies20-May-03 15:58
ColinDavies20-May-03 15:58 
GeneralRe: Burn CD Data Pin
J. Dunlap20-May-03 18:54
J. Dunlap20-May-03 18:54 
GeneralRe: Burn CD Data Pin
Joerg Wiedenmann20-May-03 20:14
Joerg Wiedenmann20-May-03 20:14 
GeneralAppending text to an edit control (mem errors) Pin
stf20-May-03 11:08
stf20-May-03 11:08 
GeneralRe: Appending text to an edit control (mem errors) Pin
Neville Franks20-May-03 12:10
Neville Franks20-May-03 12:10 
GeneralRe: Appending text to an edit control (mem errors) Pin
John R. Shaw20-May-03 13:44
John R. Shaw20-May-03 13:44 
GeneralRe: Appending text to an edit control (mem errors) Pin
dabs22-May-03 1:12
dabs22-May-03 1:12 
GeneralRe: Appending text to an edit control (mem errors) Pin
stf22-May-03 17:54
stf22-May-03 17:54 
Thanks a lot for the help everyone. Here is what I've got now:

int cTxtLen = GetWindowTextLength(hwndEdit);
if(cTxtLen > 0)
{
    pszMem = (LPTSTR) GlobalAlloc(GPTR, cTxtLen * sizeof(WCHAR));
    if (pszMem == NULL )
        OkMessage (hwnd, TEXT ("Alloc failed!!!"), TEXT ("\0")) ;
    pszMem = (LPTSTR)GlobalLock(pszMem);
    if (pszMem == NULL )
        OkMessage (hwnd, TEXT ("GlobalLock failed!!!"), TEXT ("\0")) ;
    GetWindowText(hwndEdit,(LPWSTR)pszMem,cTxtLen + 1);
    List = pszMem;
    GlobalUnlock(pszMem);
    pszMem = (LPTSTR) GlobalFree(pszMem);
    if(pszMem != NULL)
        OkMessage (hwnd, TEXT ("GlobalFree failed!!!"), TEXT ("\0")) ;
    // run List through a function that appends more text
    SendMessage (hwndEdit, WM_SETTEXT, 0, (LPARAM) List.GetBuffer(0)) ;
    List.ReleaseBuffer();
}


Neville Franks: I have already ruled out the function that is appending the text as not being a problem. I'm getting errors like:

The instruction at "0x77f5215e" referenced memory at "0x00000004". The memory could not be "written".
Click on OK to terminate the program

Unhandled exception at 0x77f536f7 in list.exe: 0xC0000005: Access violation writing location 0x003a0043.

Also I'm not that familiar with MFC at the moment which is why I'm trying to stick with just the API functions.

This code does fine for 5 times through but on the sixth time I get an error like the ones listed above. Both seem to be dealing with "writing" the memory, I'm not sure if it makes a difference or not but the variable "List" is of CString type. Also, could it be overflowing the edit control?

Thanks for the help,
stf
GeneralEnumerating DCs using ADSI Pin
Lhenno Ferrari20-May-03 11:03
Lhenno Ferrari20-May-03 11:03 
GeneralCComboBox on a CToolBar Pin
Chris Losinger20-May-03 10:40
professionalChris Losinger20-May-03 10:40 
GeneralRe: CComboBox on a CToolBar Pin
Chris Richardson20-May-03 11:02
Chris Richardson20-May-03 11:02 
GeneralRe: CComboBox on a CToolBar Pin
Anonymous20-May-03 20:58
Anonymous20-May-03 20:58 
GeneralStart VPN connection programmatically Pin
trevorb20-May-03 7:53
trevorb20-May-03 7:53 
GeneralRe: Start VPN connection programmatically Pin
Daniel Turini20-May-03 8:46
Daniel Turini20-May-03 8:46 
GeneralRe: Start VPN connection programmatically Pin
Joaquín M López Muñoz20-May-03 11:37
Joaquín M López Muñoz20-May-03 11:37 
GeneralRe: Start VPN connection programmatically Pin
Daniel Turini20-May-03 12:18
Daniel Turini20-May-03 12:18 
GeneralArrays and Memory Usage Pin
73Zeppelin20-May-03 7:00
73Zeppelin20-May-03 7:00 
GeneralRe: Arrays and Memory Usage Pin
valikac20-May-03 8:37
valikac20-May-03 8:37 
GeneralRe: Arrays and Memory Usage Pin
peterchen20-May-03 13:26
peterchen20-May-03 13:26 
GeneralRe: Arrays and Memory Usage Pin
73Zeppelin20-May-03 14:00
73Zeppelin20-May-03 14:00 
GeneralRe: Arrays and Memory Usage Pin
yaname20-May-03 16:03
yaname20-May-03 16:03 
GeneralRe: Arrays and Memory Usage Pin
peterchen21-May-03 2:04
peterchen21-May-03 2:04 
GeneralRe: Arrays and Memory Usage Pin
73Zeppelin21-May-03 3:46
73Zeppelin21-May-03 3:46 
GeneralRe: Arrays and Memory Usage Pin
peterchen22-May-03 7:58
peterchen22-May-03 7:58 
GeneralRe: Arrays and Memory Usage Pin
73Zeppelin22-May-03 10:54
73Zeppelin22-May-03 10:54 

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.