"Inside C #" notes (15) under unmanaged code

Source: Internet
Author: User

Two writing unsafe code

a) fixed keyword

The code embodies the fixed usage: fixed (type* ptr= expression) {...} , type is an unmanaged type or void type like int*, expression is an arbitrary expression that can be returned as a type* pointer, and the fixed variable can only be in {...} Used in the.

The above code runs after the foo.x=42. Can only understand this point.

Three COM Interop

The interaction of COM components with the. NET runtime is done through COM interop. This involves a lot of knowledge of COM components, previously only used in the operation of Word Microsoft.Office.Interop.Word, here is only about to understand.

A) The COM component of the instance is Airlineinfo COM, and the public method is:

. NET can only use components that contain metadata (metadata), but not inside COM, presumably with implementations of some registration and similar interfaces. Therefore, the corresponding metadata is generated for the COM before it is manipulated. This work is done by the metadata layer, which handles information related to the data type and then generates the RCW based on these types of information (runtime callable Wrapper Runtime callable wrapper). The RCW is responsible for the activation, Marshal, and lifecycle management of COM objects.

b) Use Tlbimp.exe to generate a. dll file based on a COM file with the suffix. tlb, and then use the class and metadata in the DLL as you would with a normal class.

c) Using the method mentioned in B (early bound) will be strong type checking, auto-completion and other characteristics, but sometimes not at compile time to know the COM object's metadata, then you need to use late binding method.

?

You can call a method using Type.gettypefromprogid reflection as long as you know the name of a method in a COM component.

Learning materials: Inside C # by Tom Archer

"Inside C #" notes (15) under unmanaged code

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.