PBYTE pb = NULL;
MEMORY_BASIC_INFORMATION mbi;
while(VirtualQuery(pb, &mbi, sizeof(mbi)) == sizeof(mbi))
{
   if(mbi.state == MEM_FREE)
       mbi.AllocationBase = mbi.BaseAddress;
   if((mbi.AllocationBase == hInstDll) || 
       (mbi.AllocationBase != mbi.BaseAddress) ||
        (mbi.AllocationBase == NULL))
      {
         ...
       }
        else
      ...
}