I need a snippet of EU code?
- Posted by Johnny Kinsey <jkinsey at MINDSPRING.COM> Mar 04, 1998
- 837 views
Help I need help with coding the File function's in Win32 API. Like the CopyFile, DeleteFile and others. The main prob. that I am having is how do you find out how much memory to allocate for a C structure. I have read the platform.doc that comes with the beta 2.0 ver. of EU and I have the win32.hlp for the different functions in the Win32 API so now what else do I need I can't find any where in the Docs above for the memory requirements of each structure. Do I just keep adding 4 bytes until it works for each parameter in the C function. This seems kinda iffy because what if I overwrite the OS in memory then what. Please someone give me some direction on this. Here is the section in the platform.doc that I am referring to. ------ Platform.doc ------------- You can read and write members of C structures using peek and poke, or peek4 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 or fewer 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 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 WIN32 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 numbers 0,4,8 and 12. e.g. constant A = 0, B = 4, C = 8, D = 12 Then you can write: d = peek4(p + D) ------- Platform.doc --------------------- Or am I completely screwed up. I would very much like to write a wrapper for these common file functions and one for updating and changing the windows registry if possible. Any help on this would be much appreciated. Thanks JKinsey