. NET INTPTR ==interoperable pointer

Source: Internet
Author: User

Call System.runtime.interopservice, you can use DllImport;

API functions are mainly in "kernel32.dll", "User32.dll", "GDI32.dll",

Kernel32.dll to invoke the LoadLibrary, GetProcAddress, and FreeLibrary below it. Look at MSDN and learn about the prototypes of three functions:

Hmodule LoadLibrary (LPCTSTR lpfilename);

Farproc GetProcAddress (hmodule hmodule, lpcwstr lpprocname);

BOOL FreeLibrary (hmodule hmodule);

LoadLibrary required parameter is the name of the DLL file to be called, and its return value is the handle of this DLL file;

GetProcAddress requires a handle to the DLL that is to be called, this value

Supplied by the return value of LoadLibrary, and the other parameter is the name of the function to invoke in the DLL file. Its return value is a pointer to a function;

The FreeLibrary requires a handle to the function DLL file that is called, and the return value is a Boolean type.

Note: View API functions to use vs Dumpbin.exe

Simply put, IntPtr is the wrapper structure of a struct-type pointer, which is a processing agent for type conversions between different programming languages.

Marshal: Commander of the Air Force, is a remote object management class, there are various operations to choose from.

The string argument is Intptr[dllimport ("user32.dll")]public static extern int MessageBox (int hWnd, IntPtr text, IntPtr caption, uint ty PE); void Main () {//string    var str = "hehe";    Create a pointer in the unmanaged heap    var ptr = Marshal.stringtohglobalansi (str);    Platform invoke MessageBoxA interactive pointer==intptr,uint 1,2,messagebox type;    MessageBox (0, PTR, IntPtr.Zero, 2);    Clean up    marshal.freehglobal (PTR);} Define other methods and classes here

. NET INTPTR ==interoperable pointer

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.