connecting COM to. NET (2) COM server p/invoke Way

Source: Internet
Author: User
Tags wrapper

One, COM server--> COM client

This is the traditional COM knowledge, if this part of the content is not clear, you can go to see Mr. Yang's personal column, where there are very good tutorials, I am not here nonsense ^_^

It does not mean that this part is not important, on the contrary, if the reader is familiar with this part, it will be found that all the subsequent content in form is almost imitating the traditional COM call.

Second, COM server-->. NET Client

Well, that's the point. The following diagram is the principle of this section. Each COM object will have a runtime callable wrapper (RCW) proxy, regardless of how many references it has.

In the absence of a public interface (or not at all)

The operation used in this case is p/invoke. At a minimum, we need to know the following two elements:

Name of DLL file

The name or sequence number of the function to be invoked;

Then you need to do the following two steps:

Identify it in a. NET program, must be static, external

C + +: extern "C"; call it like a normal function; note for parameters:

If it is a struct or class, note that internal members must be defined as public to expose

You can apply some properties to personalize, as described in the Personalization property code below, or you can use a wrapper class if you want to call a number of functions, or you want to make this function a member of a managed class:

Declare a DLL function directly within an existing class;

Makes functions isolated and easy to find, and you can create a class for each DLL function, respectively;

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.