Core Function DLLImport as Params
From Sputnik Wiki
DLLImport( <DLLName>, <FunctionName/Alias>, <ReturnType>, <ParameterType>, <CharSet/CallingConvention> )
Contents |
Description
See DLLImport( <varies...> ) for description
Parameters
DLLName
The name of the DLL you want to import a function from
FunctionName/Alias
The function you wish to import from the DLL.
You can add an alias to the function for example if you want to import printf from msvcrt.dll but Sputnik already contains a printf you must alias the function by entering it like so:
"printf:myprintf" // This will import printf as normal but it will callable only by using the name myprintf
ReturnType
What type of return does this function do choices are:
void null pointer byte sbyte char wchar int16 int32 int64 uint16 uint32 uint64 float double string *string
ParameterType
How many and what type of parameters does this function do choices are:
[TYPE] [Description] n NULL b SByte B Byte s Int16 S UInt16 i Int32 I UInt32 l Int64 L UInt64 f Float d Double p String t (IntPtr) Pointer (A numeric value but is an address of something) T (UIntPtr) Pointer (A numeric value but is an address of something) * Pointer READ BELOW: % Array READ BELOW: // Examples ippi // Send Int32, String, String Int32 ip*pi // Send Int32, String, POINTER String Int32 fid // Send Float, Int32, Double fi*d // Send Float, Int32, POINTER Double i%pp // Send Int32, ARRAY String, String About pointers: The variable is passed as a POINTER and if the variable is modified in the DLL it modifies the actual Sputnik variable at the same time. So if you send a $var as a *p string pointer then the DLL function runs lower case on the string the string in your $var will have changed too (Same for all data types including doubles, ints etc). About arrays: Currently arrays CANNOT also be passed as pointers (modifying the array in your DLL does not modify the array in Sputnik but evenutally I will make it so it does). This allows you to send arrays of objects for example %p sends an array of strings such as array("one", "two", "three"); You can send arrays of everything even doubles and ints etc. You cannot use ARRAY and POINTER at to the same variable example: %*p but you can use one or the other Your $variable data is converted into the type you specify upon calling the function so if you put "d" for double and your variable contains a string it will convert it to a double.
CharSet/CallingConvention
Here you define what char set and optionally what calling convention to use.
Choices are:
"" // No char set will be used "Void" // No char set will be used "Ansi" "Unicode" "Auto" // It will try decide what it wants to use // Now you can optionally decide if you want a // calling convention for example if you are using a // C/C++ DLL you need to use cdecl as the calling convention // Choices of calling convention are: cdecl fastcall stdcall thiscall winapi // You must add them to the string using the : for example: "Ansi:cdecl" // Use Ansi char set and cdecl calling convention "Unicode:stdcall" // Use Unicode char set and stdcall calling convention
Return Value
See DLLImport( <varies...> ) for return value
Remarks
None.
Example
DllImport('User32.dll', 'MessageBox', 'Int32', 'ippi', 'Unicode'); // Setup a few variables $MB_YESNO = 0x04; $MB_ICONINFORMATION = 0x40; $IDYES = 6; // Make the call $RetVal = MessageBox(0, "Hello There", "Title", $MB_YESNO | $MB_ICONINFORMATION); If ( $RetVal == $IDYES ) { println("YES was pressed"); } else { println("NO was pressed"); }