M
Mike D.
I have a problem with a dynamic library I am developing, but it is
really more of a pointer issue than anything else. Hopefully someone
here can lend me some assistance or insight into resolving this.
Ok... here goes....
I have a function that passes a pointer to a string to another
function. For example:
int FunctionA ()
{
int result;
string myString;
myString = "12345";
result = FunctionB (&myString);
}
int FunctionB (string *myString)
{
int result;
int (*dlFunction) (string);
result = (*dlFunction) (*myString);
cout << *myString << endl;
}
Now, the following function exists within the dynamic library called
by FunctionB, above.
int dlFunction (string *passedString)
{
cout << "before: " << *passedString << endl;
*passedString = *passedString + "hello";
cout << "after: " << *passedString << endl;
}
So, now here is the problem. Everything seems to works just fine.
When dlFunction is called is will display the following output:
before: 12345
after: 12345hello
This tells me that I passed the proper pointers through these
functions, since I am able to manipulate the original "12345" string
through the dynamic library call to dlFunction. However, when the
FunctionB function continues execution, and it displays the contents
of the *myString pointer, is shows the string as containing only the
orginal value of "12345."
So it appears that the dlFunction dynamic library function manipulates
the string only within it's own context, never actually altering the
original string.
How do I pass the appropriate pointers or references to allow the
dlFunction function to alter the string being pointed to with the
*passedString pointer? What am I missing/doing wrong?
Any help would be GREATLY appreciated!
Thanks,
Mike Dailey
(e-mail address removed)
really more of a pointer issue than anything else. Hopefully someone
here can lend me some assistance or insight into resolving this.
Ok... here goes....
I have a function that passes a pointer to a string to another
function. For example:
int FunctionA ()
{
int result;
string myString;
myString = "12345";
result = FunctionB (&myString);
}
int FunctionB (string *myString)
{
int result;
int (*dlFunction) (string);
result = (*dlFunction) (*myString);
cout << *myString << endl;
}
Now, the following function exists within the dynamic library called
by FunctionB, above.
int dlFunction (string *passedString)
{
cout << "before: " << *passedString << endl;
*passedString = *passedString + "hello";
cout << "after: " << *passedString << endl;
}
So, now here is the problem. Everything seems to works just fine.
When dlFunction is called is will display the following output:
before: 12345
after: 12345hello
This tells me that I passed the proper pointers through these
functions, since I am able to manipulate the original "12345" string
through the dynamic library call to dlFunction. However, when the
FunctionB function continues execution, and it displays the contents
of the *myString pointer, is shows the string as containing only the
orginal value of "12345."
So it appears that the dlFunction dynamic library function manipulates
the string only within it's own context, never actually altering the
original string.
How do I pass the appropriate pointers or references to allow the
dlFunction function to alter the string being pointed to with the
*passedString pointer? What am I missing/doing wrong?
Any help would be GREATLY appreciated!
Thanks,
Mike Dailey
(e-mail address removed)