why doesn't the callback function change a value in a global struct?

Viewed 35

I have this struct called String that contains a pointer to a char array and the length of that array, now when the callback function grabOutput is called it does copy the output into the ptr allocated buffer but the len is not change

#define  BUF_SIZE 1024

typedef struct String
{
    char * ptr;
    int len;
} String;


HANDLE Child_IN_R = NULL;
HANDLE Child_IN_W = NULL;
HANDLE Child_OUT_R = NULL;
HANDLE Child_OUT_W = NULL;
HANDLE handle = NULL;                
String str;
DWORD grabOutput(LPVOID lpParam )
{
    BOOL success = FALSE;
    DWORD dwRead, total =0;
    char buffer[BUF_SIZE];
    while(1)
    {
        success = ReadFile(Child_OUT_R, buffer, BUF_SIZE, &dwRead, NULL);
        if (!success) break;
        memcpy(str.ptr+total, buffer, dwRead);
        total += dwRead;
        str.ptr = realloc(str.ptr, total+BUF_SIZE); 
    }
    str.len = total; // this does not change the value of str.len 
    return 0;
}

why doesn't this code change the value of str.len in the global String str?

0 Answers
Related