Core Function DLLImport as Array
DLLImport( <array> )
Contents |
Description
See DLLImport( <varies...> ) for description
Parameters
array
The array must appear as so:
array( 'MyDLL.dll" // This part is optional array('user32.dll', 'MessageBox', 'Int32', 'ippi', 'Ansi'), );
- First there is the array itself.
- Second there is the optional "MyDLL.dll" to define a DLL to save the import as.
You can tell it to save the source code by adding : and a file name to the DLL example:
"MyDLL.dll:Source.cs"
The source is in C#
This parameter is optional so if you don't include the DLL name the DLLImport will just directly import these functions into your program instantly.
If you do include the DLL name then the functions will NOT be imported into your program instantly instead it will create a DLL file for you to use and you must import that file like so:
DLLImport("MyDLL.dll"); // You can import this DLL after you have compiled it
The benefit of compiling a DLL and importing that directly it saves having to recompile everything every time you call the function (Using the DLL is 10000x faster than regenerating all the calling code every time).
When you choose to import a DLL you created you can choose to only include it ONCE using the : for example:
DLLImport("MyDLL.dll:once"); // Now this DLL can only be include ONCE in your program // and any attempts to include it again will be rejected // since it is already included and working
You can also add additional strings to do special tasks when creating a DLL or just importing functions for example:
DLLImport( array( 'MyDLL.dll" '@AddBefore:c_" // causes c_ to get added before the Function names after creation array('user32.dll', 'MessageBox', 'Int32', 'ippi', 'Ansi'), // Normally the "MessageBox" imported would be called like so: MessageBox(0, "Test", "Test", 0); // HOWEVER since we added @AddBefore the name has changed to: c_MessageBox(0, "Test", "Test", 0); // We can use this to add stuff like wapi_ etc etc. ) );
'@AddBefore:c_" is a good way to modify the name of the imported files you can also use '@AddAfter:c_".
- Third you define additional arrays PER function you wish to import for example
array('user32.dll', 'MessageBox', 'Int32', 'ippi', 'Ansi')
In the above example the DLL name is 'user32.dll' its importing the function 'MessageBox' the return value is expected to be an 'Int32' and the parameters are 'ippi' meaning Int32, String, String, Int32 finally the strings are going to passed the functiyon as 'Ansi' (you could of course use 'Unicode' etc)
You can import many functions at once
For detailed information on the parameter options you can use to create this:
array('user32.dll', 'MessageBox', 'Int32', 'ippi', 'Ansi')
Click HERE
Return Value
See DLLImport( <varies...> ) for return value
Remarks
None.
Example
Example of a DLL creation
DllImport( array ( '@AddBefore:w_', // Makes the APIs start with w_ so MessageBox = w_MessageBox 'API.dll:API_DLL_Source.cs', // Tells it to produce a DLL and the Source code to it //'API.dll', // Tells it to produce only the dll // User32.dll array('User32.dll', 'MessageBox', 'Int32', 'ippi', 'Unicode'), array('User32.dll', 'GetMessageExtraInfo', 'Int32', '', ''), array('User32.dll', 'MapVirtualKey', 'UInt32', 'II', ''), array('User32.dll', 'keybd_event', '', 'bbIi', ''), array('User32.dll', 'VkKeyScan', 'Int16', 's', ''), array('User32.dll', 'SendInput', 'UInt32', 'Iti', ''), array('User32.dll', 'GetAsyncKeyState', 'Int16', 'I', ''), array('User32.dll', 'GetKeyState', 'Int16', 'I', ''), // Kernel32.dll array('Kernel32.dll', 'GetTickCount', 'Int32', '', ''), array('Kernel32.dll', 'GetTickCount64', 'Int64', '', '') ) );
Example of using the DLL (made in previous example)
DLLImport('API.dll'); // Setup a few variables $MB_YESNO = 0x04; $MB_ICONINFORMATION = 0x40; $IDYES = 6; // Make the call $RetVal = w_MessageBox(0, "Hello There", "Title", $MB_YESNO | $MB_ICONINFORMATION); If ( $RetVal == $IDYES ) { println("YES was pressed"); } else { println("NO was pressed"); }
Example of importing and using functions directly
DllImport( array ( '@AddBefore:w_', // Makes the APIs start with w_ so MessageBox = w_MessageBox // User32.dll array('User32.dll', 'MessageBox', 'Int32', 'ippi', 'Unicode'), array('User32.dll', 'GetMessageExtraInfo', 'Int32', '', ''), array('User32.dll', 'MapVirtualKey', 'UInt32', 'II', ''), array('User32.dll', 'keybd_event', '', 'bbIi', ''), array('User32.dll', 'VkKeyScan', 'Int16', 's', ''), array('User32.dll', 'SendInput', 'UInt32', 'Iti', ''), array('User32.dll', 'GetAsyncKeyState', 'Int16', 'I', ''), array('User32.dll', 'GetKeyState', 'Int16', 'I', ''), // Kernel32.dll array('Kernel32.dll', 'GetTickCount', 'Int32', '', ''), array('Kernel32.dll', 'GetTickCount64', 'Int64', '', '') ) ); // Setup a few variables $MB_YESNO = 0x04; $MB_ICONINFORMATION = 0x40; $IDYES = 6; // Make the call $RetVal = w_MessageBox(0, "Hello There", "Title", $MB_YESNO | $MB_ICONINFORMATION); If ( $RetVal == $IDYES ) { println("YES was pressed"); } else { println("NO was pressed"); }