after great efforts i tried to write this code,but i want to convert the proc of getfiledir in a way that it stores the result in array of strings and return that string array
i don't know how to declare that array equiv char **arr or char *arr in win32 asm
i just only know declaration of array string only(LOCAL arr:BYTE).
as i post my vb code in http://www.asmcommunity.net/board/index.php?topic=25297.0 section that was
locked as due to lack of efforts by me shown.but i try hard for 2-3 days and create this code.

plz help me for making a proc that stores result in array of strings.
i thing then i have 2 return that array address(right????)
as in this code i thing i have to use dynamic array but i don't know to declare and make.
plz guide me...
plz don't lock this topic this time,plz suggest views in dynamoc array of strings usage and declaration

.386
.model flat,stdcall
option casemap:none

GetFileDir Proto lpszPath:DWORD

include windows.inc
include user32.inc
includelib user32.lib
include kernel32.inc
includelib kernel32.lib

.data
  szMsgText db "invalid file handle",0
  szMsgCap  db "Message",0
  szPath db "C:\\*.*",0
.code

start:
      invoke GetFileDir,addr szPath
      invoke ExitProcess,NULL

GetFileDir Proc lpszPath:DWORD
    LOCAL hFile:HANDLE
    LOCAL wfd:WIN32_FIND_DATA
   
    invoke FindFirstFile,lpszPath,addr wfd
    mov hFile,eax
   
    .if(hFile==INVALID_HANDLE_VALUE)
        invoke MessageBox,NULL,addr szMsgText,addr szMsgCap,MB_OK
    .endif
   
    .while eax
            invoke FindNextFile,hFile,addr wfd
        .if (wfd.dwFileAttributes==FILE_ATTRIBUTE_DIRECTORY)
            invoke MessageBox,NULL,addr wfd.cFileName,addr szMsgCap,MB_OK
        .endif 
    .endw
   
    invoke CloseHandle,hFile
Ret
GetFileDir EndP


end start
Posted on 2006-09-04 12:39:03 by sihotaamarpal
Using compilers and high level languages exclusively, such as VB, leaves you without the actual knowledge of how to program.

Think of VB as a baker. You (the customer) stop by this baker's shop (VB) and tell him what you want made, this requires very little to no "real" knowledge on your behalf. It is the baker's job to understand the ingredients and baking instructions, and give you the end-result.

Think of ASM as baking it yourself. You have to posses intimate knowledge of the ingredients (instructions) and how they achieve the end-result (the program)... otherwise, with the lack of quality, you'd be out of business quickly (unless you bully every other baker out of the city and everyone is forced to come to you).

To relate, VB knows what an array is and how to utilize memory to "make" the array. VB keeps track of the array size and how it is accessed in order to do error/bounds checking. VB does EVERYTHING for you short of expressing your own desires.

On the other hand, ASM requires you to allocate a section of memory and you apply whatever concept is needed to that section of memory. In this case, you wish to apply the concept of an "array" to a fixed chunk of memory. This requires you to create the logic that accesses this portion of memory in the manner you desire (your "array"). You are also required to exercise size/error/bounds checking yourself.

You have to read some more and start digging deeper, because after two years you are *still* thinking like "the customer" and not "the baker".

To help you on your way, I will give you some advice on how to make an array from fixed chunk of memory. First, you need to decide what length your array is going to be (more complex concepts involve resizing, but let's stick to the basics), and allocate that amount of memory. Second, you need to decide how your array is going to be segmented. If we are talking a fixed amount of data, say an array of 4 byte values... then you have very little to worry about. For such an array, you just need to increment the memory pointer on a scale of 4 bytes.


;Basic concept of "long MyArray[16]" - NASM Style Syntax
mov ebx,DWORD MyArray ;Address of "MyArray" in memory, ebx becomes the pointer
mov eax,DWORD ;Access the first 4-byte value (long MyArray[0])
add ebx,4 ;Move the array pointer to the next 4-byte value
mov eax,DWORD ;Access the second 4-byte value (long MyArray[1])
mov eax,DWORD; Access the third 4-byte value (long MyArray[2])


As you can see from the above code, there is more than one way to access memory using pointers. You could also "scale" in order to directly access a single value. Things like that, and variable-sized arrays (which would require a "linked-list"), are pushing into more intermediate assembly language topics. I can tell you that your "array of strings" concept is much more complex than VB allows you to realize, and it will require a linked-list of arrays if you plan on doing anything equivalent in Assembly Language.

So, even something this simple in VB might be too complex for someone still learning basic Assembly Language concepts. For someone in your position, sihotaamarpal, I might suggest that you start thoroughly learning C programming concepts before trying to drop straight into ASM... it would help you greatly coming from a VB background.

People only tend to help you here, if you help yourself... so please start doing so.
Posted on 2006-09-04 22:57:32 by SpooK
thks spook,now i tried myself of translation of link -list of c in asm
Posted on 2006-09-05 00:38:50 by sihotaamarpal
You don't actually need a linked list unless you wish for the array to be resizable. If you know you won't have any more than, for example 256 strings in your array, then you could allocate a (256*4) section of memory. Then for each string, allocate enough room for a string then store the address to that section of memory into your 256*4 chunk. This is an "Array of Arrays" and is actually fiarly easy to do. Check out the sample code below. I've not done any actual work for you, this just kinda shows what you might want to try and do (point you in the right direction) because I too think you should possibly try a little harder.

MALLOC	MACRO	Size:REQ
INVOKE HeapAlloc, process_heap, HEAP_ZERO_MEMORY, Size
ENDM

FREE MACRO pMem:REQ
INVOKE HeapFree, process_heap, 0, pMem
ENDM

.data
process_heap DWORD 0

.code
InitArray PROC
INVOKE GetProcessHeap
mov process_heap, EAX
MALLOC ( 256 * 4 ) ; 256 string pointers
ret
InitArray ENDP

ClearArray PROC pArray:DWORD
FREE pArray
ret
ClearArray ENDP

....

; Pointer to our strings
LOCAL pStrings:DWORD
LOCAL dIndex:DWORD
....
INVOKE InitArray
mov pStrings, EAX

...
; storing a string into the array
INVOKE lstrlen, ADDR wfd.cFileName
inc EAX
MALLOC EAX
mov EDI, pStrings
mov ECX, dIndex
mov , EAX
INVOKE lstrcpy, EAX, ADDR wfd.cFileName
inc dIndex
...
; somewhere down the line you need to cleanup all your strings
; then you can clean up the array which contains the addresses
; of the strings
INVOKE ClearArray, pStrings
...


You will also need to preform bounds checking, (ie make sure you haven't inserted too many pointers into the array). That's the plus side to using Linked Lists instead of the above method, because you allocate room for each entry as you insert them. That way you can add as many entries as memory allows.

In the future, please try to put forth more effort like SpooK said. You have grown a bit of a habbit over the last two years of trying to get spoon fed source code (ie "I have this, translate it for me") and it really doesn't seem like you are trying much yourself. This issue, I don't mind so much because I hear novices complain about arrays all the time, but it would probably have done some good to search the board. IIRC there is even a macro set somewhere on the board (I think it was designed by Biterider) to make it easier, because it was such an issue.

Regards,
Bryant Keller
Posted on 2006-09-05 01:01:50 by Synfire
Thanks for clearing that up Synfire. I was trying to give sihotaamarpal the most basic of arrays... one that really doesn't even qualify as an array in these high-level terms (technically my example would just be a fixed-length/size structure). Too much OS development gets to my head :P

He does indeed need to know that arrays are (typically) linear lists of pointers to other objects in memory. So, ultimately, sihotaamarpal... I think you should study how Structures are held in memory (i.e. my example from above). Once you understand the basics of how to create/manipulate a Structure, you can move into studying Arrays. You will soon realize that the actual Array itself is just a structure of memory pointers that reference other objects in memory. In the end, you will learn that Structures and Arrays are just ways to efficiently organize and sort large amounts of data in a uniform manner.

Good luck ;)
Posted on 2006-09-05 01:46:09 by SpooK
thks Synfire  :) and Spook  8) too also
Posted on 2006-09-06 05:39:28 by sihotaamarpal