1. Accessing C variables/structures

Hi,

When using a C library from Euphoria, how do I access the variables and
structures made available by that library?

Thanks,
Ben Logan
________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com

new topic     » topic index » view message » categorize

2. Re: Accessing C variables/structures

On Wed, 26 Jul 2000 06:54:58 EDT, Ben Logan <wbljr79 at HOTMAIL.COM> wrote:

>Hi,
>
>When using a C library from Euphoria, how do I access the variables and
>structures made available by that library?
>
>Thanks,
>Ben Logan

 If you are talking about a "C" file like aclib.lib this type library file

 has to be linked to your program which can not be done with Euphoria,

 If you are talking about DLL's there all kinds of examples in the various

 librarys and sources in the archive.

new topic     » goto parent     » topic index » view message » categorize

3. 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

new topic     » goto parent     » topic index » view message » categorize

4. Re: Accessing C variables/structures

Ben Logan writes:
> When using a C library from Euphoria, how do I
> access the variables and structures made available
> by that library?

In Linux Euphoria you can link with (get the address of)
a C variable using define_c_var().
In WIN32 there is no way to link directly with a variable,
but you can access variables and structures using the
methods just described by Matthew Lewis.

Regards,
   Rob Craig
   Rapid Deployment Software
   http://www.RapidEuphoria.com

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu