Clr_via_c #. 3rd translation [1.9 Non-managed code operations]

Source: Internet
Author: User

1.9 interoperability with unmanaged code and unmanagedCodeInteroperability

 

. NetThe Framework provides advantages that many other platforms do not have.However,Few companies will redesign and re-implement their code. Microsoft also recognized this issue and passedCLRTo provide some mechanisms to allowProgramMy colleagues include hosted and unmanaged code. Specifically,CLRSupports three types of interoperability scenarios.

The managed code canDLLCall the unmanaged MethodManaged code can use a mechanism called P/invoke (platform invoke) to easily call functions contained in the DLL. In short, many types defined in FCL must internally call functions exported from kernel32.dll, user32.dll, and so on. ManyProgramming LanguageBoth provide a mechanism to allow the hosted code to conveniently call the unmanaged functions contained in the DLL. For example, the C # application can call the createsemaphore function exported from kernel32.dll.

 

Managed code can use existing COMControls (Server)Many companies have implemented a large number of unmanaged COM components. Using the Type Library from these components, you can create a managed assembly to describe COM components. Managed code can access types in managed assembly like any other managed type. For more information, see the tlbimp.exe tool configured with. NET Framework sdk. Sometimes, you may not have a library. Instead, you want to control more content generated by tlbimp.exe. In this case, you canSource codeManually construct a type so that the CLR can use it to achieve correct interoperability. For example, you can use the DirectX COM component from a C # application.

 

hosting type (server) can be used for unmanaged code many existing unmanaged codes require a COM component, this ensures that the code works correctly. With managed code, these components can be implemented more simply, avoiding all Code having to deal with reference counting and interfaces. For example, you can use C # To create an ActiveX control or a shell extension. For more information, see the tlbexp.exeand regasm.exe tools configured with. NET Framework sdk.

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.