青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

C++ Programmer's Cookbook

{C++ 基礎(chǔ)} {C++ 高級(jí)} {C#界面,C++核心算法} {設(shè)計(jì)模式} {C#基礎(chǔ)}

Interacting with COM Components Using C#

 

In this article, we will analyze COM components and their application in C#. These components became popular among developers after Microsoft released Active Server Pages. However, the whole scenario changed when Microsoft released its Windows 2000 operating system and subsequent COM+ technology. In this article, we will examine the fundamentals of this exiting technology followed by its application in C#.

Introduction to COM

COM is a set of specification and services that facilitates a developer to create reusable objects and components for running various applications. COM components are components that are developed by using these specifications. These components can be implemented either as an executable (EXE) or as a Dynamic Link Library (DLL). They are basically developed using Visual Basic or Visual C++. They can either act as a server to a Visual Basic or C++ client application, or can be applied on the Web by using Active Server Pages (ASP).

In Visual Basic 6.0 (See Figure 1), you can refer a COM component in your application by adding a reference from the Project | References Menu. After that, you can call the respective methods of the added components in your client application. These components are introduced to reduce coding and to manage an application effectively.

Figure 1—Project | References Menu

In an Active Server Page application, you will write a code like what's shown below:

Set conn= Server.CreateObject("ADODB.Connection")

In the above code, ADODB is one of the components in which Connection is an object. Conn is a user-defined object, which should be referred while accessing the methods of the Connection object as shown below:

Conn.Open "Internet"

You cannot refer a built-in component directly in applications. As already examined, COM components can be either a Dynamic Link Library or Executable. Let's now discuss what these mean.

Dynamic Link Libraries are referred to as in-process objects because they run within the same address space as the client program that called the component. The main advantage in using these types of components is that a separate process is not created each time the component is accessed. Executables are considered to be out-of-process programs. They are executed in their own address space. Moreover, they consume more processing time when the program is called by an application.

In the case of DLLs, failure of an in-process component will ultimately bring down the application, whereas this may not happen in the case of EXEs because they are executed in their own address space.

With COM technology, you can:

  1. Create reusable components for your applications.
  2. Develop the component using one language and implement it in another language. For instance, you may develop a component using Visual C++ and implement it in a Visual Basic application.
  3. Make changes to the component without affecting the application.

Windows 2000 introduced a new technology called COM+, which is an extension to the existing COM. There are advanced technologies such as DCOM, which means Distributed COM. With DCOM, you can access components of other systems in a networked environment. However, a complete discussion to these technologies is beyond the scope of this article.

Creating a COM Component

In this session, we will demonstrate how to create a COM component by using Visual Basic 6.0, with the help of a series of steps. To create a COM component by using Visual Basic 6.0, you have to use either ActiveX DLL or ActiveX EXE projects. For our discussion, ActiveX DLL is used. The steps required for creating an ActiveX DLL are outlined below.

  1. Fire up Visual Basic and select the ActiveX DLL Icon from the New Project dialog box, as shown in Figure 2.

    Figure 2—Visual Basic 6.0 start up

  2. Change the class name to something meaningful like "Our_csharp".
  3. Now supply the code shown in Listing 1:

    Listing 1

    Public Function Show()
       MsgBox ("bye")
    End Function
    
  4. To create a function, you can use the Tools | Add procedure menu, as shown in Figure 3.

    Figure 3—Adding Procedure

  5. Save the project by supplying relevant class and project names of your choice.
  6. Change the Project name and Description by selecting the Project | Properties menu (see Figure 4).

    Figure 4—Properties Dialog

  7. Set the Binary Compatibility from the Components tab of the above menu because this action will not create a separate GUID upon each compilation.
  8. Finally, create your DLL by selecting File | Make Csharpcorner.dll. This is the name by which you save your VB project.

That's all. Your DLL is now complete. The next session will show you how to apply this DLL in your C# program.

Integrating the COM Component in C#

In this session, you will learn how to apply the DLL we discussed in last session in a C# application.

As you know with Visual Basic 6.0, it's possible to develop a COM server as shown in the previous session and implement it in a Visual Basic or Visual C++ client program. You may wonder about the idea of calling this DLL in a C# application. When we compile a C# program, an Intermediate Language (MSIL) is generated and it's called as Managed Code. A Visual Basic 6.0 DLL is Unmanaged, meaning it's not being generated by the Common Language Runtime. But, we can make this Visual Basic DLL interoperate with C# by converting the same into a .NET-compatible version.

It's not possible for a C# program to communicate with a Visual Basic DLL without converting the same into its .NET equivalent. To do so, the .NET SDK provides a tool called tlbimp. It stands for Type Library Import and converts your DLL to its equivalent .NET Assembly. For the above project, supply the following command after properly installing the SDK.

tlbimp Csharpcorner.dll /out:Csharp.dll

A new .NET-compatible file called Csharp.dll would be placed in the appropriate directory. The whole process is still not complete. You have to call this DLL in a C# program, as shown in Listing 2:

Listing 2

using Csharp;
using System;

public class Csharpapply     {

   public static void main()         {
      Our_csharp c = new Our_csharp();
      s.Show();
   }

}

Notice a function named Show() in the above session. It's called in the above listing. Notice the following declaration:

using Csharp;

Csharp is our .NET-compatible DLL file. Upon conversion, it will be changed to a .NET Assembly. In C#, all assemblies are referred with the keyword "using".

Upon execution of the above C# application, you can see the message box, as shown in Figure 5.

Figure 5—Sample Message Box

If you are using Visual Studio .NET, you can refer the DLL from Project | Add Reference | COM Tab. Select your DLL by using the browse button. This will add a reference to your project. After adding a reference, copy the above code and execute.

About the Author

Anand Narayanaswamy is a Microsoft MVP (Microsoft Most Valuable Professional) who works as a freelance Web/Software developer and technical writer. He runs and maintains learnxpress.com, and provides free technical support to users. His areas of interest include Web development, Software development using Visual Basic, and in the design and preparation of courseware, technical articles, and tutorials.

posted on 2005-11-18 12:30 夢(mèng)在天涯 閱讀(707) 評(píng)論(0)  編輯 收藏 引用 所屬分類: C#/.NET

公告

EMail:itech001#126.com

導(dǎo)航

統(tǒng)計(jì)

  • 隨筆 - 461
  • 文章 - 4
  • 評(píng)論 - 746
  • 引用 - 0

常用鏈接

隨筆分類

隨筆檔案

收藏夾

Blogs

c#(csharp)

C++(cpp)

Enlish

Forums(bbs)

My self

Often go

Useful Webs

Xml/Uml/html

搜索

  •  

積分與排名

  • 積分 - 1812163
  • 排名 - 5

最新評(píng)論

閱讀排行榜

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
      <noscript id="pjuwb"></noscript>
            <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
              <dd id="pjuwb"></dd>
              <abbr id="pjuwb"></abbr>
              久久天堂国产精品| 黑人巨大精品欧美一区二区 | 亚洲黑丝在线| 伊人久久婷婷色综合98网| 国产亚洲精品一区二区| 国产一区二区三区直播精品电影| 国产一区二区三区在线免费观看| 一区二区亚洲欧洲国产日韩| 在线日韩精品视频| 一区二区毛片| 久久福利一区| 欧美顶级大胆免费视频| 亚洲精品乱码| 亚洲日韩视频| 午夜精品亚洲一区二区三区嫩草| 欧美一区二区三区四区在线观看| 久久综合国产精品| 欧美日韩福利在线观看| 国产美女一区| 亚洲精品视频在线播放| 亚洲欧美日韩精品久久| 另类春色校园亚洲| 在线亚洲国产精品网站| 久久久久九九九九| 国产精品成人在线观看| 亚洲第一网站| 亚洲欧美日韩视频一区| 美女爽到呻吟久久久久| 野花国产精品入口| 麻豆9191精品国产| 国产精品伊人日日| 99精品免费| 米奇777超碰欧美日韩亚洲| 一区二区不卡在线视频 午夜欧美不卡在 | 国产精品九九| 亚洲国产黄色片| 欧美一区网站| 一二美女精品欧洲| 欧美国产日韩一区二区| 国产性色一区二区| 亚洲一区在线免费| 亚洲国产另类 国产精品国产免费| 亚洲欧美国产高清va在线播| 久久久久网址| 日韩午夜免费| 免费欧美高清视频| 欧美在线观看天堂一区二区三区| 欧美日韩123| 亚洲欧洲精品一区二区精品久久久| 欧美一区二区三区在线观看| 亚洲精品日韩欧美| 欧美激情二区三区| 1204国产成人精品视频| 久久电影一区| 香蕉久久国产| 国产日韩欧美自拍| 欧美一区二区三区在线免费观看| 99视频在线观看一区三区| 欧美国产一区二区在线观看| 亚洲第一中文字幕| 嫩草国产精品入口| 久久人91精品久久久久久不卡| 国产夜色精品一区二区av| 久久高清国产| 欧美专区第一页| 黄色成人在线免费| 欧美电影在线观看| 欧美精品一区二区高清在线观看| 亚洲精品日韩久久| 亚洲理论在线观看| 欧美日韩一区精品| 亚洲欧美综合国产精品一区| 亚洲在线中文字幕| 国产亚洲欧洲一区高清在线观看 | 欧美一区二区三区婷婷月色| 国内偷自视频区视频综合| 久久综合久久久| 欧美77777| 中文在线一区| 香蕉久久夜色精品国产| 伊人男人综合视频网| 亚洲国产精品免费| 国产精品视频精品| 欧美freesex交免费视频| 农村妇女精品| 亚洲男人第一av网站| 久久精品成人一区二区三区蜜臀| 樱桃成人精品视频在线播放| 亚洲欧洲综合另类| 国产精品久久久久久久久搜平片 | 久久久久久9| 欧美3dxxxxhd| 久久9热精品视频| 欧美不卡视频一区| 午夜精品福利一区二区蜜股av| 久久精品国产77777蜜臀| 日韩一区二区免费高清| 亚洲欧美日韩国产一区二区三区| 在线成人av| 亚洲午夜精品一区二区| 亚洲国产精品成人va在线观看| 1024亚洲| 免费欧美日韩| 国产精品国产三级国产普通话三级 | 浪潮色综合久久天堂| 亚洲免费一级电影| 免费一级欧美在线大片| 亚洲中字黄色| 欧美激情精品久久久久久黑人| 久久精品夜色噜噜亚洲a∨| 欧美日韩国产在线播放| 欧美成人精品一区二区三区| 国产精品自拍网站| 9久re热视频在线精品| 亚洲国产欧美一区二区三区丁香婷| 亚洲视频免费| 一区二区三区精品视频在线观看 | 国产曰批免费观看久久久| 99国产精品| 日韩视频一区二区三区在线播放| 久久精品国产69国产精品亚洲| 亚洲欧美日韩精品久久奇米色影视| 免费在线观看精品| 欧美成人午夜剧场免费观看| 国产一区二区三区高清播放| 亚洲一区网站| 亚洲性线免费观看视频成熟| 欧美激情亚洲一区| 91久久综合| 亚洲精品免费在线观看| 蜜桃av一区二区三区| 麻豆精品在线视频| 一区二区三区中文在线观看| 欧美一级播放| 久久免费视频这里只有精品| 国产深夜精品| 久久精品国产精品| 久久天天狠狠| 亚洲第一狼人社区| 女生裸体视频一区二区三区| 欧美成人情趣视频| 亚洲精品欧洲精品| 欧美日韩一区二区高清| 日韩亚洲一区二区| 亚洲免费视频观看| 国产老女人精品毛片久久| 午夜精品久久久久久| 久久久久久久综合狠狠综合| 在线播放亚洲| 欧美精品久久久久a| 在线视频你懂得一区| 欧美一区二区三区四区在线观看 | 久久精品国产免费观看| 亚洲日本在线观看| 一区二区三区免费观看| 欧美午夜免费影院| 性色av一区二区怡红| 可以看av的网站久久看| 亚洲国产成人久久| 国产精品久久久久久亚洲调教 | 欧美在线播放一区| 国精产品99永久一区一区| 老色鬼久久亚洲一区二区| 亚洲人成艺术| 久久国产欧美| 亚洲激情在线观看视频免费| 欧美日韩一区二区欧美激情| 亚洲淫性视频| 欧美国产亚洲另类动漫| 亚洲在线视频免费观看| 黄色亚洲网站| 欧美日韩在线不卡| 欧美在线免费| 亚洲精品乱码久久久久久日本蜜臀| 亚洲免费在线视频一区 二区| 国内外成人在线视频| 欧美激情在线有限公司| 香蕉乱码成人久久天堂爱免费| 欧美国产综合| 久久大综合网| 亚洲私人黄色宅男| 在线免费观看日本一区| 国产精品久久久久永久免费观看| 久久婷婷麻豆| 亚洲欧美日韩系列| 日韩天堂在线观看| 欧美黄色小视频| 久久久久久久久久看片| 亚洲欧美日韩爽爽影院| 99re66热这里只有精品4| 一区免费观看视频| 国产欧美日韩在线播放| 欧美视频在线观看免费网址| 免费成人在线视频网站| 欧美一区二区三区在线| 亚洲一区二区三区四区中文 | 久久国产视频网| 中文在线资源观看网站视频免费不卡| **性色生活片久久毛片| 国产日韩欧美中文在线播放|