Hello everybody, I am still learning assembly, I wish to write an assembly dll for use with vb. I am stuck on how to pass an array of string from vb. My code is as follows:
asmStringByRef proc lpString:DWORD,lpRetByRef:PTR DWORD
;;; copy byte by byte from lpString to array b, worked ok
;local b[15]:byte
;mov esi,lpString
;lea eax,b
;mov edi,eax
;@label:
;mov al,
;inc esi
;mov , al
;inc edi
;cmp al,0
;jne @label
;invoke MessageBox,NULL,lpString,addr AppName,MB_OK ; need to fix ths line when lpString is LPSTR
;;; Following works byte by byte, even if param 2 is dword/LPSTR
;;; Fails if param 1 is of type LPSTR
mov esi, dword ptr ; also works if dword ptr [] removed
mov edi, dword ptr
@label:
mov al,
inc esi
mov byte ptr ,al
inc edi
cmp al,0
jne @label
Ret
asmStringByRef EndP
This proc doesnt work if I pass something like this in vb:
Private Declare Sub asmStringByRef Lib "C:\asmICLogix.dll" (ByVal sByVal As String, sByRef As String)
Private Sub Form_Load()
Dim s(0 To 6) As String
Dim y As String
Dim i As Long
For i = 0 To 6
s(i) = "abcdef" & i '& String(249, vbNullChar)
Next i
For i = 0 To 1 ' not supported
asmStringByRef s(0), y ' this works
MsgBox "y: " & y
Next i
End Sub
Please help me. Thanks a lot.
asmStringByRef proc lpString:DWORD,lpRetByRef:PTR DWORD
;;; copy byte by byte from lpString to array b, worked ok
;local b[15]:byte
;mov esi,lpString
;lea eax,b
;mov edi,eax
;@label:
;mov al,
;inc esi
;mov , al
;inc edi
;cmp al,0
;jne @label
;invoke MessageBox,NULL,lpString,addr AppName,MB_OK ; need to fix ths line when lpString is LPSTR
;;; Following works byte by byte, even if param 2 is dword/LPSTR
;;; Fails if param 1 is of type LPSTR
mov esi, dword ptr ; also works if dword ptr [] removed
mov edi, dword ptr
@label:
mov al,
inc esi
mov byte ptr ,al
inc edi
cmp al,0
jne @label
Ret
asmStringByRef EndP
This proc doesnt work if I pass something like this in vb:
Private Declare Sub asmStringByRef Lib "C:\asmICLogix.dll" (ByVal sByVal As String, sByRef As String)
Private Sub Form_Load()
Dim s(0 To 6) As String
Dim y As String
Dim i As Long
For i = 0 To 6
s(i) = "abcdef" & i '& String(249, vbNullChar)
Next i
For i = 0 To 1 ' not supported
asmStringByRef s(0), y ' this works
MsgBox "y: " & y
Next i
End Sub
Please help me. Thanks a lot.
First, your ASM code requires that your second argument, b, points to a receiving data area (a buffer).
Second, VB will not provide such an area unless you give the variable a string big enough to hold all the data.
Third, the quirk of VB is that in order to send the pointer to the string data area to your ASM code, you must pass the string byVal. (If you think about it, that's why the code for the first argument would work.)
Second, VB will not provide such an area unless you give the variable a string big enough to hold all the data.
Third, the quirk of VB is that in order to send the pointer to the string data area to your ASM code, you must pass the string byVal. (If you think about it, that's why the code for the first argument would work.)