|
Prev: Bluetooth
Next: GetFileVersionInfoSize on PocketPC
From: Lookie on 2 Mar 2005 00:07 Hi i am building an application to read a PC/SC application in vb6. I am having problems with one of the functions SCardListReaders.Below is the C declaration of the SCardList Readers. LONG SCardListReaders( SCARDCONTEXT hContext, LPCTSTR mszGroups, LPTSTR mszReaders, LPDWORD pcchReaders ); pcchReaders [in, out] Length of the mszReaders buffer in characters. This parameter receives the actual length of the multi-string structure, including all trailing null characters. If the buffer length is specified as SCARD_AUTOALLOCATE, then mszReaders is converted to a pointer to a byte pointer, and receives the address of a block of memory containing the multi-string structure. This block of memory must be deallocated with SCardFreeMemory. My problem is with mszReaders. i have to use SCARD_AUTOALLOCATE for the last variable.if this happens, mszReaders changers to a pointer to a byte pointer. How can vb handle this?
From: Thorsten Albers on 2 Mar 2005 08:01 Lookie <Lookie(a)discussions.microsoft.com> schrieb im Beitrag <3E4EF32E-01A6-4337-8FC0-D44B5CA37FE7(a)microsoft.com>... > LONG SCardListReaders( > SCARDCONTEXT hContext, > LPCTSTR mszGroups, > LPTSTR mszReaders, > LPDWORD pcchReaders > ); > pcchReaders > [in, out] Length of the mszReaders buffer in characters. This parameter > receives the actual length of the multi-string structure, including all > trailing null characters. If the buffer length is specified as > SCARD_AUTOALLOCATE, then mszReaders is converted to a pointer to a byte > pointer, and receives the address of a block of memory containing the > multi-string structure. This block of memory must be deallocated with > SCardFreeMemory. This is, what I would assume from the description: Private Declare Sub CopyMemory _ Lib "kernel32" Alias "RtlMoveMemory" _ ( _ pDestination As Any, _ pSource As Any, _ ByVal lByteCount As Long _ ) Private Declare Function lstrlen _ Lib "kernel32" Alias "lstrlenA" _ ( _ pszString As Any _ ) As Long Private Declare Function SCardListReaders _ Lib "..." Alias "SCardListReadersA" _ ( _ ByVal hContext As Long, _ ByVal sGroups As String, _ pszReaders As Long, _ lChReaders As Long _ ) As Long .... Dim pszReaders As Long, lChReaders As Long If SCardListReaders(hContext, sGroups, pszReaders, lChReaders) Then While lChReaders > 0 lLen = lstrlen(ByVal pszReaders) If lLen Then sString = String$(lLen, vbNullChar) Call CopyMemory(ByVal sString, ByVal pszReaders, lLen) Else sString = vbNullString End If Debug.Print sString lChReaders = lChReaders - (lLen + 1) Wend End If
From: Mike D Sutton on 2 Mar 2005 09:22 > Hi i am building an application to read a PC/SC application in vb6. I am > having problems with one of the functions SCardListReaders.Below is the C > declaration of the SCardList Readers. > > LONG SCardListReaders( > SCARDCONTEXT hContext, > LPCTSTR mszGroups, > LPTSTR mszReaders, > LPDWORD pcchReaders > ); > > pcchReaders > [in, out] Length of the mszReaders buffer in characters. This parameter > receives the actual length of the multi-string structure, including all > trailing null characters. If the buffer length is specified as > SCARD_AUTOALLOCATE, then mszReaders is converted to a pointer to a byte > pointer, and receives the address of a block of memory containing the > multi-string structure. This block of memory must be deallocated with > SCardFreeMemory. > > My problem is with mszReaders. i have to use SCARD_AUTOALLOCATE for the last > variable.if this happens, mszReaders changers to a pointer to a byte pointer. > How can vb handle this? Due to the lack of detail specified a lot of assumptions have to be made about how the API works, however have a look at something like this perhaps: '*** Warning; air code.. Private Declare Function SCardListReaders Lib "YourLib.dll" ( _ ByVal hContext As Long, ByVal mszGroups As String, _ ByVal mszReaders As Long, ByRef pcchReaders As Long) As Long Private Declare Function SCardFreeMemory Lib "YourLib.dll" ( _ ByVal pBuffer As Long) As Long Private Declare Function lstrlen Lib "Kernel32.dll" Alias "lstrlenA" ( _ ByVal lpString As Long) As Long Private Declare Function lstrcpy Lib "Kernel32.dll" Alias "lstrcpyA" ( _ ByVal lpString1 As String, ByVal lpString2 As Long) As Long .... Dim hContext As Long Dim Groups As String Dim BufPtr As Long, BufLen As Long Dim Strings() As String, NumStrings As Long hContext = PopulateHandle() Groups = PopulateGroups() BufLen = SCARD_AUTOALLOCATE If (SCardListReaders(hContext, Groups, BufPtr, ByVal BufLen) Then NumStrings = MultiStringToStringArray(BufPtr, Strings()) Call SCardFreeMemory(BufPtr) End If .... Private Function MultiStringToStringArray(ByVal inPtr As Long, ByRef outString() As String) As Long Dim RetStrs() As String, NumRet As Long ' Converts a multi-string buffer to an array of strings Dim ThisString As String, StringLen As Long Dim CurPtr As Long CurPtr = inPtr Do StringLen = lstrlen(CurPtr) If (StringLen > 0) Then ThisString = Space$(StringLen) Call lstrcpy(ThisString, CurPtr) ReDim Preserve RetStrs(NumRet) As String RetStrs(NumRet) = ThisString NumRet = NumRet + 1 CurPtr = CurPtr + StringLen + 1 End If Loop While StringLen > 0 MultiStringToStringArray = NumRet outString() = RetStrs() End Function '*** Assumptions made are: * SCardFreeMemory() takes a single input which is the pointer to the allocated buffer * SCardListReaders() returns non-0 for success * When pcchReaders is set to SCARD_AUTOALLOCATE, is takes the value directly and not a pointer to this value (so buffer length can be overwritten.) - If it does explode then remove the "ByVal" from the SCardListReaders() call and see if that works any better. * A "multi-string structure" is simply a bunch of concatenated null-terminated strings terminated with a double null. * My code actually works.. ;) With all this, I would strongly recommend you save everything before running any of the above, if any of these are wrong then it's likely to explode ;) Hope this helps, Mike P.s. There's a Direct memory manipulation tutorial on my site which introduces working with memory in VB if you're interested. - Microsoft Visual Basic MVP - E-Mail: EDais(a)mvps.org WWW: Http://EDais.mvps.org/
From: Mike D Sutton on 2 Mar 2005 10:32 Ah, just found the documentation in the MSDN (didn't realise these were Win32 API call, assumed it was your own library..) Change the declare of SCardFreeMemory() (and also the "Lib" of the SCardListReaders() call) to this: '*** Private Declare Function SCardFreeMemory Lib "Winscard.dll" ( _ ByVal hContext As Long, ByRef pvMem As Any) As Long '*** And change the call in the code to: '*** Call SCardFreeMemory(hContext, ByVal BufPtr) '*** And change the SCardListReaders() call to: '*** Private Const SCARD_S_SUCCESS As Long = &H0 .... If (SCardListReaders(hContext, Groups, BufPtr, BufLen) = SCARD_S_SUCCESS) Then '*** Other than that, looks near enough.. Hope this helps, Mike - Microsoft Visual Basic MVP - E-Mail: EDais(a)mvps.org WWW: Http://EDais.mvps.org/
From: Chris Tacke, eMVP on 2 Mar 2005 10:52 There are other posts that attempt to answer the question, but really, you can't do programming for today's CE devices with VB6 - not since CE 2.0 at the latest. -- Chris Tacke Co-founder OpenNETCF.org Has OpenNETCF helped you? Consider donating to support us! http://www.opennetcf.org/donate "Lookie" <Lookie(a)discussions.microsoft.com> wrote in message news:3E4EF32E-01A6-4337-8FC0-D44B5CA37FE7(a)microsoft.com... > Hi i am building an application to read a PC/SC application in vb6. I am > having problems with one of the functions SCardListReaders.Below is the C > declaration of the SCardList Readers. > > LONG SCardListReaders( > SCARDCONTEXT hContext, > LPCTSTR mszGroups, > LPTSTR mszReaders, > LPDWORD pcchReaders > ); > > pcchReaders > [in, out] Length of the mszReaders buffer in characters. This parameter > receives the actual length of the multi-string structure, including all > trailing null characters. If the buffer length is specified as > SCARD_AUTOALLOCATE, then mszReaders is converted to a pointer to a byte > pointer, and receives the address of a block of memory containing the > multi-string structure. This block of memory must be deallocated with > SCardFreeMemory. > > > My problem is with mszReaders. i have to use SCARD_AUTOALLOCATE for the > last > variable.if this happens, mszReaders changers to a pointer to a byte > pointer. > How can vb handle this? > > >
|
Pages: 1 Prev: Bluetooth Next: GetFileVersionInfoSize on PocketPC |