RE: Using DLLs
You can call DLL Functions in several ways, here's the most common :
Example Method one :
Function YourPrefferedFunctionName(DLL_ParameterList) : DLL_ReturnType; StdCall; External 'Filename of DLL' Name 'DLL_FunctionName_Case_Sensitive';
Example Method two :
Function DLL_FunctionName_Case_Sensitive(DLL_ParameterList) : DLL_ReturnType; StdCall; External 'Filename of DLL';
If you intend to call several functions from one DLL, it is recomended to declare a Constant for the DLL FileName
NetAPI = 'netapi32.dll';
AdvAPI = 'advapi32.dll';
Also ... read about directives such as "StdCall", sometimes for backward compatibility you may need other directives as CDecl.
The conventions specify, how the parameteres are handled by the Function call.
RE: RE: Using DLLs
I'm sorry Filip, that made no sense to me at all.
And how do I find out what DLL does what?
Hi again Goober ... )
Let's take NETAPI32.DLL as an example.
This DLL is created by Microsoft and the explanation of its use is described in the SDK help files.
A common Function in NETAPI32.DLL is NetUserAdd.
How it is declared within the DLL :
In Delphi Language this means :
Function NetUserAdd(ServerName : lpWStr; Level : DWord; Buf : lpByte; Parm_Err : lpDWord) : LongInt;
Since lpByte is a "C" Type we need to define it in Delphi :
lpByte = PByte;
PByte is declared in Windows.dcu as "PByte = ^Byte;"
When you want to use this Function in your Delphi app you may declare it in two ways ...
In the first method, you have the option to name the function within your environment, what ever you want, but then the Name clause at the end of the declaration need a Case Sensitive String :
Function AddUser(ServerName : lpWStr; Level : DWord; Buf : lpByte; Parm_Err : lpDWord) : LongInt; StdCall; External 'NETAPI32.DLL' Name 'NetUserAdd';
If you intend to use the actual name of the Function as declared in the DLLs Export table you don't need the Name clause :
Function NetUSerAdd(ServerName : lpWStr; Level : DWord; Buf : lpByte; Parm_Err : lpDWord) : LongInt; StdCall; External 'NETAPI32.DLL';
It is not so very difficult as it may seem, start with simple API Functions, they are all described in the SDK help files.
Also you will find several third_part DLLs on your system, the only ways of dealing with their export tables and understand them is either to find an example on the internet or to contact the producer and ask for help.
How do you know what DLL does what ... Well ... you don't know before you have used one or another Function in the actual DLL.
Again ... with API calls, in the SDK help files, there is a Quick Info ... with a Library part.
When you understand the use of the FUnction, check it's Library and you know what DLL it is declared in.
Then you know at least one of the DLLs Functions ... )
Sorry for my english ... I could explain better in Norwegian though ... )
Hope you understand ...