Hello,
I'm translating a program from vb6 to freebasic, I'm stuck with this piece of code.
the compiler telles me 'Argument count mismatch' ?
' Declare Function lstrcpyA Lib "kernel32" (ByVal RetVal As String, ByVal Potr As Long) As Long 'vb6 syntax
Function GetString(ByVal lpszA as Long) as String
' GetString = String$(lstrlenA(ByVal lpszA), 0) 'vb6 syntax
GetString = String$(Len(lpszA), 0)
' Call lstrcpyA(ByVal GetString, ByVal lpszA) 'vb6 syntax
lstrcpy(ByVal GetString, ByVal Cast(String, lpszA))
End Function
What am I doing wrong?
> What am I doing wrong?
Everything, beginning with trying to use a VB syntax with FB.
Can we know what are you passing in the lpszA parameter? Maybe a pointer to a null terminated string? I strongly doubt that with FB you will need to use lstrcpy to simply copy a string.
Hi Jermy,
I guess you think of something like this... Is that it?
Pierre
Function GetString(ByVal lpSZA as LPTSTR) as String 'Convert a ZSTRING to a Dynamic string
'One way... Dim As String sGetString = String$(lstrlenA(Cast(LPTSTR ,lpSZA)), 0) 'Build a big enough dynamic string
'One way... Dim As LPTSTR pString = StrPtr(sGetString) 'Get the pointer of the dynamic string
'One way... lStrCpyA(pString, Cast(LPTSTR, lpSZA)) 'Copy the ZSTRING to the dynamic string
'One way... FUNCTION = *pString 'Set the dynamic string content to the function
FUNCTION = *lpSZA 'Set the dynamic string content to the function
End Function
Dim As ZString * 50 zs = "123"
? GetString(@zs)
lpszA = Long Pointer String z? ansi
Now i see it, its a ugly vb6 work around.
Declare Function lstrlenA Lib "kernel32" (ByVal lpString as Long) as Long ''' Determines the length of the specified string (not including the terminating null character)
Declare Function inet_ntoa Lib "wsock32.dll" (ByVal addr as Long) as Long ''' The inet_ntoa function converts an (Ipv4) Internet network address into an ASCII string in Internet standard dotted-decimal format.
' If no error occurs, inet_ntoa returns a character pointer to a static buffer containing the text address in standard ".'' notation. Otherwise, it returns NULL.
Function GetInetAddrStr(Address as Long) as String
GetInetAddrStr = GetString(inet_ntoa(Address))
End Function
Function GetString(ByVal lpszA as Long) as String
' GetString = String$(lstrlenA(ByVal lpszA), 0) 'vb6 syntax
' GetString = String$(Len(lpszA), 0)
' Call lstrcpyA(ByVal GetString, ByVal lpszA) 'vb6 syntax
' lstrcpyA(ByVal GetString, ByVal Cast(String, lpszA))
End Function
most vb6 programs i can copy and paste to freebasic, this one got some ugly work around, its better to start all over again. ;D
Another way...
Pierre
'\64\fbc.exe -s console -w pedantic
#Lang "fb"
#Define Unicode
#Include once "windows.bi"
#Include once "win\winsock2.bi"
'_____________________________________________________________________________
Function GetString(ByVal lpSZA as zString Pointer) as String 'Convert a ZSTRING to a Dynamic string
'One way... Dim As String sGetString = String$(lstrlenA(Cast(LPTSTR ,lpSZA)), 0) 'Build a big enought dynamic string
'One way... Dim As LPTSTR pString = StrPtr(sGetString) 'Get the pointer of the dynamic string
'One way... lStrCpyA(pString, Cast(LPTSTR, lpSZA)) 'Copy the ZSTRING to the dynamic string
'One way... FUNCTION = *pString 'Set the dynamic string content to the function
FUNCTION = *lpSZA 'Set the dynamic string content to the function
End Function
'_____________________________________________________________________________
Function GetInetAddrStr01(ByVal Address as DWORD) as String 'Pointer
Dim inAddr As in_addr
inAddr.S_addr = Address
Function = GetString(inet_ntoa(inAddr))
End Function
'_____________________________________________________________________________
Function GetInetAddrStr02(ByVal Address as DWORD) as String
Dim inAddr As in_addr
inAddr.S_addr = Address
Function = *inet_ntoa(inAddr)
End Function
'_____________________________________________________________________________
Print GetInetAddrStr01(&h04030201)
Print GetInetAddrStr02(&h01020304)
Print
Print "Press a key or click to end" : Dim buttons As Long
Do : GetMouse(0, 0, 0, Buttons) : IF buttons Or Len(InKey) Then Exit Do : End If : Sleep 200 : Loop
'_____________________________________________________________________________
'
Thanks Pierre, It pointed me to the right direction :)