Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
call function that pass string from RapidQ
#11
Quote:They return the pointer to string's data, i dunno what you mean by "string contents".

Code:
dim p as byte ptr
  s$ = "abc"
  p = strptr( s$ )

  for i = 1 to len( s$ )
    print chr$(*p);
    p += 1
  next i

In your example s$ string len is known because it's static. While in the above DLL mode, it's only receiving pointer to the string without know len. It may called dynamics string pointer received by FB DLL.

For example if in this situation where unkown string length received by a function in Rapid-Q, Varptr$ keyword can be used to retrieve it's lenght and fill the calling variable with the string. I dunno what is behind that keyword, probably it recognized the string lenght with chr$(0) delimeter.

What I'm trying to find is the keyword that does similar with Rapid-Q VarPtr$. If I use sadd() and strptr(), the print routine only show the string address not the string itself. If I use Byte ptr, how do I know the string lenght from an adrress?

Sterling Christensen, it does not matter if the string is placed in an array of byte like in C, the important point for coder is to find the point of strings arrays end. If array, how to fetch the ubound() of the array. I think this is problem for diakin getting the DLL work with Rapid-Q. It is because the DLL routine is not completed due to in-proper string management to allow it being printed to screen with the exact string lenght or as a whole.

If we know the string lenght from give string address, the above byte ptr loop can be used to transfer string value to a variable$.
Reply
#12
Oh!.. Yeh! Big Grin

It's working now!
'---- dll code ------

Code:
declare function teststr  lib "mydll4"  alias "teststr"     ( byval ptr_tstr as byte ptr) as integer
'$include: 'DllMain.bi'

'***********************************************'
function teststr    (  byval ptr_tstr as byte ptr) as integer  export  
   print "ptr_tstr=" ;ptr_tstr
   dim sss as string
   sss = *ptr_tstr
   print "in dll sss=" ;sss
   teststr= len(sss)
end function

'---- rq code ----------
Code:
declare function teststr  lib "mydll4" alias "teststr@4" (   tstr1 as long ) as integer
dim zzz as long
aa$="aaaasddf"
print "aa$=" ;aa$
zzz=varptr(aa$)
print "teststr=" ;teststr ( (zzz))

Nice! Thank you!

Some more questions:

1. RapidQ works good with API Dll
For example:
'---- rq code ----------
Code:
Declare Function DeleteFile Lib "kernel32" Alias "DeleteFileA" (ByVal lpFileName As String) As Long

call DeleteFile ("dummy.decoy")

It works without ptr using.
Is FB dll differents from Windows API dll?
Or it use ptr too, but just it is transparently for user?
Is "ByVal lpFileName As String" in VB the same as
"byval ptr_tstr as byte ptr" inFB?

Oh! Sorry!
Yes, it's the same
This RQ code works also good!
'---- rq code ----------
Code:
declare function teststr  lib "mydll4" alias "teststr@4" (   tstr1 as string ) as integer

aa$="aaaasddf"
print "aa$=" ;aa$
print "teststr=" ;teststr ( (aa$))
'--------- RQ Docs-----------------
Unlike some implementations which force you to pass your STRING as a pointer, Rapid-Q will do all this for you, so you need not worry. Whenever you see LPZSTR as a parameter, that just means Long Pointer Zero-Terminated String. You can safely pass any string variable
'--------------------------------------

2. ".. ptr_tstr as byte ptr"
Why "as byte" ???
Really ptr is long, isn't it?[/code]
ith best regards, Andrew Shelkovenko.
http://www.wildgardenseed.com/RQDP/FreeBasic/index.html - FreeBasic documentation Project
Reply
#13
Next problem.. :-?

I need to return string value from dll.
Code:
declare function teststr  lib "mydll4"  alias "teststr"     ( byval ptr_tstr as byte ptr) as byte ptr
'$include: 'DllMain.bi'

'*********************'
function teststr    (  byval ptr_tstr as byte ptr) as byte ptr export  

dim sss as string
sss = *ptr_tstr
print "in dll sss=" ;sss
sss=sss+"bzzzz"
print "in dll sss=" ;sss
teststr= varptr(sss)

end function

---- RQ side -------
Code:
declare function teststr  lib "mydll4" alias "teststr@4" (   tstr1 as string ) as long

defint rqptr
aa$="12"
print "aa$=" ;aa$

rqptr=varptr (aa$)
print "RQ varptr=";rqptr

zz=teststr ( (aa$))
print "teststr=" ; zz
print "----------"

'heh pointer in RQ :-(
DIM Mem AS QMemoryStream
defint bb
' copy 7 bytes from address zz
Mem.MemCopyFrom (zz, 7)
Mem.Position = 0
bb$=space$(7)
Mem.read (bb$)
print "bb$=" ;(bb$)

result is
aa$=12
RQ varptr=26947924
in dll sss=12
in dll sss=12bzzzz
teststr=16248784
----------
bb$=-Ёў $@

How I can return string from dll function ?

(I test Mem.MemCopyFrom (rqptr, 2) - it's working good )
ith best regards, Andrew Shelkovenko.
http://www.wildgardenseed.com/RQDP/FreeBasic/index.html - FreeBasic documentation Project
Reply
#14
Sorry again :oops:

I need use
---
teststr= sadd(sss)

not
teststr= varptr(sss)

It works fine.

Thanks!
ith best regards, Andrew Shelkovenko.
http://www.wildgardenseed.com/RQDP/FreeBasic/index.html - FreeBasic documentation Project
Reply
#15
Quote:Sterling Christensen, it does not matter if the string is placed in an array of byte like in C, the important point for coder is to find the point of strings arrays end. If array, how to fetch the ubound() of the array.
FreeBASIC strings are null-terminated, just like C strings. So just search for a CHR$(0).
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)