Hey, i have tested with some code and i cannot see what you say...
maybe is the version of the dbp you're ussing? i mean an old version bug? some mnemonic / instruction you have ussed? I have the latest dbp with the latest update 5.6, maybe is it
I have atahced a zip with my code, three test functions.
That takes an string parameter, and return the same string with an extra internal dll defined string atached.
Other functon that take two passed strings parameters and return these string joined, and last function, a simple example with a message box that does not return any value; this is good to see how db passes the parameters when the function does not return any param and how act when the function have params....
Here is the code to review...
format PE GUI 4.0 DLL
entry DLL_MAIN
include '%fasminc%win32a.inc'
; -----------------------------------------------------------
; THESE ARE SOME MACROS TO ADD STRING TO RESOURCES
; YOU NEED IT! UNCOMENT IT IF YOU DONT HAVE IT IN THE RESOURCE.INC FILE
; ALSO, YOU CAN ADD IT TO THE RESOURCE.INC FILE IN MACRO FOLDERS
; TO REUSE IT :)
; -----------------------------------------------------------
;NEXT_STRING = 1
;END_STRING_TABLE = 0
;macro stringtable label
; {
; local data,size
; label dd RVA data,size,0,0
; data dw ?
; string_size equ size = $ - data
; }
;macro stritem string,action
; {
; local size
; virtual at 0
; db string
; size=$
; end virtual
; dw size
; du string
; if action = END_STRING_TABLE
; string_size
; end if
; }
; -----------------------------------------------------------
; CODE START
; -----------------------------------------------------------
section '.code' code readable executable
; -----------------------------------------------------------
; DLL MAIN PROC
; -----------------------------------------------------------
proc DLL_MAIN, hinstDLL,fdwReason,lpvReserved
mov eax,TRUE
return
endp
; -----------------------------------------------------------
; FUNCTION Return String$. Take an string as parameter and return
; another String
; -----------------------------------------------------------
proc ReturnStr,strParam
enter
mov esi,[strParam+4] ;obtaining the real pointer (the real string parameter position in the stack)
mov edi,varStrBuffer ;coping the address of the var
.loop:
lodsb ;load the first char (pointed by esi) to the al register, after loaded in al, automaticly esi points to the next char
cmp al,0 ;testing if the string contain nothing
je .next ;if is 0, then jump to the next to add the "TEST!" text.
mov [edi],al ;if not 0, then add the char in al to the varstr buffer
inc edi ; incrementing to the next byte memory posibion to save the next char
jmp .loop ;jumping to loop to repit the sequence until the char 0 (end of the string) is found
.next:
mov esi,varTestText ;pointing esi to the address off varTestText to start adding TEST! string
.loopb:
lodsb ;load the first char (pointed by esi) to the al register, after loaded in al, automaticly esi points to the next char
cmp al,0 ;testing if the string contain nothing
je .end ;if is 0, then jump to the nex to add the "TEST!" text.
mov [edi],al ;if not 0, then add the char in al to the varstr buffer
inc edi ; incrementing to the next byte memory posibion to save the next char
jmp .loopb ;jumping to loop to repit the sequence until the char 0 (end of the string) is found
.end:
mov al,0 ;Loading 0 on al
mov [edi],al ;Adding one extra byte at the end of the string "zero" :)
mov eax,varStrBuffer ;Returning the address of the variable to dbp
return ;Returning to DBP
endp
; -----------------------------------------------------------
; FUNCTION Join Strings$. Take two string as parameter and return
; both joined
; -----------------------------------------------------------
proc JoinStr,strParamA,strParamB
enter
mov esi,[strParamA+4] ;obtaining the real pointer (the real string parameter position in the stack) for strParamA
mov edi,varStrBuffer ;coping the address of the var
.loop:
lodsb ;load the first char (pointed by esi) to the al register, after loaded in al, automaticly esi points to the next char
cmp al,0 ;testing if the string contain nothing
je .next ;if is 0, then jump to the next to add the "TEST!" text.
mov [edi],al ;if not 0, then add the char in al to the varstr buffer
inc edi ; incrementing to the next byte memory posibion to save the next char
jmp .loop ;jumping to loop to repit the sequence until the char 0 (end of the string) is found
.next:
mov esi,[strParamB+4] ;obtaining the real pointer (the real string parameter position in the stack) for strParamB
.loopb:
lodsb ;load the first char (pointed by esi) to the al register, after loaded in al, automaticly esi points to the next char
cmp al,0 ;testing if the string contain nothing
je .end ;if is 0, then jump to the nex to add the "TEST!" text.
mov [edi],al ;if not 0, then add the char in al to the varstr buffer
inc edi ; incrementing to the next byte memory posibion to save the next char
jmp .loopb ;jumping to loop to repit the sequence until the char 0 (end of the string) is found
.end:
mov al,0 ;Loading 0 on al
mov [edi],al ;Adding one extra byte at the end of the string "zero" :)
mov eax,varStrBuffer ;Returning the address of the variable to dbp
return ;Returning to DBP
endp
; -----------------------------------------------------------
; FUNCTION Show Message$. Take one string as parameter and
; show a message box :)
; -----------------------------------------------------------
proc ShowMsg,strMessage
enter
mov eax,[strMessage] ;notice here is no needed add 4 to the address
invoke MessageBox,HWND_DESKTOP,eax,msgTitle,MB_OK
return
endp
; -----------------------------------------------------------
; DATA SECTION
; -----------------------------------------------------------
section '.data' data readable writable
varTestText db ' TEST!',0
msgTitle db 'StringAsm Dll Message!',0
varStrBuffer rb 2048 ;
; -----------------------------------------------------------
; IMPORTED API DATA
; -----------------------------------------------------------
section '.idata' import data readable
library user32,'USER32.DLL'
import user32,
MessageBox,'MessageBoxA'
; -----------------------------------------------------------
; DLL EXPORTED DATA
; -----------------------------------------------------------
section '.edata' export data readable
export 'STRINGASM.DLL',
ReturnStr,'ReturnStr',
JoinStr,'JoinStr',
ShowMsg,'ShowMsg'
section '.reloc' fixups data discardable
; -----------------------------------------------------------
; STRING RESOURCES
; -----------------------------------------------------------
section '.rsrc' resource data readable
directory RT_STRING,str1
resource str1,1,LANG_ENGLISH+SUBLANG_DEFAULT,str_table
stringtable str_table
stritem "RETURN STRING$[%SS%ReturnStr",NEXT_STRING
stritem "JOIN STRING$[%SSS%JoinStr",NEXT_STRING
stritem "SHOW MESSAGE$%S%ShowMsg",END_STRING_TABLE
In the dbp side, this is the test code...
Print Return String$("This is a..") `Testing Function ONE
Print Join String$("Hello ","World!") `Testing Function Two
Show Message$ "Message From DBP!" `Testing Function Three
Wait Key
Even, i have added to the zip, the compiled dll and the example dbp code is added too.
http://www.zonauy.com/darkbasic/darkbasic_stringtests.zip
Cheers and thanks.
Roberto A. Berrospe Machin, Zona Servicios.