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;*/
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:
If you do not need to change anything in mbi2, you should definitely use a const reference:
Always remember that const-correctness is your friend!