update platform 7

Documentation Version for Comments and Changes

You are invited to make any changes...add any comments.

Changes will `eventually` be merged into the offical documentation.

Leave any commnents here...

...

... back to index page OE documentation



"QuickView" (if it's on your system). You will see a list of all the C routines that the dll exports.

To find out which .dll file contains a particular Windows C function, run Euphoria\demo\dsearch.ex

Accessing C Variables

You can get the address of a C variable using define_c_var. You can then use poke and peek to access the value of the variable.

Accessing C Structures

Many C routines require that you pass pointers to structures. You can simulate C structures using allocated blocks of memory. The address returned by allocate can be passed as if it were a C pointer.

You can read and write members of C structures using peek and poke, or peek4u, peek4s, and poke4. You can allocate space for structures using allocate.
You must calculate the offset of a member of a C structure. This is usually easy, because anything in C that needs 4 bytes will be assigned 4 bytes in the structure. Thus C int's, char's, unsigned int's, pointers to anything, etc. will all take 4 bytes. If the C declaration looks like:

// Warning C code ahead! 
 
struct example { 
    int a;           // offset  0 
    char *b;         // offset  4 
    char c;          // offset  8 
    long d;          // offset 12 
}; 

To allocate space for "struct example" you would need:

atom p = allocate(16) -- size of "struct example" 

The address that you get from allocate is always at least 4-byte aligned. This is useful, since Windows structures are supposed to start on a 4-byte boundary. Fields within a C structure that are 4-bytes or more in size must start on a 4-byte boundary in memory. 2-byte fields must start on a 2-byte boundary. To achieve this you may have to leave small gaps within the structure. In practice it is not hard to align most structures since 90% of the fields are 4-byte pointers or 4-byte integers.

You can set the fields using something like:

poke4(p + 0, a) 
poke4(p + 4, b) 
poke4(p + 8, c) 
poke4(p +12, d) 

You can read a field with something like:

d = peek4(p+12) 

Tip:
For readability, make up Euphoria constants for the field offsets. See Example below.

constant RECT_LEFT = 0, 
RECT_TOP  = 4, 
RECT_RIGHT = 8, 
RECT_BOTTOM = 12,
Not Categorized, Please Help

Search



Quick Links

User menu

Not signed in.

Misc Menu