Thread: Using DLLs
View Single Post
  #4  
Old 01-03-2001, 10:47 PM
PoseFant PoseFant is offline
Senior Member
 
Join Date: Jan 2001
Posts: 1,002
Default Using DLLs

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 :

NET_API_STATUS NetUserAdd(

LPWSTR servername,
DWORD level,
LPBYTE buf,
LPDWORD parm_err
);

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 :

Type
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 ...


Regards


/Filip
Reply With Quote