How to use EnumPageFiles API function

G

Guest

Hi,

I want to get a list of the information of pagefiles with the API function
EnumPageFiles
However, the declaration confused me, since the first parameter , a pointer
to a callback function for each pagefile, is specified as OUT.
I wonder what is the output of the parameter and what it is for.
I think it should be a pointer to a callback function of mine, which should
be called for each pagefile, so that I can use the parameters passed from
the parameters of the pagefile. For my application, the prameters of the
callback function are right what I want. However, the code met a invalide
pointer access failure. The code is as follows:

BOOL OnEachPageFile(LPVOID pContext,
PENUM_PAGE_FILE_INFORMATION pPageFileInfo,
LPCTSTR lpFilename)
{
SwapInfo* ptmp = static_cast<SwapInfo*>(pContext);
ptmp->free = pPageFileInfo->TotalSize - pPageFileInfo->TotalInUse;
ptmp->name = lpFilename;
ptmp->path = lpFilename;
ptmp->size = pPageFileInfo->TotalSize;
ptmp->type = "Pagefile";
ptmp->used = pPageFileInfo->TotalInUse;
return FALSE;
}


int get_swap_info(vector<SwapInfo> & swapinfo)
{
SwapInfo info;
PENUM_PAGE_FILE_CALLBACK pf = &OnEachPageFile;
swapinfo.clear();
while( EnumPageFiles(pf, &info)){
swapinfo.push_back(info);
}
return -1;

}

As specified in MSDN, the sub of the callback PENUM_PAGE_CALLBACK should be
declared CALLBACK ( __stdcall acturally),but the declaration in psapi.h does
NOT give a CALLBACK decoration, I wonder why.

I tried to change the declaration of PENUM_PAGE_FILE_INFORMATION, placed
a CALLBACK there, and the execption is gone, but EnumPageFiles always
returns true even if my callback function returns false. So the while loop
will never terminates, how could I get the expected action ?

Help me , please!
Thanks ahead!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top