The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: normcook on May 26, 2009, 01:34:57 PM

Title: Create String Array in Masm DLL
Post by: normcook on May 26, 2009, 01:34:57 PM
This post is about mixed programming, specifically an ASM DLL to
be used in VB6.  The DLL will return an array of filepaths, given
a starting path.  I'm OK with the DLL format and the use of
FindFirstFile/FindNextFile to enumerate the files.  My problem
is how to fill the passed array.

In VB, I envision the declare as
Private Declare Function EnumFiles Lib "FileList.dll" (ByRef FileArr() As String, ByRef ReturnCount As Long)
   where FileArr is undimmed.

In Masm,

EnumFiles proc ArrPtr:DWORD, RetCnt:DWORD
endp

I suspect that for each found filepath, I will need
to SysAlloc... or SafeArrayCreate, but not sure
how to fill an array.

Any thoughts?
Title: Re: Create String Array in Masm DLL
Post by: hutch-- on May 26, 2009, 02:07:19 PM
Norm,

There are a couple of ways to do it, allocate a big enough buiffer in VB then pass its address OR as you mentioned use a string allocation function like one of the SysAlloc() functions in the DLL, write what you want to it and pass the handle of the string back to VB. With the second option you will need to make sure you can deallocate the string when its no longer needed.
Title: Re: Create String Array in Masm DLL
Post by: Mark Jones on May 26, 2009, 03:11:19 PM
Just a semantical note, there is no such thing as a "String Array" in assembler. All data (code included) boils down to bytes and addresses, and blocks of data become an "array" in interpretation only. Sorry if this seems pedantic but the distinction can be important in understanding.

I seem to recall some older posts here about MASM+VB, try the search box at the top-left. "MASM VB" turned up 7 pages of results, perhaps someone has already covered this.
Title: Re: Create String Array in Masm DLL
Post by: Vortex on May 26, 2009, 05:01:54 PM
Hi normcook,

You need to take in account also that assembly strings are generally NULL terminated and VB strings have a predefined length byte.