Why does. NET Framework have no dedicated P/invoke library?

Source: Internet
Author: User

There is a simple question: Looking for Windows API definitions is generally asking: C # Is there any windows. h file similar to that used in C ++?

This is really a silly question. It's a C #ProgramMembers will know that C # does not have any header file. So the answer is too simple: No -_-.

Yes, this is the answer that C # programmers know. But how can someone still ask this question? So either the person who asks the question is an idiot or you don't understand the problem.

The real purpose of this problem is that he wants to call Native Windows APIs in C #, but he feels that it is cumbersome to declare windows APIs one by one and their data structures. In C ++, windows. h can be directly called.

Of course more people understand this question and give some reliable answers: With http://pinvoke.net/

Further think ,. net Framework itself must also use a lot of windows APIs, if decompile is a few. net Framework DLL, you will find that what you want is in Microsoft. under Win32, unfortunately, all are internal. We have to re-create the wheel.

Why does. NET Framework not publish these things? I guess it may be because the. NET Framework itself should be platform-independent. If you make these public, use these ApisCodeObviously, it cannot run on Linux. As for writing pinvoke code by yourself, although the Code cannot be cross-platform, this is user behavior, and Microsoft is not responsible.

Using pinvoke is not just as simple as writing a declaration. You must also consider whether the current operating system does not support or does not support workaround. You also need to consider the parameter encoding/decoding. Every time you use pinvoke, it makes no sense to repeat these tasks.

Therefore, there is a garbage in http://pinvoke.net. Http://pinvoke.codeplex.com/is a better choice.

No silly questions, only stupid answers.

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.