News:

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

Problems with creating a Struct in MASM32.

Started by Shooter, February 15, 2011, 09:08:59 PM

Previous topic - Next topic

fearless

Might be needs addr like:

INVOKE GetIpAddrTable, Addr pIpAddrTable,Addr pdwSize, bOrder
ƒearless

Shooter

Quote from: fearless on February 19, 2011, 04:05:41 PM
Might be needs addr like:

INVOKE GetIpAddrTable, Addr pIpAddrTable,Addr pdwSize, bOrder

Addr on the first param assembles fine, but yields an exception when ran. I haven't tried it on the second one yet.
Never use direct references to anything ever. Bury everything in
macros. Bury the macros in include files. Reference those include
files indirectly from other include files. Use macros to reference
those include files.

dedndave

your structure defintion is out of the ballpark, i think
http://msdn.microsoft.com/en-us/library/aa366847%28v=vs.85%29.aspx

it is a nested structure - you will also need to look at MIB_IPADDRROW
http://msdn.microsoft.com/en-us/library/aa366845%28v=vs.85%29.aspx

fearless is right also - the first 2 parms are pointers

Shooter

Quote from: dedndave on February 19, 2011, 04:11:27 PM
your structure defintion is out of the ballpark, i think
http://msdn.microsoft.com/en-us/library/aa366847%28v=vs.85%29.aspx

it is a nested structure - you will also need to look at MIB_IPADDRROW
http://msdn.microsoft.com/en-us/library/aa366845%28v=vs.85%29.aspx

fearless is right also - the first 2 parms are pointers

Wouldn't these be part of the included files?
Never use direct references to anything ever. Bury everything in
macros. Bury the macros in include files. Reference those include
files indirectly from other include files. Use macros to reference
those include files.

dedndave

i don't find them in the includes

here is an example by Farabi...
http://www.masm32.com/board/index.php?topic=15028.msg121757#msg121757

usually, if something is missing in the inc files, you can use the forum search tool to find info   :P

Shooter

Quote from: dedndave on February 19, 2011, 04:21:55 PM
i don't find them in the includes

here is an example by Farabi...
http://www.masm32.com/board/index.php?topic=15028.msg121757#msg121757

usually, if something is missing in the inc files, you can use the forum search tool to find info   :P

OK, I see how Farabi created not one, but three structs that appear to be what I need, but either I'm blind or they aren't there... he didn't seem to use them in his post.
Never use direct references to anything ever. Bury everything in
macros. Bury the macros in include files. Reference those include
files indirectly from other include files. Use macros to reference
those include files.

dedndave

_MIB_IPADDRTABLE struct
dwAddr DW 0
dwIndex DW 0
dwMask DW 0
dwBCastAddr DW 0
dwReasmSize DW 0
unused1 DB 0
wType DW 0
_MIB_IPADDRTABLE ends


a problem here is that you have defined the structure as initialized
then, in the uninitialized data section...
pIpAddrTable    _MIB_IPADDRTABLE <?>
it spits out an error

replace the 0's with ?'s
_MIB_IPADDRTABLE struct
dwAddr DW ?
dwIndex DW ?
dwMask DW ?
dwBCastAddr DW ?
dwReasmSize DW ?
unused1 DB ?
wType DW ?
_MIB_IPADDRTABLE ends


usually, structures are defined as initialized only when they are your own invention - not msdn stuff

Shooter

Quote from: dedndave on February 19, 2011, 04:45:20 PM
a problem here is that you have defined the structure as initialized
then, in the uninitialized data section...

Alright... tried that, but still crashes, and no matter what, I'm still getting that 'warning' about the BSS segment. How, or rather, where should I be putting this code? I noticed in Farabi's code he didn't have .data, .data?, or .code.
Never use direct references to anything ever. Bury everything in
macros. Bury the macros in include files. Reference those include
files indirectly from other include files. Use macros to reference
those include files.

fearless

I usually put my structures under the .const section and before any .data stuff. Then i put the data structure variables in .data and any other uninitialized data vars in .data?

I would probably arrange it all like this:


.CONST
_MIB_IPADDRTABLE STRUCT
dwAddr DW 0
dwIndex DW 0
dwMask DW 0
dwBCastAddr DW 0
dwReasmSize DW 0
unused1 DB 0
wType DW 0
_MIB_IPADDRTABLE ENDS


.DATA
pIpAddrTable    _MIB_IPADDRTABLE <>


.DATA?
pdwSize DW ?
bOrder DW ?


.CODE
INVOKE GetIpAddrTable, Addr pIpAddrTable, Addr pdwSize, TRUE ; instead of using bOrder var just set it



Edit: after looking at pdwSize - needs to be set before call to function to specifies the size in bytes of the buffer pointed to by the pIpAddrTable parameter. which is a MIB_IPADDRTABLE Structure (http://msdn.microsoft.com/en-us/library/aa366847%28v=vs.85%29.aspx). The one defined and your using is also required, but is called MIB_IPADDRROW Structure (http://msdn.microsoft.com/en-us/library/aa366845%28v=vs.85%29.aspx)

typedef struct _MIB_IPADDRTABLE {
  DWORD         dwNumEntries;
  MIB_IPADDRROW table[ANY_SIZE];
} MIB_IPADDRTABLE, *PMIB_IPADDRTABLE;

typedef struct _MIB_IPADDRROW {
  DWORD          dwAddr;
  DWORD          dwIndex;
  DWORD          dwMask;
  DWORD          dwBCastAddr;
  DWORD          dwReasmSize;
  unsigned short unused1;
  unsigned short wType;
} MIB_IPADDRROW, *PMIB_IPADDRROW;


tbh it looks a bit messy. The community comment on the page has this which is just lol:
QuoteI came across this poor excuse for a structure and immediately had to call over a fellow developer to point how absurd it looked. To seriously consider, in production code, making a two member struct where one member simply gives the number of elements of the other and then use the worst macro name I have ever come across, "ANY_SIZE, is lunacy. Only a vast amount of bumbling chicanery could have made such a simple concept so confusing to the first glance.
ƒearless

Shooter

Never use direct references to anything ever. Bury everything in
macros. Bury the macros in include files. Reference those include
files indirectly from other include files. Use macros to reference
those include files.

dedndave

.CONST
_MIB_IPADDRTABLE STRUCT
dwAddr DW 0
dwIndex DW 0
dwMask DW 0
dwBCastAddr DW 0
dwReasmSize DW 0
unused1 DB 0
wType DW 0
_MIB_IPADDRTABLE ENDS

.DATA
pIpAddrTable    _MIB_IPADDRTABLE <>


when you define a structure type, it does not need to be in a section
placing it a section generates data - in the code fearless posted - twice   :bg
you are merely describing the data type

Shooter

So, back to what Fearless was saying about pdwSize, how is it known how big to make it?
Never use direct references to anything ever. Bury everything in
macros. Bury the macros in include files. Reference those include
files indirectly from other include files. Use macros to reference
those include files.

dedndave

from what i can see.....

you set the dwSize dword to 0
call the function - it should fail with ERROR_INSUFFICIENT_BUFFER
but - it will fill the dwSize value with the number of bytes required in the buffer
then - allocate space (HeapAlloc or something) for that buffer
set the pointer
set the size it's set for you
make the call again

it's similar to reading a registry value for which you do not know the size

dedndave

i dunno how to test it without DHCP   :P
i mean - i can dump the results and all
i just can't see how it would look if i were on a DNS domain

i cheated - lol
without using any structures....
        INCLUDE    \masm32\include\masm32rt.inc
        INCLUDE    \masm32\include\ws2_32.inc
        INCLUDE    \masm32\include\iphlpapi.inc

        INCLUDELIB \masm32\lib\ws2_32.lib
        INCLUDELIB \masm32\lib\iphlpapi.lib

_MIB_IPADDRROW STRUCT
  dwAddr       dd ?
  dwIndex      dd ?
  dwMask       dd ?
  dwBCastAddr  dd ?
  dwReasmSize  dd ?
  unused1      dd ?
  wType        dd ?
_MIB_IPADDRROW ENDS

_MIB_IPADDRTABLE STRUCT
  dwNumEntries dd ?
  table        dd ?
_MIB_IPADDRTABLE ENDS

        .DATA

IPdwSize dd 0

        .DATA?

BigAssBuffer db 8192 dup(?)

        .CODE

_main   PROC

;call it once to get the required buffer size

        INVOKE  GetIpAddrTable,offset BigAssBuffer,offset IPdwSize,0

;call it again to fill the buffer

        INVOKE  GetIpAddrTable,offset BigAssBuffer,offset IPdwSize,0

        mov     edx,offset BigAssBuffer
        mov     ecx,128

loop00: push    ecx
        push    edx
        mov     eax,[edx]
        print   uhex$(eax),32
        pop     edx
        pop     ecx
        add     edx,4
        loop    loop00

        print   chr$(13,10)
        inkey
        exit

_main   ENDP

        END     _main

Shooter

Dave,
Do you know of any reason why adding this line:
include masm32rt.inc
blocks windows.inc from loading? I received the error:
QuoteE:\Program Files\RadASM\masm32\Include\masm32rt.inc(38) : fatal error A1000: cannot open file : \masm32\include\windows.inc
But, if I comment out the 'masm32rt.inc', it assembles just fine.

-Shooter
Never use direct references to anything ever. Bury everything in
macros. Bury the macros in include files. Reference those include
files indirectly from other include files. Use macros to reference
those include files.