This article is a mirror article of machine translation, please click here to jump to the original article.

View: 20943|Reply: 0

[Source] C# imports and calls Win32 API functions via DllImport

[Copy link]
Posted on 11/26/2015 10:14:48 AM | | |
In C# programs, we often need to directly call the underlying APIs provided by Windows to better control the operation of the program, but since C# is run on . We can't call the managed languages on the Net CLR by directly including the .h header file of the Win32 API like a language like C++. Fortunately, Microsoft has provided us with a means to map functions in the Win32 API into C# code via DllImport Attribute from the very beginning.
[DllImport("user32.dll", EntryPoint = "FindWindow")]
public static extern int FindWindow(
            string lpClassName,
            string lpWindowName);
Among them, user32.dll specifies the name of the Win32 dynamic link library that needs to be imported, while the EntryPoint property specifies the name definition of the function to be mapped in the Win32 library. It should be noted that in C#, any C# function that needs to be used as an external function proxy must be declared as a public static extern ***.





Previous:"The type initializer for 'Emgu.CV.CvInvoke' threw an exception"?
Next:Please tell me how to train win10 Cortana
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com