C # functions required to call c ++ dll shared memory

Source: Internet
Author: User

The following call functions are all functions used in the project. Therefore, you do not need to modify the c ++ functions one by one to the functions supported by c # In msdn.

[Csharp]
// Create a file ing
[DllImport ("kernel32.dll", EntryPoint = "CreateFileMapping", SetLastError = true, CharSet = CharSet. Ansi)]
Public static extern IntPtr CreateFileMapping (int hFile, IntPtr lpattriing, uint flProtected, uint dwMaximumSizeHigh, uint dwMaximumSizeLow, string lpName );
// Open the file ing object
[DllImport ("kernel32.dll", EntryPoint = "OpenFileMapping", SetLastError = true, CharSet = CharSet. Auto)]
Private static extern IntPtr OpenFileMapping (uint dwDesiredAccess, bool bInheritHandle, String lpName );
// Map the file data to the address space of the process
[DllImport ("Kernel32.dll")]
Private static extern IntPtr MapViewOfFile (IntPtr hFileMappingObject, uint dwDesiredAccess, uint dwFileOffsetHigh, uint dwFileOffsetLow, uint dwNumberOfBytesToMap );
// Release the file data image from the address space of the calling thread
[DllImport ("Kernel32.dll", EntryPoint = "UnmapViewOfFile", SetLastError = true, CharSet = CharSet. Auto)]
Private static extern bool UnmapViewOfFile (IntPtr lpBaseAddress );
// Close an opened file handle
[DllImport ("kernel32.dll", EntryPoint = "CloseHandle", SetLastError = true, CharSet = CharSet. Auto)]
Private static extern bool CloseHandle (IntPtr hHandle );
// Obtain the last error message
[DllImport ("kernel32.dll", EntryPoint = "GetLastError", SetLastError = true, CharSet = CharSet. Auto)]
Private static extern uint GetLastError ();
 
// The function www.2cto.com is required to send messages.
[DllImport ("User32.dll", EntryPoint = "FindWindow", CharSet = CharSet. Ansi)]
Public static extern IntPtr FindWindow (string lpClassName, string lpWindowName );
 
[DllImport ("User32.dll", EntryPoint = "PostMessage", CharSet = CharSet. Ansi)]
Public static extern bool PostMessage (IntPtr hWnd, uint Msg, uint wParam, uint lParam );
//
Const int ERROR_ALREADY_EXISTS = 183;
// File access permission used in the OpenFileMapping and MapViewOf Functions
Const int FILE_MAP_COPY = 0x0001;
Const int FILE_MAP_WRITE = 0x0002;
Const int FILE_MAP_READ = 0x0004;
Const int FILE_MAP_ALL_ACCESS = 0x0002 | 0x0004;
// Protect attributes during file ing in the CreateFileMapping Function
Const int PAGE_READONLY = 0x02;
Const int PAGE_READWRITE = 0x04;
Const int PAGE_WRITECOPY = 0x08;
Const int PAGE_EXECUTE = 0x10;
Const int PAGE_EXECUTE_READ = 0x20;
Const int PAGE_EXECUTE_READWRITE = 0x40;
//
Const int INVALID_HANDLE_VALUE =-1;


From richerg85's column

Related Article

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.