Pass String And Back

I want to send a pointer string (c-type strings only, please) to a function and have that function fill the pointer string. I know I can do this by casting the function itself as a string, but I want the function to return a BOOL instead of a string. I have tried something like this...

1
2
3
4
5
6
7
BOOL ParentFunction()
{
     char* chStr=NULL;

(do stuff)

     ChildFunction(hWnd, chStr);


Then in the child function...

1
2
3
4
5
BOOL ChildFunction(HWND hw, LPSTR lpString)
{
    (allocate memory and fill string)

    return TRUE;


However, this doesn't affect chStr in ParentFunction();

What I want is to have ChildFunction() fill the string and pass that data back in the parameter.

Also, I'm assuming that if I allocate memory in ChildFunction() that I can then free it in ParentFunction(), if I can get it to work, that is.
Last edited on
How about passing the LPSTR by reference? Like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
BOOL ParentFunction()
{
     char* chStr=NULL;

     //(do stuff)

     ChildFunction(hWnd, chStr);

     //(do stuff)

     //(dealocate memory for chStr)

     return TRUE;
}

//------------------

BOOL ChildFunction(HWND hw, LPSTR &lpString)
{
    //(allocate memory and fill string)

    return TRUE;
}
Last edited on
Thanks a bunch. I didn't even know you could do that. But it works like a charm, just like I wanted.
Glad to know and to be of help.

Ogoyant
Topic archived. No new replies allowed.