News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Create String Array in Masm DLL

Started by normcook, May 26, 2009, 01:34:57 PM

Previous topic - Next topic

normcook

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?

hutch--

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.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Mark Jones

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.
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

Vortex

Hi normcook,

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