Hi all :)

I had searched the board but cannot find the answer for this.
I'm trying to make a DLL that will be call from my program (HLL).
The program will pass in an array by refference.



.Data
cMsg db 'length of ta_Reff[0] = %lu',13,10,
'Value of ta_Reff[0] = %s',0
.Data?
cBuffer db 64 dup (?)

.Code

GetArray Proc Uses ESI ta_Reff:DWORD
Local ln_Len:DWord

mov esi, ta_Reff
invoke lstrlen, esi
mov ln_Len, eax

invoke wsprintf, Addr cBuffer, Addr cMsg, ln_Len, esi
invoke MessageBox, 0, Addr cBuffer, 0, 0

ret
GetArray EndP


From my program I tested the code with array of string
cArr[0] = "Test 1"
cArr[1] = "Test 2"
cArr[2] = "Test 3"
cArr[3] = "so on"

The question is:
1. How can I get the value from cArr[1] and next array
2. From the example there are 4 members of cArr. How can I check that.

I tried all methods that I know, but could not get it! I'm really lost now.:confused:

Thanks.
Posted on 2002-12-29 23:07:12 by HermanT
Try indexing it like this

GetArray Proc Uses ESI ta_Reff:DWORD

Local ln_Len:DWord

mov esi, ta_Reff
mov esi, [esi + 4 * 0] ; index 0
invoke lstrlen, esi
mov ln_Len, eax

invoke wsprintf, Addr cBuffer, Addr cMsg, ln_Len, esi
invoke MessageBox, 0, Addr cBuffer, 0, 0

mov esi, ta_Reff
mov esi, [esi + 4 * 1] ; index 1
invoke lstrlen, esi
mov ln_Len, eax

invoke wsprintf, Addr cBuffer, Addr cMsg, ln_Len, esi
invoke MessageBox, 0, Addr cBuffer, 0, 0

ret
GetArray EndP
There is no way to tell how many members there are in the array. One thing you could do is make the last member null, and when your code sees that esi is null u know you have run out of strings.
Posted on 2002-12-30 03:55:37 by BubbaFate
Thanks for the reply BubbaFate :)

I already did that and it didn't work. So to make sure that I was not make any mistake before, I tried again using your code (cut & paste). Well.. it doesn't work either :( it giving me an error "DLL call caused an exception" under W2K. For WinME there is no error but it display a blank MessageBox

As I mentioned before, I tried different method. But all I can get is the first member of the array.
This is the code for all methods I used

cArr[0] = "Test 1"
cArr[1] = "Test 2"
so on..



GetArray Proc Uses ESI EBX ta_Reff:DWORD
Local ln_Len:DWord, lc_Asc[4], lc_Asc2[4]
Local lc_Hex1[4], lc_Hex2[4], lc_Hex3[4], lc_Hex0[4], lc_Hex4[4], lc_Hex5[4]

.Data
cMsg db 'lea esi, ta_Reff = %s',13,10,
'lodsd -> into eax = %s',13,10,
'DW2Char of eax = %s',13,10,
'mov ebx, ta_Reff = %s',13,10,
'mov ebx, [ebx] = %s',13,10,
'mov ebx, [esp-8] = %s',13,10,
'length of ta_Reff = %lu',13,10,
'Value of ta_Reff = %s',13,10,
'DWord of [ta_Reff] = %s',13,10,
'DW2Char of [ta_Reff] = %s',0
.Data?
cBuffer db 128 dup (?)

.Code
invoke lstrlen, ta_Reff
mov ln_Len, eax ; ln_Len = 6

lea esi, ta_Reff
invoke dw2hex, esi, Addr lc_Hex1 ; esi = 0012F490 (dynamic)

lodsd
mov ebx, [eax]
invoke dw2hex, ebx, Addr lc_Hex5 ; ebx = 74736554
invoke DW2Char, ebx, Addr lc_Asc2 ; ebx = t s e T = Test

mov ebx, ta_Reff
invoke dw2hex, ebx, Addr lc_Hex2 ; ebx = 01E36CA8 (dynamic)

mov ebx, [ebx]
invoke dw2hex, ebx, Addr lc_Hex0 ; ebx = 74736554

mov ebx, [esp-8]
invoke dw2hex, ebx, Addr lc_Hex4 ; ebx = 74736554

mov ebx, ta_Reff
mov ebx, [ebx]
invoke dw2hex, ebx, Addr lc_Hex3 ; ebx = 74736554
invoke DW2Char, ebx, Addr lc_Asc ; ebx = t s e T = Test

mov ebx, ta_Reff ; Value of ta_Reff = "Test 1"

invoke wsprintf, Addr cBuffer, Addr cMsg,
Addr lc_Hex1, Addr lc_Hex5, Addr lc_Asc2, Addr lc_Hex2,
Addr lc_Hex0, Addr lc_Hex4,
ln_Len, ebx, Addr lc_Hex3, Addr lc_Asc

invoke MessageBox, 0, Addr cBuffer, 0, 0
ret
GetArray EndP


Anymore idea ??

Thanks again :alright:
Posted on 2002-12-30 07:54:03 by HermanT
are you sure that you are passing the structure to the dll correctly? when you say that you can only get the first string, that sounds to me like your passing by value... what hll are you using ? Vb? maybe u could post the call part of that code. Best thing to do is just to step right into the dll with a debugger and see what the stack is lookin like
Posted on 2002-12-30 13:35:44 by BubbaFate
D**n, I really forget about this. This hll actually pass an array by value. It only can pass by reff into a COM. And it also using one base array not zero base.

But what confusing is when I try to pass in by reff (the hll uses symbol "@" to pass in by reff) after it return from the dll, all the string of the array changed into the first string. Like this

before after
--------------------------------------------------
cArr[1] = 'Test 1' cArr[1] = 'Test 1'
cArr[2] = 'Test 2' cArr[2] = 'Test 1'
cArr[3] = 'ljkshdf' cArr[3] = 'Test 1'

OK then, last one how can I use debugger to step into the dll. What debugger can I use for this ?
BTW I'm using VFP

Thanks BubbaFate :alright:
Posted on 2002-12-30 21:25:13 by HermanT
D**n, I really forget about this. This hll actually pass an array by value. It only can pass by reff into a COM object. And it also using one base array not zero base.

But what confusing is when I try to pass in by reff (the hll uses symbol "@" to pass in by reff) after it return from the dll, all the string of the array changed into the first string. Like this

before after
--------------------------------------------------
cArr[1] = 'Test 1' cArr[1] = 'Test 1'
cArr[2] = 'Test 2' cArr[2] = 'Test 1'
cArr[3] = 'ljkshdf' cArr[3] = 'Test 1'

OK then, last one how can I use debugger to step into the dll. What debugger can I use for this ?
BTW I'm using VFP

Thanks BubbaFate :alright:
Posted on 2002-12-30 21:27:46 by HermanT
you should be able to use any debugger that allows you to step through code... just hit the "step into" button when u get to the function call and u should be transferred to an assembly dump of your dll
Posted on 2002-12-31 05:36:41 by BubbaFate
Oopsss....
Why did I posted twice. How come ? :grin: :o

Well.. Thank you for being with me :alright:
I'll give it a try

Regards
Posted on 2002-12-31 09:56:16 by HermanT