Createfilemapping's msdn translation and usage experience
Source: Internet
Author: User
The error "invalid handle" is always returned during the test of creating and opening file ing. After carefully reading msdn, I find that the function cannot be understood. Here I will translate the relevant explanations.
Handle createfilemapping (
Handle hfile, // physical file handle
Lpsecurity_attributes lpattributes, // Security Settings
DWORD flprotect, // Protection Settings
DWORD dwmaximumsizehigh, // large file size
DWORD dwmaximumsizelow, // Low file size
Lptstr lpname // shared memory name
);
1) physical file handle
Any available physical file handle. If you need to create a memory ing unrelated to the physical file, set it to 0 xffffffff (invalid_handle_value.
If you need to associate with a physical file, make sure that the access mode when creating your physical file matches the "Protection Settings", such as: the physical file is read-only, an error occurs when the memory ing needs to be read/written. we recommend that you create physical files in exclusive mode.
If invalid_handle_value is used, you also need to set the size of the memory space to be applied, regardless of whether the physical file handle parameter is valid, so that createfilemapping can create a memory space unrelated to the physical file size for you, it exceeds the actual file size. If your physical file is valid and the size parameter is 0, the returned address range is the same as that of the physical file. the ing address space of the returned file can be copied, integrated, or named. The initial content is 0.
2) Protection Settings
It is the security setting, but generally it is enough to set null. Use the default security configuration. in Win2k, if you need to restrict the usage of the application process that shares the memory file ing to the entire network, consider the restrictions.
3) High File Size
I think our machines are currently 32-bit Dongdong, and it is impossible to get a private 32-bit address space that more than 32-bit processes can address. Generally, set it to 0, I don't want to try setting it to a value greater than 0 either.
4) Low file size
This can still be set. However, to let other sharing users know the information about the file ing you applied for, I added a Structured description to the header of the obtained address space, record the memory ing size, name, and so on. In this way, the actual requested space is increased by a header information structure size than the input space. I think this method similar to BSTR should be reasonable.
5) shared memory name
This is the root cause of the hit during my test today, because in order to mutex access to the memory, I set a mutex handle, and the name is the same as the name of the shared memory, this is because they use the same namespace.
7) corresponding error of getlasterror when createfilemapping is called
Error_file_invalid if you attempt to create a zero-length file ing, this should be reported
Error_invalid_handle if you find that your namespace maps to the existing memory, mutex, semaphores, and the same name in the critical zone is troublesome
Error_already_exists indicates that the memory space name already exists.
8) Naming of related services or platforms is retained
Terminal Services:
The name can contain the "Global" or "local" prefix in the global or session namespace primary file ing. Other parts can contain any character except (). For details, refer to the kernel object name spaces.
Windows 2000 or later:
If Terminal Services does not run the special meanings of the "global" and "local" prefixes
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service