xHarbour Reference Documentation > Function Reference |
Executes a DLL function via call template.
DllExecuteCall( <pCallTemplate>, [<xParams,...>] ) --> nResult
The function returns the result of the executed DLL function as a numeric value.
Function DllExecuteCall() executes a DLL function using the call template as it is prepared by function DllPrepareCall(). The DllPrepareCall()/DllExecuteCall() way of calling a function in an external DLL is advantageous when the same DLL function must be executed many times. The call template is prepared once and contains all information required to execute the DLL function. If a DLL function needs to be called only once or a few times, it can be called directly via DllCall(). The overhead of preparing the call template can be avoided in such cases.
See also: | DllCall(), DllPrepareCall(), FreeLibrary(), GetProcAddress(), GetLastError(), LoadLibrary() |
Category: | DLL functions , xHarbour extensions |
Source: | rtl\dllcall.c |
LIB: | xhb.lib |
DLL: | xhbdll.dll |
// The example implements two Windows API wrappers for conversion of // Ansi strings to Unicode and vice versa. The call templates for // DllExecuteCall() are created on the first function call and stored // in STATIC variables. #define DC_CALL_STD 0x0020 PROCEDURE Main LOCAL cString, cWideString cString := "Hello World" cWideString := AnsiToWide( cString ) ? Len( cString ), cString ? Len( cWideString ), cWideString ? WideToAnsi( cWideString ) RETURN FUNCTION AnsiToWide( cString ) STATIC pCallTemplate LOCAL nWideLen := 2 * ( Len( cString ) ) LOCAL cWideChar := Replicate( Chr(0), nWideLen ) LOCAL nRet IF pCallTemplate == NIL // create call template on first call pCallTemplate := DllPrepareCall( ; "Kernel32.dll", ; // external DLL DC_CALL_STD , ; // calling convention "MultiByteToWideChar" ) // external function ENDIF nRet := DllExecuteCall( ; pCallTemplate , ; 0 , ; 0 , ; cString , ; -1 , ; @cWideChar , ; nWideLen ) RETURN cWideChar FUNCTION WideToAnsi( cWideChar ) STATIC pCallTemplate LOCAL nLen := Int( Len( cWideChar ) / 2 ) LOCAL cString := Replicate( Chr(0), nLen ) LOCAL nRet IF pCallTemplate == NIL // create call template on first call pCallTemplate := DllPrepareCall( ; "Kernel32.dll", ; // external DLL DC_CALL_STD , ; // calling convention "WideCharToMultiByte" ) // external function ENDIF nRet := DllExecuteCall( ; pCallTemplate , ; 0 , ; 0 , ; cWideChar , ; -1 , ; @cstring , ; nLen , ; 0 , ; 0 ) RETURN cString
http://www.xHarbour.com