James Lin <[EMAIL PROTECTED]> wrote: hvreddy wrote:
>
> As every body knows we can't use global variables directly in the
> shared library so i created a structure as a global variable and
> used global variables inside structure.
> Then i tryed to allocate memory for the structure variable in
> LibOpen finction using MemPtrNew and free in LibClose function.
> Library compiled fine and when i try to open it in my application
> it is crashing.
> here is my code
>
> typedef struct
> {
>
> int x ;
> int y ;
> float z;
> }GLOBALTEST;
>
> GLOBALTEST *globaltest;
>
> It is there in the global scope.
And that's the problem: you can't use any globally-scoped variables. That's
what a global is. That your global variable is a pointer to a structure
allocated by MemPtrNew is irrelevant; the pointer you're using is stored in a
global!
Shared libraries should retrieve the SysLibTblEntryType structure for the
library's reference number and store a pointer to its pseudo-global data in
it. That's what the reference number is there for. For example:
Err LibOpen(UInt16 libRefNum)
{
GLOBALTEST* globaltest = MemPtrNew(sizeof *globaltest);
SysLibTblEntryType* libEntryP = SysLibTblEntry(libRefNum);
libEntryP->globalsP = globaltest;
/* ... other opening code ... */
}
See PalmSource's SampleLib sample code.
- James
--
For information on using the PalmSource Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/support/forums/
Dear James,
Thanks for your reply,
In SampleLib I really didn't understand where they are using
Global(pseudo)variables.
If you don't mind can you please little elaborate the explanation .
Means As your example in LibOpen
ibEntryP->globalsP = globaltest;
After that we need not to assign Any memory for the structure?
Can we use this globaltest variable in other part of library as a normal
global variable ?
Thanks once again for your help.
Regards,
Harsha
---------------------------------
Heres a new way to find what you're looking for - Yahoo! Answers
--
For information on using the PalmSource Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/support/forums/