Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Accessing global vars in an exe

Posted on 1999-08-03
4
Medium Priority
?
225 Views
Last Modified: 2010-04-15
I have an application on AIX that dynamically loads libraries at run-time (the executable is not linked to the libraries). Is it possible to access a global variable inside the executable, from the loaded library ? I tried declaring the global, then using "extern long glName;", and it compiles. But when I try to access it, my app crashes. P.S. my 'C' is quite rusty.

Thankyou,
Glen.
0
Comment
Question by:gburson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 10

Accepted Solution

by:
rbr earned 400 total points
ID: 1264171
Try this
1.c Your programm

long global_var=10;

long *get_globalvar(void)
{
      return (&global_var);
}

2.c your dll

long *pglobal_var=get_globalvar();




0
 

Author Comment

by:gburson
ID: 1264172
Thanks for the response. I am trying to test it. Can you advise me on how to export the function name. I have declared it like,

long * getAppInfo(void);

but when I check the exported functions, its not there (I check using 'nm' as I am running on AIX).

Thanks again,
Glen.
0
 
LVL 11

Expert Comment

by:alexo
ID: 1264173
How do you export functions in a DLL under AIX?
You should be able to do the same with a global variable.
0
 

Author Comment

by:gburson
ID: 1264174
I had the same problem originally with the global (it wasn't exported). I referenced it in some of the code, and then it was exported. Not true with the function. I have called it in the code, explicitly named it in an export file, used the linker option to export all symbols, and its still not there !

I must be missing something ...

Ta,
Glen.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question