hey, can anybody help me, as to how to create an array
it needs to work with winsock, where there are multiple connections, and every time there's a new connection ( under FD_ACCEPT ), it needs to create/access it's specific index within the array, depending on the connection handle ( stored in wParam ) , then when data is received i need to access the array again by only knowing the socket handle which is in wParam
the array needs to be a string, about 128 long, to store a filename

so basically, how do you create an array that can be accessed at anytime, and can create new indexes at anytime

P.S. i've searched here for some help, but most stuff i found is too complictaed for me :confused:
Posted on 2004-02-10 05:03:26 by someone
Hi someone, first off you should always use MAX_PATH (260) for filename buffers, it is the maximum allowable path+filename size in Windows. If you were just to create an array of elements all the same size it would be mostly empty space. You might think about doing it a little more efficiently.

First allocate a buffer large enough to hold all of the elements, you can expand this if you need to:
; This will allocate 1MB of memory for paths

invoke VirtualAlloc, NULL, 100000h, MEM_COMMIT, PAGE_READWRITE
mov [pPathArray],eax
mov [ArrayPointer],eax

As you can see I moved the base address into both the pointer and the index, the pointer is fixed and used to release the memory later, the index starts at the bottom of the array.

Next every time you add a string you will have to copy it to the array then move the pointer to the next starting position. This is best done in a proc:
AddPath proc pPathString:DWORD


invoke lstrcpy, [ArrayPointer],[pPathString]
push eax ; save the address that it starts at
invoke lstrlen,[pPathString]
inc eax ; NULL terminator
add [ArrayPointer],eax ; move the pointer to the start of the next string
pop eax ; pop the start of the string that was just added and return it
ret
AddPath endp

Then every time you call AddPath it will add the path to the array and return a pointer to that string. If you want you can store these pointers in the lParam or create another array of DWORDs to store the pointers to the strings. If you elect to make another array, you store the pointers then when you want string 0 you get element 0 and it will contain the offset of the string in memory.

Pretty simple method but it works very well.

If you need more space later you call VirtualAlloc with the addess of the array + the size:

; This will allocate another 1MB of memory for paths

mov eax,[pPathArray]
add eax,100000h ; the top of the old array, we will append to that
invoke VirtualAlloc, eax , 100000h, MEM_COMMIT, PAGE_READWRITE


When your done be sure to free the array:

; 100000h = total size you have to increase this if you have added any new space

invoke VirtualFree,[pPathArray],100000h,MEM_RELEASE
Posted on 2004-02-10 07:13:35 by donkey

Hi someone, first off you should always use MAX_PATH (260) for filename buffers, it is the maximum allowable path+filename size in Windows. If you were just to create an array of elements all the same size it would be mostly empty space. You might think about doing it a little more efficiently.



It was allways bugging me 260 MAX_PATH is windows trait or file system ??
Posted on 2004-02-10 07:27:49 by AceEmbler
Well, since Windows doesn't care what IFS you are running it is a Windows imposed limitation and not one imposed by the file system. But since Windows is your only means of accessing the IFS it amounts to the same thing.
Posted on 2004-02-10 07:33:42 by donkey
hi,
thanks, it worked, and i understand arrays now.
i'm still havin trouble though, with getting the winsock connections to find out which index of the array it has, i want it to store in somewhere like lParam like you said, but lParam has the socket window messages (e.g. FD_CONNECT, FD_ACCEPT, etc.), unless i've got it wrong ? how would that be done anyway.

also it's only the filename (not the filepath) thats stored in the string, so i only made it 128, but i'll make it bigger

thanks for your help, it's much appreciated
Posted on 2004-02-10 08:03:39 by someone
I am not an expert, but I was using Donkey's Array Routines and having a problem with the FreeArray code.

I am only posting this here incase someone else wants to use this coding example.

The problem



; 100000h = total size you have to increase this if you have added any new space
invoke VirtualFree,[pPathArray], [COLOR=BLUE]100000h[/COLOR] ,[COLOR=RED]MEM_RELEASE [/COLOR]


I was receiving a 57h error = parameter is incorrect.

Here is why.

MEM_RELEASE
Releases the specified region of reserved pages. If this flag is specified, the dwSize parameter must be zero, or the function fails.

When the MEM_RELEASE flag is used then the Blue size parm MUST be 0h.


I changed it and now no error!

No offense to Donkey is intended.

StillLearning
Posted on 2004-06-12 23:42:16 by StillLearning
Yup that's right, I had made a mistake in the first post, I corrected it somewhere else on the board, can't remember where though. I did not come back to this thread so I never noticed the error. I had typed it on the fly and copy and pasted it from one place to another, further multiplying the error. But rest assured that I don't do that in my applications.

I am not so arrogant that I can't admit a mistake so obviously no offense could possibly be taken ;)
Posted on 2004-06-13 00:59:34 by donkey