how to use dll files in VB?

  • (2 Pages)
  • +
  • 1
  • 2

17 Replies - 14565 Views - Last Post: 12 December 2011 - 03:27 PM Rate Topic: -----

#1 ashub  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 01-December 11

how to use dll files in VB?

Posted 01 December 2011 - 07:00 AM

Hey Buddies, I want to connect a finger print scanner with my VB6 project.
I've got few .dll files with the scanner but nothing more..
Can any body help me..?
Thanx in advance..
Is This A Good Question/Topic? 0
  • +

Replies To: how to use dll files in VB?

#2 Neku  Icon User is offline

  • D.I.C Regular

Reputation: 20
  • View blog
  • Posts: 268
  • Joined: 21-May 09

Re: how to use dll files in VB?

Posted 02 December 2011 - 03:31 PM

you need to declare them

there are to ways to do so:
when you press ctrl+T you access the compunent menu from there select the ActiveX or dll file you want.
just mark v in the check box near it and press ok.
if you need there's brows button to look for other dll/oxc files in other locations in this menu.
thats late binding if i remember the name correctly.. if its ActiveX control it will show on the left as object you draw like button, textbox and so on and from code window you write code for it.

you can also declare it in similare way this example:

Public Declare Function AccessCheck Lib "advapi32.dll" Alias "AccessCheck" (pSecurityDescriptor As SECURITY_DESCRIPTOR, ByVal ClientToken As Long, ByVal DesiredAccess As Long, GenericMapping As GENERIC_MAPPING, PrivilegeSet As PRIVILEGE_SET, PrivilegeSetLength As Long, GrantedAccess As Long, ByVal Status As Long) As Long



(just took a randome code from the API viewer xD)

both have advantage and disadvantage in terms of how much memory they take and how you write code for them.
please note:
if the dll/oxc is not installed well or at sometimes not in the folder of the program exe the program will crash when you try to run it.
so find a way to register your dll/oxc and keep a copy in exe folder.
Was This Post Helpful? 0
  • +
  • -

#3 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 300
  • View blog
  • Posts: 1,776
  • Joined: 26-March 09

Re: how to use dll files in VB?

Posted 03 December 2011 - 02:40 AM

Just to add to Neku's reply, you would need to know what methods/functions are exposed in the DLL.

In Neku's code snippet, the function AccessCheck is declared, along with it's required parameters.

Unfortunately, it's not just as easy as referencing the DLL and things will start to work, there will be quite a bit more work involved than that.

If you've got DLL's that came with the scanner, I would expect the manufacturer to also have some example code (assuming it wasn't shipped with it's own application for usage).

Can you tell us the make and model of the device you're trying to use...
Was This Post Helpful? 0
  • +
  • -

#4 ashub  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 01-December 11

Re: how to use dll files in VB?

Posted 04 December 2011 - 12:17 AM

It has two dll files namely
1)ftrScanAPI.dll
2)ScanAPIHelper.dll

the first one is from Futronic Scanner API Dynamic Link Library driver, and i have no idea about the second one.
Was This Post Helpful? 0
  • +
  • -

#5 ashub  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 01-December 11

Re: how to use dll files in VB?

Posted 04 December 2011 - 12:24 AM

I just want to know one thing- with the help of these dll files how will I scan the finger prints and show it in my project?
Was This Post Helpful? 0
  • +
  • -

#6 Neku  Icon User is offline

  • D.I.C Regular

Reputation: 20
  • View blog
  • Posts: 268
  • Joined: 21-May 09

Re: how to use dll files in VB?

Posted 04 December 2011 - 09:08 AM

if these files came with the scanner then they are used for the scanning proccess.
so you'll have to access their methods, subs and functions and see what they need and what data they give.
maybe they give a set of cords that could be used to draw the fingerprint on the screen or inside some other control.
Was This Post Helpful? 0
  • +
  • -

#7 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 300
  • View blog
  • Posts: 1,776
  • Joined: 26-March 09

Re: how to use dll files in VB?

Posted 04 December 2011 - 01:30 PM

Sorry to sound a bit harsh here, but googling your manufacturer gives the first hit as the SDK and worked examples. Take a look here!.

In future, at least take the time to search for something yourself and don't expect us to do it for you....it's not difficult.

If you can't be bothered to do the basics, then why should we?
Was This Post Helpful? 1
  • +
  • -

#8 ashub  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 01-December 11

Re: how to use dll files in VB?

Posted 05 December 2011 - 11:47 PM

View PostNeku, on 04 December 2011 - 09:08 AM, said:

if these files came with the scanner then they are used for the scanning proccess.
so you'll have to access their methods, subs and functions and see what they need and what data they give.
maybe they give a set of cords that could be used to draw the fingerprint on the screen or inside some other control.

thanx for the reply.
Considering all the replies, i have read the sdk files.
In it i found many functions and subs.
but now the question is how to attach that dll file with visual basic.
if i have to declare them then what is the method?
and after attachment of that dll how to access those subs or functions??

Also, the dll files are not registered one and we cannot even register them with regsvr32.exe
So attaching those dll files by using "Components" or "References" is not possible, as they need a registered dll files..

tried searching in google, queried in many forms but found no clue yet.
i hope the guru's here will sure help me out of this.. :)
Was This Post Helpful? 0
  • +
  • -

#9 Neku  Icon User is offline

  • D.I.C Regular

Reputation: 20
  • View blog
  • Posts: 268
  • Joined: 21-May 09

Re: how to use dll files in VB?

Posted 07 December 2011 - 11:58 AM

you'll need to declare them as in the second way i'v shown you.
you can do this since you now know what subs and functions you have inside the DLL.
i'll give example based on the snippet i gave

Public Declare Function AccessCheck Lib "advapi32.dll" Alias "AccessCheck" (pSecurityDescriptor As SECURITY_DESCRIPTOR, ByVal ClientToken As Long, ByVal DesiredAccess As Long, GenericMapping As GENERIC_MAPPING, PrivilegeSet As PRIVILEGE_SET, PrivilegeSetLength As Long, GrantedAccess As Long, ByVal Status As Long) As Long





as in this example: public is the scope of the declaration, in this case it mean that all loaded forms in memory can access this function.

if you use Private insted of Public only the loaded forms that have the code above can access the function.

Note: difference between functions and subs: a sub can get information via variables from caller but never give a result back (unless at the end it pop up a message for example if it was matematical calculation but then it still do it with either changing text in a control or msgbox)

a function get info with variables from caller and give back result.
whether or not {sorry if misspelling >.<} you need the result is up to you.
if you dont need dont equal a variable to the function and dont use the "(" ")"

a caller could be another sub or function.

in the example above after the Public Declare Function come the name of the function.
you could use any name you want but if its not found inside the DLL then it wont work or most likely crash.

the Lib "advapi32.dll" is the reference to the file and the file should always be in same folder as the EXE.

the Alias "AccessCheck" in the code above is the reference to the function inside the DLL, therefore i could have declared it this way if i wanted:

Public Declare Function ABC Lib "advapi32.dll" Alias "AccessCheck" (pSecurityDescriptor As SECURITY_DESCRIPTOR, ByVal ClientToken As Long, ByVal DesiredAccess As Long, GenericMapping As GENERIC_MAPPING, PrivilegeSet As PRIVILEGE_SET, PrivilegeSetLength As Long, GrantedAccess As Long, ByVal Status As Long) As Long



now anytime i call in the code to function named ABC the computer will understand that it mean AccessCheck inside the DLL file.

inside the () are all the values the function need and thier type.


because i'm nice i'll give you snippet how to call subs and functions :)

to call sub:


Call SubName() ' where SubName will be replaced with proper name and if needed there are values inside the ()




to call function:

'option A: calling and getting result

Variable = FunctionName(NeededValueOne As DataType, NeededValueTwo As DataType) As Datatype

'variable equal to function therefore get result from it.
'the function need 2 values that could be of any kind and give a result that too
'could be of any kind (even if its different from the type of needed values)




how it work:

lets say the needed values are integers and the result is string.

then:

Variable = FunctionName( 5,7) As String
'Note Variable in this case should be sring too to avoid errors that crash the program



in this case the function might combine the given integers so the result will be 57.


'Option B: calling without the need of result

FunctionName ValueA As DataType, ValueB As DataType




in this example function get 2 values but it dont need to be equal to variable to store result in it.
the function do whatever it needs too and if needed it will disply result alone (like in MsgBox).

in this example the values could be file names and the function may compare/delete/rename or do whatever in should with the file names.

hope this help and last tip, here's example to declare a sub that is inside DLL:


Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)


Was This Post Helpful? 0
  • +
  • -

#10 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 300
  • View blog
  • Posts: 1,776
  • Joined: 26-March 09

Re: how to use dll files in VB?

Posted 08 December 2011 - 01:16 AM

A good post by Neku on how to use DLL files above, but I'm slightly confused. If you've acquired and read the SDK as you say, then why didn't you look at the example programs???

Direct from the website:

Quote

Standard SDK package includes MS
Windows example programs with source
code to show how to use the SDK for the
following development platforms:
  • VB6 and VC6
  • Borland Delphi
  • VB.Net and VC.net
  • VB.2005 and VC.2005
  • JAVA

Was This Post Helpful? 0
  • +
  • -

#11 ashub  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 01-December 11

Re: how to use dll files in VB?

Posted 09 December 2011 - 11:02 PM

View PostNeku, on 07 December 2011 - 11:58 AM, said:

you'll need to declare them as in the second way i'v shown you.
you can do this since you now know what subs and functions you have inside the DLL.
i'll give example based on the snippet i gave

Public Declare Function AccessCheck Lib "advapi32.dll" Alias "AccessCheck" (pSecurityDescriptor As SECURITY_DESCRIPTOR, ByVal ClientToken As Long, ByVal DesiredAccess As Long, GenericMapping As GENERIC_MAPPING, PrivilegeSet As PRIVILEGE_SET, PrivilegeSetLength As Long, GrantedAccess As Long, ByVal Status As Long) As Long





as in this example: public is the scope of the declaration, in this case it mean that all loaded forms in memory can access this function.

if you use Private insted of Public only the loaded forms that have the code above can access the function.

Note: difference between functions and subs: a sub can get information via variables from caller but never give a result back (unless at the end it pop up a message for example if it was matematical calculation but then it still do it with either changing text in a control or msgbox)

a function get info with variables from caller and give back result.
whether or not {sorry if misspelling >.<} you need the result is up to you.
if you dont need dont equal a variable to the function and dont use the "(" ")"

a caller could be another sub or function.

in the example above after the Public Declare Function come the name of the function.
you could use any name you want but if its not found inside the DLL then it wont work or most likely crash.

the Lib "advapi32.dll" is the reference to the file and the file should always be in same folder as the EXE.

the Alias "AccessCheck" in the code above is the reference to the function inside the DLL, therefore i could have declared it this way if i wanted:

Public Declare Function ABC Lib "advapi32.dll" Alias "AccessCheck" (pSecurityDescriptor As SECURITY_DESCRIPTOR, ByVal ClientToken As Long, ByVal DesiredAccess As Long, GenericMapping As GENERIC_MAPPING, PrivilegeSet As PRIVILEGE_SET, PrivilegeSetLength As Long, GrantedAccess As Long, ByVal Status As Long) As Long



now anytime i call in the code to function named ABC the computer will understand that it mean AccessCheck inside the DLL file.

inside the () are all the values the function need and thier type.


because i'm nice i'll give you snippet how to call subs and functions :)

to call sub:


Call SubName() ' where SubName will be replaced with proper name and if needed there are values inside the ()




to call function:

'option A: calling and getting result

Variable = FunctionName(NeededValueOne As DataType, NeededValueTwo As DataType) As Datatype

'variable equal to function therefore get result from it.
'the function need 2 values that could be of any kind and give a result that too
'could be of any kind (even if its different from the type of needed values)




how it work:

lets say the needed values are integers and the result is string.

then:

Variable = FunctionName( 5,7) As String
'Note Variable in this case should be sring too to avoid errors that crash the program



in this case the function might combine the given integers so the result will be 57.


'Option B: calling without the need of result

FunctionName ValueA As DataType, ValueB As DataType




in this example function get 2 values but it dont need to be equal to variable to store result in it.
the function do whatever it needs too and if needed it will disply result alone (like in MsgBox).

in this example the values could be file names and the function may compare/delete/rename or do whatever in should with the file names.

hope this help and last tip, here's example to declare a sub that is inside DLL:


Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)




Thanx a ton for this explanation.. :) :)
Was This Post Helpful? 0
  • +
  • -

#12 ashub  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 01-December 11

Re: how to use dll files in VB?

Posted 09 December 2011 - 11:08 PM

View Postmaj3091, on 08 December 2011 - 01:16 AM, said:

A good post by Neku on how to use DLL files above, but I'm slightly confused. If you've acquired and read the SDK as you say, then why didn't you look at the example programs???

Direct from the website:

Quote

Standard SDK package includes MS
Windows example programs with source
code to show how to use the SDK for the
following development platforms:
  • VB6 and VC6
  • Borland Delphi
  • VB.Net and VC.net
  • VB.2005 and VC.2005
  • JAVA



Well I guess, I just missed that..
Sorry for that..
And thanx for the help.. :) :)

This post has been edited by ashub: 09 December 2011 - 11:20 PM

Was This Post Helpful? 0
  • +
  • -

#13 ashub  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 01-December 11

Re: how to use dll files in VB?

Posted 11 December 2011 - 11:45 PM

View Postmaj3091, on 04 December 2011 - 01:30 PM, said:

Sorry to sound a bit harsh here, but googling your manufacturer gives the first hit as the SDK and worked examples. Take a look here!.

In future, at least take the time to search for something yourself and don't expect us to do it for you....it's not difficult.

If you can't be bothered to do the basics, then why should we?


The link which you gave in your reply, contains only a program and not its source code.
If you find its source code kindly post a link.
well i'm sorry if i'm asking for the basics, but i'm a new bee in VB.
Though I'm referring many sites and forums but i guess this one is the most responsive and active among them.. :)
And thanx for your giving me your precious time on this matter..

This post has been edited by ashub: 11 December 2011 - 11:46 PM

Was This Post Helpful? 0
  • +
  • -

#14 Neku  Icon User is offline

  • D.I.C Regular

Reputation: 20
  • View blog
  • Posts: 268
  • Joined: 21-May 09

Re: how to use dll files in VB?

Posted 12 December 2011 - 06:09 AM

uumm i just found out a small problem with the function code and how it return the result.. hold on while i fix it >_<"
Was This Post Helpful? 0
  • +
  • -

#15 Neku  Icon User is offline

  • D.I.C Regular

Reputation: 20
  • View blog
  • Posts: 268
  • Joined: 21-May 09

Re: how to use dll files in VB?

Posted 12 December 2011 - 06:32 AM

ok i fix it.

in most programming language when you write a function you need to use the word return and value after it in order to get the result from the function.
but in VB if you write a function and you want to get result from it ( when doing Variable=Function(val1, val2) As Datatype ) you need to write the function name inside the function and make it equal the result.

example:

Private Function sum (a As Integer, b As Integer)
sum= a+b
End Function




now about ByVal and ByRef:


ByVal mean that when you call a sub or function only a copy of the value inside the variables is passed.
if there's any change to it the variables will get their original value upon exiting the sub/function. ByVal recommanded for input values.

ByRef mean that the memory address of the variable is passed, therefor any change will change the variable, it could make problems if the variable shouldent change.
ByRef recommanded for output values.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2