Hi asm programmers. Long time lurker, first time poster. I am primarily a VB user but have recently started dabbling with MASM32 & find it fascinating. I am working on a DLL to be called from VB which will speed up some string manipulations. I have written one Proc which accesses a string I pass & it works fine. (After some trial & error & a lot of GPF's)

Now I want to pass a String Array to the DLL & have it return a Long (DWORD). The declare will look something like:

Private Declare Function ArrayOps lib "MyDLL.dll" (StringArray() As String) As Long

Then in the DLL:

ArrayOps proc Array:DWORD
;lots of brilliant code
ArrayOps endp

My thought was to set ebx to the start of the array. I've tried several approaches,
lea esi,Array mov ebx,
mov esi,Array mov ebx,
lea ebx,Array
mov ebx,Array
etc

Any thoughts?

By the way, I've been testing my routines with this:
invoke MessageBox, NULL,ebx, addr MsgCaption, MB_OK

Thanks all.
Posted on 2002-07-13 07:23:53 by NormCook
If you search this board, you will find several posts from me regarding using VB strings in asm dlls.

I have never messed with passing an array of strings though. But, i can still see that you are going to have problems with your approach....
- internally, VB arrays are actually structs, with a member of that struct pointing to the actual array, so what you asm dll will be getting is a pointer to a struct (because you are passing ByRef). This struct is not documented by MS, but it is documented in a few third party VB websites.
- the strings will be stored in your array as BSTRs. Usually when you pass a string ByVal, it gets converted to an ANSI null terminated string, however because you are passing an array, the strings will not get converted

So, there is a lot of overhead to do it the way you are. I would advise two things:

- use fixed length strings, it will make your task considerably easier
- place your strings inside a byte array, then pass the first element of the byte array ByRef, so your declare and code will look like this:

[size=12]

Private Declare Function ArrayOps lib "MyDLL.dll" (ByVal byteArray As Long) As Long

blah = ArrayOps(ByRef byteArray(0))
[/size]


this will pass a pointer to the first element of your byte array (just like you do in C/C++).


One last point: in your code suggestions, you had this:


lea esi, Array

'Array' is a local variable, so it is setup inside a stack frame. 'lea' means Load Effective Address. As you are passing a pointer to Array, then you are loading a pointer to the Array variable, you end up with a pointer to a pointer to your array in esi......
Posted on 2002-07-13 09:05:38 by sluggy