I have this code in Visual Basic 6.0 which reads a card, runs fine on both Win XP and higher versions.
WinScard.dll It already comes with the operating system, it is not an external library.
//////////////////////////////////////////////////////////
Code: Select all
Private Declare Function SCardEstablishContext Lib "WinScard.dll" ( _
ByVal dwScope As Long, ByVal pvReserved1 As Long, _
ByVal pvReserved2 As Long, ByRef phContext As Long) As Long
Private Declare Function SCardListReaders Lib "WinScard.dll" Alias "SCardListReadersA" ( _
ByVal hContext As Long, ByVal mzGroup As String, _
ByVal ReaderList As String, ByRef pcchReaders As Long ) As Long
Private Sub Form_Load()
Form1.AutoRedraw = True
Dim mszGroups As String
Dim szReaderLists As String * 256
Dim bConversion As Boolean
Dim lResult As Long
Dim hContext As Long
Dim nReaderCount As Long
Const SCARD_SCOPE_USER = 0
Const SCARD_S_SUCCESS = 0
bConversion = False
lResult = SCardEstablishContext(SCARD_SCOPE_USER, 0, 0, hContext)
If lResult <> SCARD_S_SUCCESS Then
Form1.Print "Cannot establish connection"
Form1.Print "ReturnCode(ESTACON): " + Hex(lResult)
End If
nReaderCount = 255
lResult = SCardListReaders(hContext, mszGroups, szReaderLists, nReaderCount)
Form1.Print "szReaderLists = " & szReaderLists
Form1.Print "nReaderCount = " & nReaderCount
Form1.Print "timeGetTime = " & timeGetTime
Form1.Refresh
End Sub
Now my idea is to do it in FreeBasic, with which the code looks like this, but it gives me an error .....
//////////////////////////////////////////////////////////
Code: Select all
#include "windows.bi"
extern "windows"
Declare Function SCardEstablishContext Lib "WinScard.dll" ( _
ByVal dwScope As Long, ByVal pvReserved1 As Long, ByVal pvReserved2 As Long, ByRef phContext As Long ) As Long
end extern
extern "windows"
Declare Function SCardListReaders Lib "WinScard.dll" Alias "SCardListReadersA" ( _
ByVal hContext As Long, ByVal mzGroup As String, ByVal ReaderList As String, ByRef pcchReaders As Long) As Long
end Extern
Dim mszGroups As String
Dim szReaderLists As String * 256
dim bConversion As Boolean
dim lResult As Long
dim hContext As Long
dim nReaderCount As Long
Const SCARD_SCOPE_USER = 0
Const SCARD_S_SUCCESS = 0
bConversion = False
lResult = SCardEstablishContext(SCARD_SCOPE_USER, 0, 0, hContext) <------ this line works fine
If lResult <> SCARD_S_SUCCESS Then
print "Cannot establish connection"
print "ReturnCode(ESTACON): " + Hex(lResult)
End If
nReaderCount = 255
lResult = SCardListReaders(hContext, mszGroups, szReaderLists, nReaderCount) <------ in this line I have the error
print "szReaderLists = " & szReaderLists
print "nReaderCount = " & nReaderCount
sleep
I am compiling with FreeBasic 1.0.9.0 - Windows 32 bits
The error that the IDE FBIDE gives me is the following...
//////////////////////////////////////////////////////////
Command executed:
"D:\Programacion\FreeBasic_1090\fbc.exe" "D:\Programacion\Proyectos\FreeBasicNFC\FBIDETEMP.bas"
Compiler output:
D:\Programacion\FreeBasic_1090\bin\win32\ld.exe: D:\Programacion\Proyectos\FreeBasicNFC\FBIDETEMP.o:fake:(.text+0x138): undefined reference to `SCardListReadersA@32'
Results:
Compilation failed
System:
FBIde: 0.4.6
fbc: FreeBASIC Compiler - Version 1.09.0 (2021-12-31), built for win32 (32bit)
OS: Windows XP (build 2600, Service Pack 3)
//////////////////////////////////////////////////////////
Seeing that it only gave me an error in SCardListReaders, I realized that in the VB6 code it is as Alias
........ Private Declare Function SCardListReaders Lib "WinScard.dll" Alias "SCardListReadersA" (........
So in this function declaration in VB6, I removed the Alias
........ Private Declare Function SCardListReaders Lib "WinScard.dll" (........
And when executing in VB6, it also gave me an error with a MsgBox, just like in Freebasic
Cannot find entry point DLL SCardListReaders in WinScard.dll
//////////////////////////////////////////////////////////
So in FreeBasic, I put the Alias the same as in VB6, but it keeps giving me the error, I've read that maybe it's because of the linker,
or because maybe I should call the DLL in another way.
The strange thing is that there is a function that works well and the other does not, being the 2 of the same Dll.
I have also seen that freebasic has the libraries.
FreeBasic_1090\inc\win\winscard.bi
and
FreeBasic_1090\lib\win32\libwinscard.dll.a
but I don't know how to use them, since there are no examples.
I hope you can help me, since I have been trying to solve this for 2 days, but there is no way.
Thank you very much and greetings to all !!!