DllStructAlloc

Create a Dll Structure handle to an entry in the WIL Structure descriptor table.

Syntax:

DllStructAlloc( member-descriptor [, memory-address ] )

Parameters:

(s) member-descriptor: tab or space character delimited list of data type*:name pairs of structure members. Data type and name must be separated by a colon (:) character. If  multiline strings are used, the data type and name must be separated by using a double colon (::) instead of the single colon and a type/name member pair must be on the same line. Multiple pairs can be on a single line.

(i) memory-address: [optional] DLL entry point supplied memory address to a DLL structure.

Returns:

(i) Dll structure handle.

 

The returned handle can be used with DllCall or DllCallCdecl when calling an external DLL entry point that requires the memory address of a C/C++ language style structure as a parameter.  The handle can be used to both pass information to or retrieve information from the DLL entry point depending on the entry point's implementation.

Member-descriptor

The member descriptor string parameter must contain the string representation of the C/C++ language structure to create.  Each member of the structure must have both a supported data type specifier and a name.  The data type specifier can be any data type from the list below.  

*Supported data type strings include: atom, bool, boolean, byte, char, colorref, double, dword, dword_ptr, dwordlong, float, handle, hbitmap, hbrush, hcursor, hdesk, hfile, hfont, hglobal, hicon, hinstance, hkey, hmenu, hmodule, hmonitor, hpen, hresult, hrgn, hwnd, int, int_ptr, int64, long, long_ptr, long64, ulong64, lparam, lpcstr, lpcwstr, lpstr, lptr, lpvoid, lpwstr, short, uchar, uint, ulong, unsigned char, unsigned int, unsigned long, ushort, wchar, wndproc, word, and wparam.

A supported data type name followed by an asterisk (*) character will be declared a pointer.  Note that the DllStructPeek and DllStructPoke functions do not perform any interpretation of the contents of the memory location contained in a member with an asterisk modified data type or the LPVOID data type.  Structure members declared as LPVOID or with an asterisk modifier will usually either contain or should be set to a valid memory address or 0 depending on the requirements of the Dll function using the structure.  See IntControl 32, IntControl 42, and IntControl 98 documentation for more information about using raw memory addresses in WIL scripts.

The member name can be any text excluding tab (@tab), space (" "), colons (:), or semicolons (;).  Each data type/member pair can be separated by white space or semicolons.

The member data types must be compatible with the documented data types for the DLL structure. Each structure member descriptor must be listed in the order indicated by the external DLL's documentation or 'header' file.  

Use the '[elements]' qualifier to indicate that a member is an array.  The opening square bracket ([) must immediately follow the name with no intervening white space and 'elements' must be an integer indicating the number elements in the array.

Memory-address

The optional second parameter is a structure memory address returned by an external DLL entry point.  The function copies the contents of the supplied memory location into memory allocated for the structure described by the first parameter.  This parameter is only necessary when an entry point returns a memory address to a structure or has an out parameter that is a pointer to a pointer to a structure.

Use the returned Dll structure handle with DllCall or DllCallCdecl by passing the handle to the external function with the new 'lpstruct' parameter type specifier. The structure descriptor table shares resources with binary buffers so a combined maximum of 128 binary buffer and DLL structure handles can be active at one time.

Note: the function assumes standard Windows 8 byte structure alignment.

Example:
;=========================================================
;   Create the structure
;   struct {
;      int            var1;
;      unsigned char  var2;
;      unsigned int   var3;
;      char           var4[128];
;      float          var5;
;   }
;=========================================================
descriptor = "int:var1 byte:var2 uint:var3 char:var4[128] float:var5"
structhandle = DllStructAlloc( descriptor )
;   Set data in the struct
DllStructPoke( structhandle, "var1", -1  )
DllStructPoke( structhandle, "var2", 255  )
DllStructPoke( structhandle, "var3", -1  )
DllStructPoke( structhandle, "var4", ArrayFromStr( "Hello World" )  )
DllStructPoke( structhandle, "var5", 99.0  )
;   Get data from the struct
Pause("var1", DllStructPeek( structhandle, "var1" ) )
Pause("var2", DllStructPeek( structhandle, "var2" ) )
Pause("var3", DllStructPeek( structhandle, "var3" ) )
Pause("var4", ArrayToStr( DllStructPeek( structhandle, "var4" ) ) )
Pause("var5", DllStructPeek( structhandle, "var5" ) )
; Free all resources associated with a DLL structure handle.
DllStructFree( structhandle )
Exit
See Also:

DataCast, DllCall, DllCallbackDestroy, DllCallCdecl, DllCall Additional information, Binary Operations, DllLoad, DllFree, DllHwnd, DllHinst, DllStructFree, DllStructPeek, DllStructPoke, IntControl 77,  IntControl 96, IntControl 97, IntControl 98