Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HOW DO YOU USE THE DECLARE STATEMENT??

Status
Not open for further replies.

TNN

Programmer
Sep 13, 2000
417
0
0
US
In VB6 help the DECLARE statement is stated as follows:

"Used at module level to declare references to external procedures in a dynamic-link library (DLL)."

My question is how do you know what the external procedure does in the dll? In other words how do you know what to call? When they say external procedure I presume they mean a procedure within the dll. How do you find out what a dll does and then what procedure to call from within it??

It looks like the dll doesn't even have to be referenced in the projects references. How does it find the correct dll??

Can anyone give me any info on this?? Thank You.

TNN, Tom



TOM
 
Um,

do you think you could go back to the beginning and describe what your problem is ?

Transcend
[gorgeous]
 
The declare statment links VB code with DLL entry points, which is effectively what the VB6 help says

The confusion arises because there are 2 (basic) sorts of DLL
1) COM based (aka Active-X)
and
2) Non-COM based

VB6 uses COM based files (DLL, OCX and EXE) extensively accessed through either the references (DLL and EXE) or components (OCX). In order for the file to appear in the VB component/reference list, it has to be registered with windows (use regsvr32 for ocx and dll and commad switch -regserver for EXE) The file can then be used in standard ways i.e.
Code:
dim myobj as mylib.object
set myobj = new ...

for non-COM dlls (many windows dlls) the declare statment tells VB, where to find the DLL, what the internal DLL name of the routine is, what VB should call it, what the input parameters are and what the return value is...

example
Code:
Public Declare Function SetWindowPos Lib "user32" Alias "SetWindowPos" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
broken down..

Public - scope of declaration (Public is seen thoroughout project and can only be used in a module, private can be used in a form / class etc)

Function - returns a value Sub doesn't

SetWindowPos - the Name VB will interpret as a call to this DLL function. SO you can change this to whatever you want.

lib "user32" - which contains the function, yo can include apath here if neccessary, but I believe that the search path of the PC is used anyway.

"SetWindowPos" - The internal DLL function name, which is not always the same as the external VB name. Windows often has different versions of the same function for different character coding (UNICODE etc)

parameter list - list of parameters used by function (note many require use of byval keyword)

return type - return type.
How do you find out what a dll does and then what procedure to call from within it??

most of the API functions have a declaration supplied by MS (or other) in the API viewer add in) So they are largely declared for you, however, some can need tweaking for particular jobs (and some are plain wrong)

Take Care

Matt
If at first you don't succeed, skydiving is not for you.
 
Further to Matt's post there are some examples of declaring and using API functions here:


________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'

for steam enthusiasts
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top