Re: Accessing C variables/structures
> -----Original Message-----
> From: Ben Logan
> When using a C library from Euphoria, how do I access the
> variables and
> structures made available by that library?
As Bernie mentioned, this only works with DLL's, like the win32 API.
I'd recommend checking out win32lib's handling of structures. The important
routines are:
allot()
allocate_structure()
allotted_size()
fetch()
store()
Basically, you define a series of constants that you'll use to access
structures. For example, if the C declaration looks somthing like:
typedef struct _point{
LONG rectLeft;
LONG rectTop;
LONG rectRight;
LONG rectBottom
} POINT;
Then in Eu you'd do this:
global constant
rectLeft = /allot( Long ),
rectTop = /allot( Long ),
rectRight = /allot( Long ),
rectBottom = /allot( Long ),
SIZEOF_RECT = /allotted_size()
When you want to create a RECT structure yourself:
atom rect
rect = allocate_struct( SIZEOF_RECT )
store( rect, rectLeft, left )
store( rect, rectTop, top )
store( rect, rectRight, right )
store( rect, rectBottom, bottom )
To retrieve values, you simply use fetch:
left = fetch( rect, rectLeft )
etc...
C functions will return pointers to structures. So if you receive a pointer
to a RECT structure, just substitute that value for 'rect' above. It's
important to remember to use free() when you're done with a structure, so
you don't leak memory. Also, if the structure includes a pointer to a
string (usually starts with 'lpsz') you'll need to free_strings() when
you're done with it.
Matt
|
Not Categorized, Please Help
|
|