hi,
I want to define an array of a structure at design time here is code below, but i have some problems with it the .NameSize value will always be 255d i think so i need to be able to get the size of .Name somehow...but i dont want to have to manually insert the sizes of all the strings must be a simpler way.ya so i dont the struc is correct as it is....any help would be good maybe theres an easy way or something im not sure:(



struc Api
{
.Name:times 255d db ?
.NameSize = $ -.Name
}
struct Api

section '.data' code readable
TheApi db 'GetModuleHandleA',0

section '.data?' code readable writeable
ApiNames Api


thanks
Posted on 2003-02-17 05:01:13 by keyoke
I don't understand what exactly do you want to achieve. Could you give some more details?
Posted on 2003-02-17 07:05:16 by Tomasz Grysztar
i want to be able to define an array of strings with their lengths saved with them so i dont have to calculate it at runtime.
ok i found this example of a struc which saves the length of the string in the fasm help docs so.



struc API [Name]
{
common
label .Name byte
db Name
.Size = $ - .Name
.Thunk dd ?
}


but now i want to be able to create an array which i would normally define as



ApiNames db 'GetModuleHandle',0
db 'MessageBoxA',0
db 'Beep',0


i thought it would be defined like this



ApiNames API 'GetModuleHandle',
API 'MessageBoxA',
API 'Beep'


but this isnt the case
Posted on 2003-02-17 10:21:51 by keyoke
That macro dosn't save the size of structure in data section, it only defines a compile-time constant. You should rather look at the "strtbl" macro earlier in docs, which solves a similar problem.
I'm still not sure what exactly do you want. If you want to store size of API name in the dword before the actual name, you can use this macro:


struc API Name
{
.Length dd .Size
.Name db Name
.Size = $ - .Name
}

and then use it like:


first API "GetModuleHandle"
second API "MessageBoxA"

but you need to provide separate label for each name in this case. You can allow to store more names with single macro this way:


struc API [Name]
{
local Size,Data
dd Size
Data db Name
Size = $ - Data
}

APINames API "GetModuleHandle",\
"MessageBoxA",\
"Beep"

Now the structure consists of dwords containing sizes of names followed by names. You will need to read N from first dword and skip N+4 bytes to get address of the second name, etc. So maybe you'd rather want to store sizes in separate array and the addresses of string among with them:


struc API [Name]
{
forward
local Size,Data
dd Size,Data
common
dd 0
forward
dd Size
Data db Name
Size = $ - Data
}

This macro should be used in the same way as previous, but will create the different structure: the array of 8-byte fields containing sizes and addresses of strings, then dword 0 to mark end of array and then the strings' data addressed by the fields of that structure.
Posted on 2003-02-17 11:42:35 by Tomasz Grysztar
Thanks Privalov,
this last macro is perfect
:grin:
Posted on 2003-02-17 23:37:13 by keyoke