[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
--------------------------------------------------------------------------------
Defining a external DLL DLL [STATIC] FUNCTION <FunName>( ;
function to be called [ <Param1> AS <Type> ] ;
at RunTime [ <ParamN> AS <Type> ] ) ;
AS <return> [PASCAL] LIB <DllName>
#xcommand DLL [<static:STATIC>] FUNCTION <FuncName>( [ <uParam1> AS <type1> ] ;
[, <uParamN> AS <typeN> ] ) ;
AS <return> [<pascal:PASCAL>] LIB <*DllName*> ;
=> ;
[<static>] function <FuncName>( [NOREF(<uParam1>)] [,NOREF(<uParamN>)] ) ;;
local hDLL := LoadLibrary( <(DllName)> ) ;;
local cFarProc ;;
local uResult ;;
if hDLL != 0 ;;
cFarProc = GetProcAddress( hDLL, <(FuncName)>, [<.pascal.>], <return> [,<type1>] [,<typeN>] ) ;;
uResult = CallDLL( cFarProc [,<uParam1>] [,<uParamN>] ) ;;
FreeLibrary( hDLL ) ;;
end ;;
return uResult
#endif
FiveWin lets you declare an external DLL function to be called at RunTime
by its own name! See DllCall.prg example.
<FuncName> The name of the DLL function. Remember Clipper only uses
10 characters maximum length.
<Param1> Name of a parameter.
Length in bytes
<Type>, BYTE, CHAR 1
<return> WORD, BOOL, HANDLE, HWND, HDC 2
LONG, STRING, LPSTR, PTR 4
DOUBLE 8
<DllName> Name of the DLL.
We recommend to develop a C language based connection functions when you
are going to develop an intensively work with some DLLs. See "using
Windows API". Examples:
Calling SndPlaySound() at RunTime:
#include "FiveWin.ch"
function Main()
SndPlaySound( "tada.wav", 0 )
return
DLL FUNCTION SndPlaySound( cFile AS LPSTR, nType AS WORD ) AS BOOL ;
PASCAL LIB "MMSYSTEM.DLL"
Designing the same DLL connection using C language:
#include <WinTen.h>
#include <Windows.h>
#include <MMSystem.h>
#include <ClipApi.h>
CLIPPER SNDPLAYSOU() // ND()
{
_retl( sndPlaySound( _parc( 1 ), _parni( 2 ) ) );
}
In this situation it is necessary to use a specific LIB so the linker will
know how the DLL connection must be done at RunTime. Example:
TEST.DLL // Is a commercial DLL we are going to use
IMPDEF.EXE TEST.DEF TEST.DLL // IMPDEF.EXE is a tool Microsoft and
// Borland provides
Now, edit TEST.DEF -which it is an ascii file- and rename the symbols
with 10 characters or less with an underscore:
LESS10 ---> _LESS10
Then do:
IMPLIB.EXE TEST.LIB TEST.DEF
When linking use that .LIB !
Review our \WinApi directory C -only registered users- source code to see a
lot of examples of doing this.
Warning: SndPlaySound() is already built inside FiveWin.lib. It has been
used just in this example for learning purposes.
See Also:
CallDLL
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson