Function call in Classic Visual Basic |
'************************************************************************ '* Sample of a GeoDLL function call in Classic Visual Basic * '* for determining a returned string using its pointer. * '* * '* Attention: For VB.net the declarations differ from this example! * '* See example VB.net *' '* * '* Some functions of the 32-bit Dynamic Link Library GeoDLL return a * '* string as a reference to its pointer (pointer to the string in * '* memory). With the VB function GetStringFromPointer() the string can * '* be determined from the storage area using its pointer. The sample * '* can be included in the VB source code directly. * '* * '* The presented function only works with 32bit architecture. For 64bit * '* architecture, the API functions must be adapted. * '* * '* Authors: * '* Dipl.-Ing. Fred Killet, Killet GeoSoftware Ing.-GbR * '* Dipl.-Ing. Klaus-Jochen Sympher, Dr.-Ing. Pecher und Partner GmbH * '* Dieter Otter, Tools & Components, www.vbarchiv.net * '* * '* For the sample in the calling directory of GeoDLL the files * '* geodll32.dll and geodllbn.bin must be present. * '* * '* A lot of changes were accomplished. Unfortunately we did not have * '* the possibility to compile the sample. If there are any syntax bugs * '* in the source code, Mr. Killet asks for report! * '************************************************************************
'Declare required API functions for Classic Visual Basic Private Declare Function lstrcopy Lib "kernel32" _ Alias "lstrcpyA" ( _ ByVal lpString1 As String, _ ByVal lpString2 As Long) As Long
'Note: This different declaration for VB.net: 'Private Declare Function lstrcopy Lib "kernel32" _ ' Alias "lstrcpyA" ( _ ' ByVal lpString1 As String, _ ' ByVal lpString2 As Integer) As Integer
Private Declare Function lstrlen Lib "kernel32" _ Alias "lstrlenA" ( _ ByVal lpString As Long) As Long
'Read string from the memory by using its pointer and return it. Public Function GetStringFromPointer _ (ByVal lpStrPointer As Long) As String
Dim nLen As Long Dim sBuffer As String
'Length of the string nLen = lstrlen(lpStrPointer)
'Buffer with needed size sBuffer = Space$(nLen)
'Get string from the pointer address lstrcopy sBuffer, lpStrPointer If InStr(sBuffer, vbNullChar) > 0 Then sBuffer = Left$(sBuffer, InStr(sBuffer, vbNullChar) - 1) End If
'Return string GetStringFromPointer = sBuffer End Function
'Declare GeoDLL function Public Declare Function getdllversion Lib "GeoDLL32( _ ByRef lngVersion as Long) as Integer
'Here as an example, the string with the GeoDLL version number, 'returned from GeoDLL, is determined Sub meineAnwendungMitGeoDLL32()
Dim lngVersion as Long 'the pointer of the strings Dim strVersion as String 'the string it self
'GeoDLL writes the its version number as string to the memory 'and returns the string position as a pointer
rc = getdllversion(lngVersion)
'Find string using the pointer 'This follows for example "12.03 C++" strVersion = getStringFromPointer(lngVersion)
End sub
|