Core Function DLLCall

From Sputnik Wiki
Jump to: navigation, search
DLLCall( <Dll/DLLName>, <FunctionName/Alias>, <ReturnType>, <ParameterType>, <CharSet/CallingConvention>, <Parms> )

Contents

Description

Dynamically call a function in a DLL.

Parameters

DLLName

See DLLImport( <varies...> ) for DLLName

You can optionally insert the return value from a DLLOpen() here instead of the DLLName()

In which case you ignore all other parameters until you hit the <Params>

FunctionName/Alias

See DLLImport( <varies...> ) for FunctionName/Alias

ReturnType

See DLLImport( <varies...> ) for ReturnType

ParameterType

See DLLImport( <varies...> ) for ParameterType

CharSet/CallingConvention

See DLLImport( <varies...> ) for CharSet/CallingConvention

Params

None, one or more than one parameter to pass to the DLL function.

Return Value

See DLLImport( <varies...> ) for return value

Remarks

DLLCall() is basically a wrapper for DLLImport() it will import the DLL function and immediately call it.

You can use DLLOpen() to store a previously opened DLL function so you can call it over and over again with DLLCall which is significantly after than just using DLLCall() alone.

The reason it is faster to open it with DLLOpen() first (or just use DLLImport instead) is because since Sputnik is made in C# there is no physical way for it to dynamically call DLLs at runtime without using a C/C++ DLL. (which I could include with Sputnik but choose not to to keep the amount of DLLs needed to a minimal) So Sputnik has to physically compile the DLLCall internally in its RAM as an object it can call and the compiler take takes a fraction of a second but obviously too slow for thousands of calls a second. Therefor it's best to use DLLOpen() or DLLImport() so the compile only takes place ONCE making the Call part extremely fast just like any other function.

Example

Example of using DLLCall() with all its parameters

// Setup a few variables
$MB_YESNO = 0x04;
$MB_ICONINFORMATION = 0x40;
$IDYES = 6;
// Make the call
$RetVal = DLLCall(	'User32.dll', 'MessageBox', 'Int32', 'ippi', 'Unicode',
					0, "Hello There", "Title", $MB_YESNO | $MB_ICONINFORMATION
				);
If ( $RetVal == $IDYES )
{
	println("YES was pressed");
}
else
{
	println("NO was pressed");
}

Example of using DLLCall() with minimal parameters by using DLLOpen() to avoid having to redefine the function

// Store the DLL function to call later
$Call = DLLOpen('User32.dll', 'MessageBox', 'Int32', 'ippi', 'Unicode');
// Setup a few variables
$MB_YESNO = 0x04;
$MB_ICONINFORMATION = 0x40;
$IDYES = 6;
// Make the call
$RetVal = DLLCall($Call, 0, "Hello There", "Title", $MB_YESNO | $MB_ICONINFORMATION);
If ( $RetVal == $IDYES )
{
	println("YES was pressed");
}
else
{
	println("NO was pressed");
}
// Remove the DLL once we dont need it anymore
DLLClose($Call);

Example of using DLLCall() with the Library class "API" from "Win32" folder this class provides a wrapper for DLLOpen() DLLImport() DLLClose() and DLLCall() all rolled into one it works similar to how Perl calls APIs.

// Include the API class
Include('Win32/API.spk');
 
// Store the DLL function to call later
my $Call = new API('User32.dll', 'MessageBox', 'Int32', 'ippi', 'Unicode');
// Setup a few variables
$MB_YESNO = 0x04;
$MB_ICONINFORMATION = 0x40;
$IDYES = 6;
// Make the call
$RetVal = $Call->Call(0, "Hello There", "Title", $MB_YESNO | $MB_ICONINFORMATION);
If ( $RetVal == $IDYES )
{
	println("YES was pressed");
}
else
{
	println("NO was pressed");
}
// Remove the DLL once we dont need it anymore
Unset($Call);
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox