Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 01-02-2001, 11:09 PM
Goober Goober is offline
Junior Member
 
Join Date: Jan 2001
Posts: 17
Default Using DLLs

Could someone tell me how to use dlls?
Also, how do I find out what can be done with a dll?

Thanks
Goober
Reply With Quote
  #2  
Old 01-02-2001, 11:54 PM
PoseFant PoseFant is offline
Senior Member
 
Join Date: Jan 2001
Posts: 1,002
Default 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

Example :

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

Good Luck.


Regards

/Filip
Reply With Quote
  #3  
Old 01-03-2001, 08:19 PM
Goober Goober is offline
Junior Member
 
Join Date: Jan 2001
Posts: 17
Default RE: RE: Using DLLs

I'm sorry Filip, that made no sense to me at all.
What is:
YourPrefferedFunctionName
DLL_ParameterList
DLL_ReturnType
StdCall
DLL_FunctionName_Case_Sensitive

And how do I find out what DLL does what?

Thanks again
Goober
Reply With Quote
  #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
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 04:25 PM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.