DLL Libraries
Program Control
 
This group of functions is designated only for programmers who well know Windows API realm. It facilitates adding of such functions and properties which the Peter programming system does not support itself. With help of functions for DLL it is possible to make use of all functions of the Windows operating system and alike functions of additional DLL libraries. The functions are not somehow checked by the Peter system (like e.g. validity of memory pointers) and therefore the program crash or serious damage of data can occurs when it is incorrectly used. Detailed descriptions of the Windows API SDK system functions you can obtain on the Microsoft Internet pages (www.microsoft.com) in the developers section.
 
Image bm196.GIF load library
 
A parameter of the function is DLL library filename (include file extension). This function assures loading of the library into memory and returns numeric identifier of the library. If the library is not found then zero value is returned. The LoadLibrary system function is used to load library. The number which it returns corresponds to the handle of loaded module.
 
Image bm197.GIF free library
 
The function frees library (whose identification number is entered as function parameter) from memory. Entering zero as invalid number is allowed. The FreeLibrary system function is used to free library. The entered number corresponds to the handle of module.
 
Image bm198.GIF import function
Image bm199.GIF library identifier
Image bm200.GIF function name
Image bm201.GIF number of parameters
Image bm202.GIF calling convention C
 
The import function element is used to find a function in the library. The GetProcAddress system function is used. As first parameter an identification number of module loaded in memory is entered (entering zero as invalid number is allowed). The second parameter is name of the function (text). If such function is not found, then second attempt is performed - an "A" letter is added to the name of function (variant with 8-bit text parameters). The third parameter is count of parameters of the function (number of parameters between 0 to 65K is checked). Without entering it a zero number of parameters is assumed. By the term "one parameter" you can understand one entry in the stack with 4-byte size (that is doubleword). Last parameter is flag determining that the function is called with the C convention. That means all parameters are released from the stack after returning from the function. This calling convention is used for instance in the printf function and in further functions using variable number of parameters. All other functions use Pascal calling convention. That means called function provides releasing parameters from the stack (default setting). If the function is found a memory block with below described structure is returned. This block must be deleted by the function for freeing memory block before the program is closed. If the function is not found a zero number is returned. All parameters of functions are automatically cleared when creating the memory block of function.
 
Image bm203.GIF execute function
 
The execute function element assures calling and executing of the function of DLL library. As element parameter an address of memory block is entered which is returned by the previous element import function. It is usual memory block which can be created, modified or deleted by the operations for memory block service. For instance you can prepare several memory blocks for miscellaneous ways of calling of one function. Memory block for function calling has following structure:
 
(4 bytes) addres of the called function
(2 bytes) N number of parameters of the function (1 parameter is 4-byte entry in the stack)
(2 bytes) ancillary flags: if the bit 0 is set then C calling convention is used (parameters are deleted from the stack after returning from the function) otherwise Pascal calling convention is used (called function provides releasing parameters from the stack)
(N * 4 bytes) N parameters of function, the first parameter is on the lowest address of the stack when calling function
 
Parameters of the function must be set before calling function. By default all parameters are initialized to zero when importing function. Setting of the parameters is performed by following operations for manipulation with memory blocks. The first parameter is located on offset 8 from the beginning of the memory block. Every parameter is 4-byte number (doubleword). Attention on handing on text parameter - this parameter is pointer on ASCIIZ text in preponderance functions, not directly text itself. Element for executing function can be used either as command or as a function returning numeric parameter.
 
Image bm204.GIF create memory block
 
Required size of memory block is entered as parameter of the element. Element returns address of the memory block. The memory block must be deleted with the following function for freeing memory block when the program is closed. Memory blocks up to size 4 KB are served by internal efficient service of the Peter system which guarantees quick creating, modifying or deleting blocks. For memory blocks with size above 4 KB the HeapAlloc system function is used and blocks are rounded to 256-byte boundaries.
 
Image bm205.GIF free memory blok
 
This element ensures deleting of memory block, address of which is entered as a parameter. Entering invalid address 0 is allowed.
 
Image bm206.GIF change size of memory block
Image bm207.GIF address of memory block
Image bm208.GIF new size
 
The function ensures change size of the memory block. The first parameter is address of the memory block, size of which has to be changed. By entering zero value a new memory block will be created. The second parameter is new size of the memory block. By entering zero value this memory block will be deleted. The function returns address of new memory block. Thanks to internal optimization the memory block need not to be changed (the same address is returned). If size of the memory block does not suit then this function creates new block with required size and copies content of old block into it.
 
Image bm209.GIF read pointer
Image bm210.GIF write pointer
 
The read pointer and write pointer elements serve for setting addresses in memory, from/to where will be stored data using following elements for data reading/writing. By reading value of one of the following element a shift of the reading pointer occurs. By writing value into element a shift of the writing pointer occurs. The read/write pointers are not ever checked for validity. By incorrect manipulation undesirable modification of system/program memory can arrive.
 
Image bm211.GIF data copy
 
The data copy element ensures copy of data block from address appointed by read pointer to address appointed by write pointer. Size of data is determined by parameter of the element. Read pointer and write pointer are shifted by the entered data size after operation.
 
Image bm212.GIF data comparison
 
The data comparison element ensures comparison of data blocks appointed by read and write pointers. Size of data is determined by parameter of the element. If a difference between data is found then the element returns size of remaining data and read and write pointers stay adjusted to the different data. If data are the same then the element returns zero and read and write pointers point after end of data.
 
Image bm213.GIF byte with sign (char) (shift pointer by 1)
Image bm214.GIF byte without sign (BYTE) (shift pointer by 1)
Image bm215.GIF word with sign (short) (shift pointer by 2)
Image bm216.GIF word without sign (WORD) (shift pointer by 2)
Image bm217.GIF 3-byte with sign (shift pointer by 3)
Image bm218.GIF 3-byte without sign (shift pointer by 3)
Image bm219.GIF doubleword with sign (long) (shift pointer by 4)
Image bm220.GIF doubleword without sign (DWORD) (shift pointer by 4)
Image bm221.GIF decimal number 4 bytes (float) (shift pointer by 4)
Image bm222.GIF decimal number 8 bytes (double) (shift pointer by 8)
Image bm223.GIF logical value (BOOL) (shift pointer by 4)
Image bm224.GIF text terminated by null ASCIIZ (shift pointer by N+1)
Image bm225.GIF pointer to text terminated by null ASCIIZ (shift pointer by 4)
Image bm226.GIF text with fixed length (shift pointer by N, shorter text is enlarged with spaces)
Image bm227.GIF length N of text with fixed length (it need to be set before using of previous element)
 
With the help of elements for data access a program can read/write from/to the memory. By reading element a value is loaded from memory, address of which is determined by the read pointer. The read pointer is shifted by size of the element. By setting value of element the value is saved to memory, address of which is determined by the write pointer. The write pointer is shifted by size of the element. 8-bit characters are used at text elements. If text in UNICODE code is required than conversion of the text is needed using the MultiByteToWideChar and WideCharToMultiByte system functions. In mostly Windows functions a pointer to the text terminated by zero is handed on as a parameter (LPCTSTR type of parameter) instead of text itself. If the element for setting pointer to text terminated by null is used then content of used variable has not be modified until calling of the DLL function, otherwise the pointer can become invalid (only pointer to content of the text variable is handed on).
 
Image bm228.GIF read data from file
Image bm229.GIF write data to file
 
The read data from file and write data to file elements ensure reading/writing data from/to the file. Size of data to read/write is entered as a parameter of the element. Memory pointers for reading and writing point data in memory, file pointers point data in the file.
 
Image bm230.GIF identifier of window element
 
This element converts identification number of the window element of the Peter system to the identification number of the Windows (HWND). A zero is returned for invalid element.
 
Image bm231.GIF create 3D object from memory blocks
Image bm232.GIF number of vertices
Image bm233.GIF vertices
Image bm234.GIF normals (0=auto)
Image bm235.GIF texture mapping (0=none)
Image bm236.GIF colors (0=none)
Image bm237.GIF number of faces
Image bm238.GIF faces
 
This element serves for fast and efficient creation of 3D object of the 3D graphics e.g. with calculation. The element returns the identification number of the created object.
 
As the first parameter the number of object vertices is given. The second parameter is address of memory block which contains coordinates of the individual vertices. Each vertex is determined by 3 real 4-byte numbers representing X, Y and Z coordinate of the vertex.
 
The third parameter is address of memory block which contains normals. This parameter can be unused or zero can be used. In such case normals of the object will be generated automatically with angle for smoothing 0.5. If normals are used, their count must correspond to count of vertices. Normals are entered with the same way as vertices (3 real 4-byte numbers).
 
The fourth parameter is address of memory block which contains definition of texture mapping. A pair of real 4-byte numbers representing horizontal and vertical coordinates of the point in texture is entered for every vertex of the object. Left upper corner of the texture has coordinate (0,0), right lower corner has coordinate (1,1). The parameter can be omitted or zero can be used if texture mapping is not needed.
 
The fifth parameter is address of memory block which contains definition of colors of individual vertices of the object. Color for every vertex is entered as 4 real 4-byte numbers representing color components RGBA in order red, green, blue and alpha component. Every component has range 0 (=black) to 1 (=full brightness), zero value for alpha component represents transparency and 1 value represents full visibility. Number of colors must correspond to number of vertices of the object. Zero can be adduced instead of the address or parameter can be omited if color definition is not required, then uniform color will be used for whole object.
 
The sixth parameter states number of triangle faces from which the object is assembled. The seventh parameter is address of memory block which contains definition of faces of the object. Every face is a triangle with 3 vertices. Single face is determined with three 4-byte integers without sign representing index of the vertex. One vertex can be shared with more faces.
 
Image bm239.GIF memory block from 3D object
 
The element makes accessible definition of 3D object of the 3D graphics in purpose to export the object or to create modified version of the object. The identification number of the object is used as parameter of the element.
 
The element returns address of memory block which contains definition of the object. This memory block has size 32 bytes and contains eight 4-byte integer entries without sign. Meaning of the entries corresponds description of previous element create 3D object from memory blocks.
 
offset 0: parameters, now reserved and set to zero
offset 4: number of vertices of the object
offset 8: address of memory block containing coordinates of vertices
offset 12: address of memory block containing normals
offset 16: address of memory block containing texture mapping (0=none)
offset 20: address of memory block containing color of vertices (0=none)
offset 24: number of faces of the object
offset 28: address of memory block containing definition of faces
 
Important: Returned memory block containing definition of the object and individual data memory blocks alike are newly created and therefore they need to be deleted after completion of work with the data.

Full Html Context Help of The Peter - Gemtree Software & Children Programming