views:

48

answers:

4

Hi,

I have a list which contains a number of _MEMORY_BASIC_INFORMATION structs nested within mb structs (defs below). What I am having problems with is getting the info from the nested _MEMORY_BASIC_INFORMATION out. I am using an iterator to traverse the list. From below I know the error is g->mbi; but I don't know how I should reference the nested struct... Thanks.

Basically I am trying to write the base address from gMemList[i] to start = (DWORD)g.mbi.BaseAddress; but I am getting the error c2228: left of '.mbi' must have a class/struct/union.

list<struct mb *> gMemList

std::list<mb *>::iterator i = gMemList.begin();
while(i != gMemList.end())
{
    struct mb *g = *i;
    MEMORY_BASIC_INFORMATION mbi2 = g->mbi;
    start = (DWORD)mbi2.BaseAddress;
    buf = new wchar_t[255];
        while(start < mbi2.RegionSize)
    {...

//struct mb
//{
//  MEMORY_BASIC_INFORMATION mbi;
//  char *p;
//};

/*typedef struct _MEMORY_BASIC_INFORMATION {
PVOID BaseAddress;
PVOID AllocationBase;
DWORD AllocationProtect;
SIZE_T RegionSize;
DWORD State;
DWORD Protect;
DWORD Type;
} MEMORY_BASIC_INFORMATION, *PMEMORY_BASIC_INFORMATION;*/
A: 

Maybe this is what you are looking for:

while(start < (char*)(g->mbi.BaseAddress) + mbi2.RegionSize)
{
  ...
  start++;
}

Could be DWORD* instead of char*, I don't know what RegionSize stands for.

BTW variable start should be DWORD*, not DWORD. Or char*, there's not much information provided.

Dialecticus
Totally agree with the increment.. But that doesn't really address the error.
baash05
A: 

g is a pointer, you got it right with:

MEMORY_BASIC_INFORMATION mbi2 = g->mbi;

Why are you then doing this?:

start = (DWORD)g.mbi.BaseAddress;

dereference g, or use mbi2, which you already declared.

PigBen
And make mbi2 a reference, unless you have a reason to do a member-by-member copy here.
EboMike
Pig Pen, so rather than being 0x1000000 which is the base address in the first element in the list I am getting the value 0xffcc0000 which is the last value in the list.
flavour404
I have no idea what part of your code you are referring to. Your snippet creates a list of mb pointers, doesn't add any elements, then tries to iterate over the list. Since there are no elements in it, that while loop will not even be entered. So you can't be referring to this piece of code.
PigBen
+1  A: 

When posting such a problem, it is always extremely helpful to include the specific error message that you get from your compiler.

At the first sight I can't see why your code does not compile. However, you should be aware that your assignment of mbi2 does create a copy of the whole _MEMORY_BASIC_INFORMATION structure. (And maybe that is the source of the problem here.) You probably do not need to copy the structure, if I understand your case correctly, since you only want to get some information from it.

Try this:

_MEMORY_BASIC_INFORMATION &mbi2=(*i)->mbi;

If you do not need to change anything in mbi2, you should definitely use a const reference:

const _MEMORY_BASIC_INFORMATION &mbi2=(*i)->mbi;

Always remember that const-correctness is your friend!

svenor
A: 

I think the problem is your use of the word struct. In c++ there is little difference between struct and class.
So, just for giggles change all instances of the word struct, to class.

The problem becomes more obvious when you do that. You don't have a "g" object, you have a struct g. (PS BAD NAMING)

Pull off all instances of the word struct from this code and it should all work out.

Interview question: What is the difference between a class and an object?

baash05