Execute native code directly in the. NET Program (C #)

Source: Internet
Author: User
Do not use C ++ CLI or native DLL.
Directly in. net ProgramNative code.

In the VB era, there have been many good referers who have made a compilation of direct calls in VB.Code.
A general module is specially designed to dynamically generate assembly code.

In fact, this is the execution of inline ASM.

The old method in. Net still works. But today we will not introduce this, but a more diverse way of using function interfaces.

I wrote a post about 06 years ago and dynamically called the native DLL export function in C.

The method introduced today and this public point both use a new feature of. NET 2.0.

Marshal. getdelegateforfunctionpointer

Unlike dynamic API calling, function pointers are not obtained from external DLL, but are dynamically allocated by. net programs.
It is actually executing inline ASM.

Compared with the old methods in the VB era, it has the advantage that function prototypes can be diversified,
The call can be performed using the delegate method. the. NET type in the parameter is automatically converted to the local type by the framework.

Maybe this is rarely used by the average person.

What are the actual uses?
Use it for fun and display it ;)

It can still be used properly in terms of security protection.
For example, from a pure developer perspective, you can apply this to the registration authorization code.

In addition, it can be used in. Net security protection tools. After the encryption tool encrypts the. NET program, it automatically injects these calls into the program.
You can even compile some simple method bodies into native code during encryption.
You do not need to attach a native DLL.

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.