Share via


How can I get the size of a file mapping?

Question

Sunday, December 27, 2015 5:29 PM

Hello! 

I want to use a filemaping to transfer information at two process. For Example, In one process I use

 hfilemap=CreateFileMapping(hfile, NULL,  PAGE_READWRITE ,0,  4096, "mymap" ). At the other process call

 hfilemap=OpenFileMapping( FILE_MAP_READ|FILE_MAP_WRITE , 0,  "mymap" );

Now, if Idon‘t know the size of filemapping is 4096, How can I get the size of filemapping ?

Thanks!

  • CJS

All replies (3)

Sunday, December 27, 2015 8:14 PM ✅Answered

Check if this works:

    LPVOID v = MapViewOfFile( hfilemap, FILE_MAP_READ, 0, 0, 0 );

    MEMORY_BASIC_INFORMATION mbi = { 0 };

    VirtualQueryEx( GetCurrentProcess(), v, &mbi, sizeof( mbi ) );

Then see the value of mbi.RegionSize.

However, if the actual amount of transferred data is less than the pre-allocated size of the mapping, then the size can be embedded, for example, in the first four bytes.


Monday, December 28, 2015 8:18 AM

Thank you!

 Please help me to answer another question.

If I want to know which file is associatting with the filemapping object,  How  to do it?

Thanks

-CJS


Tuesday, January 5, 2016 3:25 AM

Hi chencjss,

>>If I want to know which file is associatting with the filemapping object,  How  to do it?

If you have new question, I suggest you post your question in a new thread.

Best Regards,
Herro Wong

We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.