473,241 Members | 1,602 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,241 software developers and data experts.

Passing pointer to function using DLSYM()

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
mi*********@mtdproducts.com
Nov 14 '05 #1
7 5121
On 12 Jan 2004 11:42:17 -0800, mi*********@mtdproducts.com (Mike D.) wrote:
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";
OK. First thing is to show us the definition of your "string" user-defined type.
From your usage, you've put
typedef char *string;
somewhere in your code, prior to this statement. Is that correct?

result = FunctionB (&myString);
}

int FunctionB (string *myString)
{
int result;
int (*dlFunction) (string);

result = (*dlFunction) (*myString);
You left dlfunction uninitialized, so this statement isn't going to do what you
think it will do.
cout << *myString << endl;


Here, you go weird. It appears that you *don't* have a C program at all, and
thus your problem (no matter how interesting) is off topic in comp.lang.c.

While C and C++ (the language it /appears/ you are writing in) share many
constructs and philosophies, they are not identical languages. So, while (if we
ignore the C++ constructs in your code) your problem /may/ have a C solution, we
cannot assert that such a solution will apply to the C++ program you have
presented us with.

Best bet: go ask in comp.lang.c++ or one of the newsgroups dedicated to
programming on your platform.

[snip]

--
Lew Pitcher
IT Consultant, Enterprise Technology Solutions
Toronto Dominion Bank Financial Group

(Opinions expressed are my own, not my employers')
Nov 14 '05 #2
"Mike D." wrote:

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.
Sounds like it is off topic. What is a dynamic library.

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;
What is a string? Probably invading implementation namespace.

myString = "12345";
To do this myString must be a char*. Thus string must be a
typedef. Things are looking bad.

result = FunctionB (&myString);
I don't see any definition of FunctionB, which must receive a
char**
}

int FunctionB (string *myString)
Here it is. Why wasn't it defined before use.
{
int result;
int (*dlFunction) (string);

result = (*dlFunction) (*myString);
dlFunction is uninitialized. Nasal Demons are flying.

cout << *myString << endl;
You never defined cout, and what are all these left shifts? Maybe
this whole thing should be made into a compilable chunk, and moved
to c.l.c++, where it might be topical.
}

Now, the following function exists within the dynamic library called
by FunctionB, above.


No it doesn't. C has no dynamic libraries. I'm getting bored, so

... snip ...

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!

Nov 14 '05 #3
nrk
Mike D. wrote:
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);
Ignoring the C++ portions of your code, and other OT stuff in your post,
look at the above declaration: dlFunction is a pointer to a function that
takes a *string* (whatever that is) and returns an int. However, in your
definition of dlFunction below, dlFunction is a function that takes a
*pointer to string* and returns int. Since you want the passed parameter
to be modified by the function and retain those modifications later, you
most certainly want to pass a *pointer to string*. Perhaps, what you want
here is:
int (*dlFunction) (string *);


result = (*dlFunction) (*myString);

and this should likely be:
result = (*dlFunction) (myString);
cout << *myString << endl;
}
Now, the following function exists within the dynamic library called
by FunctionB, above.

int dlFunction (string *passedString)
Note that this definition takes a *pointer to string* as its argument, not a
string.

-nrk.

ps: it is rather unfortunate that you gave the same name to your
pointer-to-function and function.
{
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
mi*********@mtdproducts.com


Nov 14 '05 #4
Wow... are all newsgroups so full of condesending assholes, or did I
just get lucky?

I know fully well my code has c++ as well as C in it. It was the C
portion I asked for help with, therefore it was appropriate to ask in
this forum. The fact that I posted snippets of the C++ in my app is
irrelevent. C++ AND C can and often are used together when coding an
application.

Dlsym() is a function for accessing dynamic link libraries in C or
C++, so yes-- C DOES have the capability to access dynamic link
libraries.

The code I posted was a made-up example of what I tried to do. It is
not the actual functional code, so the fact that I didn't pick the
right function names to use for this example, or that I called the
function before declaring it is irrelevent. I posted the sample code
in the hopes that someone would simply say "here is why it isn't
working. Fix this and it should function properly."

So were all of you genious' treated like morons the first time you
asked for help with a code problem, or were you all born expert
programmers?


nrk <ra*********@deadbeef.verizon.net> wrote in message news:<U2***************@nwrddc01.gnilink.net>...
Mike D. wrote:
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);


Ignoring the C++ portions of your code, and other OT stuff in your post,
look at the above declaration: dlFunction is a pointer to a function that
takes a *string* (whatever that is) and returns an int. However, in your
definition of dlFunction below, dlFunction is a function that takes a
*pointer to string* and returns int. Since you want the passed parameter
to be modified by the function and retain those modifications later, you
most certainly want to pass a *pointer to string*. Perhaps, what you want
here is:
int (*dlFunction) (string *);


result = (*dlFunction) (*myString);


and this should likely be:
result = (*dlFunction) (myString);
cout << *myString << endl;
}
Now, the following function exists within the dynamic library called
by FunctionB, above.

int dlFunction (string *passedString)


Note that this definition takes a *pointer to string* as its argument, not a
string.

-nrk.

ps: it is rather unfortunate that you gave the same name to your
pointer-to-function and function.
{
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
mi*********@mtdproducts.com

Nov 14 '05 #5
Mike D. <mi*********@mtdproducts.com> scribbled the following:
Wow... are all newsgroups so full of condesending assholes, or did I
just get lucky?
Do you think anyone who tells you you are wrong is a condescending
asshole?
I know fully well my code has c++ as well as C in it. It was the C
portion I asked for help with, therefore it was appropriate to ask in
this forum. The fact that I posted snippets of the C++ in my app is
irrelevent. C++ AND C can and often are used together when coding an
application.
You are correct that if you need help with the C part, you should get
it here. However interoperability with C++ is defined by C++, not by
C.
Dlsym() is a function for accessing dynamic link libraries in C or
C++, so yes-- C DOES have the capability to access dynamic link
libraries.
No it doesn't. Dlsym() is not part of the C language, it's an
implementation-specific extension.
The code I posted was a made-up example of what I tried to do. It is
not the actual functional code, so the fact that I didn't pick the
right function names to use for this example, or that I called the
function before declaring it is irrelevent. I posted the sample code
in the hopes that someone would simply say "here is why it isn't
working. Fix this and it should function properly."
If what is at fault here is Dlsym(), then we can't help you, as Dlsym()
isn't part of the C language. You want an implementation-specific
group.
So were all of you genious' treated like morons the first time you
asked for help with a code problem, or were you all born expert
programmers?


*I* was treated like a moron at the first time, yes. I got over it
pretty quickly.

PS. Please don't top-post, thanks.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"I said 'play as you've never played before', not 'play as IF you've never
played before'!"
- Andy Capp
Nov 14 '05 #6
Mike D. writes:

[Response at end]
Wow... are all newsgroups so full of condesending assholes, or did I
just get lucky?

I know fully well my code has c++ as well as C in it. It was the C
portion I asked for help with, therefore it was appropriate to ask in
this forum. The fact that I posted snippets of the C++ in my app is
irrelevent. C++ AND C can and often are used together when coding an
application.

Dlsym() is a function for accessing dynamic link libraries in C or
C++, so yes-- C DOES have the capability to access dynamic link
libraries.

The code I posted was a made-up example of what I tried to do. It is
not the actual functional code, so the fact that I didn't pick the
right function names to use for this example, or that I called the
function before declaring it is irrelevent. I posted the sample code
in the hopes that someone would simply say "here is why it isn't
working. Fix this and it should function properly."

So were all of you genious' treated like morons the first time you
asked for help with a code problem, or were you all born expert
programmers?


nrk <ra*********@deadbeef.verizon.net> wrote in message

news:<U2***************@nwrddc01.gnilink.net>...
Mike D. wrote:
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);


Ignoring the C++ portions of your code, and other OT stuff in your post,
look at the above declaration: dlFunction is a pointer to a function that takes a *string* (whatever that is) and returns an int. However, in your definition of dlFunction below, dlFunction is a function that takes a
*pointer to string* and returns int. Since you want the passed parameter to be modified by the function and retain those modifications later, you
most certainly want to pass a *pointer to string*. Perhaps, what you want here is:
int (*dlFunction) (string *);


result = (*dlFunction) (*myString);


and this should likely be:
result = (*dlFunction) (myString);
cout << *myString << endl;
}
Now, the following function exists within the dynamic library called
by FunctionB, above.

int dlFunction (string *passedString)


Note that this definition takes a *pointer to string* as its argument, not a string.

-nrk.

ps: it is rather unfortunate that you gave the same name to your
pointer-to-function and function.
{
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!


I make no claims to understanding your problem. But I get the *feeling*
that you expect a function to "grow" a string. Since that function doesn't
own the space the string inhabits this seems like an unrealistic
expectation.

Although the problem is not at the boundaries, one would really like a
blackboard to describe this problem ....

To get help here you will have to rephrase your question and avoid using the
dreaded words "DLL". You do not swear in church and ....
Nov 14 '05 #7
Mike D. <mi*********@mtdproducts.com> spoke thus:
Wow... are all newsgroups so full of condesending assholes, or did I
just get lucky? etc.


You just got lucky. Do yourself a favor and take a look at

http://www.msu.edu/~pfaffben/writing...off-topic.html
http://www.eskimo.com/~scs/C-faq/top.html

and much will be made known to you.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Nov 14 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
3
by: mpatnam | last post by:
I have an executable which links to a static library (.a). I want to provide a hook by overriding a function part of this static library. Eg: I have a function "int blkstart(int i)" in this static...
11
by: truckaxle | last post by:
I am trying to pass a slice from a larger 2-dimensional array to a function that will work on a smaller region of the array space. The code below is a distillation of what I am trying to...
4
by: dkarthik | last post by:
Hello All, I am a newbie to C++. I was trying a sample program from internet which demonstrates dynamic class loading in C++. Actually, I thought of using this design, in one of the applications...
0
by: nirnimesh | last post by:
I'm intercepting a library function call using LD_PRELOAD and in-turn calling the orignial library function. Essentially, intercept.cc: void (*real_func)(void) = (void (*) (void))...
8
by: Ivan Liu | last post by:
Hi, I'd like to ask if passing an object as an pointer into a function evokes the copy constructor. Ivan
54
by: John | last post by:
Is the following program print the address of the function? void hello() { printf("hello\n"); } void main() { printf("hello function=%d\n", hello); }
7
by: TS | last post by:
I was under the assumption that if you pass an object as a param to a method and inside that method this object is changed, the object will stay changed when returned from the method because the...
1
by: etienne | last post by:
Hello all, i'm experimenting a problem in trying to cast a char * variable to a pointer to a function. My problem is that I want to execute functions in threads, using the pthread_create...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.