PlanetSquires Forums

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: lstrcpy syntax?  (Read 594 times)

jermy

  • FireFly3 User
  • Little Newbie FireFly
  • *
  • Posts: 15
lstrcpy syntax?
« on: June 23, 2017, 11:20:19 AM »

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' ?

Code: [Select]
' 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?
Logged

Josť Roca

  • FireFly3 Registered User
  • Master FireFly Member
  • *
  • Posts: 2785
    • Josť Roca Software
Re: lstrcpy syntax?
« Reply #1 on: June 23, 2017, 11:51:08 AM »

> 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.

Pierre Bellisle

  • FireFly3 User
  • Junior FireFly Member
  • *
  • Posts: 57
Re: lstrcpy syntax?
« Reply #2 on: June 23, 2017, 08:49:54 PM »

Hi Jermy,

I guess you think of something like this... Is that it?

Pierre

Code: [Select]
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)
Logged

jermy

  • FireFly3 User
  • Little Newbie FireFly
  • *
  • Posts: 15
Re: lstrcpy syntax?
« Reply #3 on: June 24, 2017, 06:52:17 AM »

lpszA = Long Pointer String z? ansi

Now i see it, its a ugly vb6 work around.

Code: [Select]
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
« Last Edit: June 24, 2017, 06:56:05 AM by jermy »
Logged

Pierre Bellisle

  • FireFly3 User
  • Junior FireFly Member
  • *
  • Posts: 57
Re: lstrcpy syntax?
« Reply #4 on: June 24, 2017, 04:29:57 PM »

Another way...

Pierre

Code: [Select]
'\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
'_____________________________________________________________________________
'
Logged

jermy

  • FireFly3 User
  • Little Newbie FireFly
  • *
  • Posts: 15
Re: lstrcpy syntax?
« Reply #5 on: June 30, 2017, 04:12:08 PM »

Thanks Pierre, It pointed me to the right direction  :)
Logged