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

C++ Programmer's Cookbook

{C++ 基礎} {C++ 高級} {C#界面,C++核心算法} {設計模式} {C#基礎}

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 夢在天涯 閱讀(725) 評論(0)  編輯 收藏 引用 所屬分類: C#/.NET

公告

EMail:itech001#126.com

導航

統(tǒng)計

  • 隨筆 - 461
  • 文章 - 4
  • 評論 - 746
  • 引用 - 0

常用鏈接

隨筆分類

隨筆檔案

收藏夾

Blogs

c#(csharp)

C++(cpp)

Enlish

Forums(bbs)

My self

Often go

Useful Webs

Xml/Uml/html

搜索

  •  

積分與排名

  • 積分 - 1818834
  • 排名 - 5

最新評論

閱讀排行榜

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
              亚洲国产欧美一区二区三区同亚洲 | 一区二区欧美国产| 欧美成人综合网站| 亚洲国产日韩在线| 亚洲国产精品第一区二区| 久久阴道视频| 亚洲片国产一区一级在线观看| 欧美激情精品久久久久久| 欧美成人69av| 亚洲深夜av| 午夜精品久久久久久久99黑人| 国产午夜精品美女毛片视频| 久久久久久久97| 欧美大片免费久久精品三p| 99精品国产福利在线观看免费| 一区二区三区精密机械公司 | 国产日韩欧美在线观看| 久久免费国产精品| 欧美电影在线观看完整版| 制服丝袜激情欧洲亚洲| 亚洲综合视频网| 一区二区视频在线观看| 亚洲六月丁香色婷婷综合久久| 国产精品国产三级国产专区53| 久久黄色网页| 欧美激情亚洲自拍| 欧美一区二区大片| 欧美a级在线| 欧美一区影院| 欧美国产精品中文字幕| 午夜精品久久久久99热蜜桃导演| 久久久91精品国产一区二区三区 | 伊人久久婷婷| 亚洲特黄一级片| 亚洲国产精品传媒在线观看| 一本色道久久综合亚洲精品按摩| 国产亚洲精品高潮| 一卡二卡3卡四卡高清精品视频| 国产日韩欧美夫妻视频在线观看| 亚洲国产成人av好男人在线观看| 国产精品sm| 亚洲国产精品热久久| 国产情侣一区| 亚洲乱亚洲高清| 亚洲国产专区校园欧美| 亚洲欧美日韩国产综合| 一本久道久久久| 久久亚洲春色中文字幕| 欧美一区综合| 国产精品99免视看9| 亚洲人精品午夜在线观看| 激情成人av| 午夜精品久久久久久99热| 一区二区三区视频在线 | 99精品欧美一区二区三区| 在线成人国产| 欧美在线播放| 久久国产精品久久精品国产| 欧美日韩国产一级片| 亚洲高清在线观看一区| 亚洲大胆美女视频| 久久精品国产久精国产思思| 欧美在线精品一区| 欧美午夜不卡影院在线观看完整版免费| 欧美国产1区2区| 亚洲二区在线视频| 久久婷婷一区| 欧美成人a视频| 在线观看日韩| 免费日韩av| 亚洲大片在线| 日韩视频一区二区在线观看 | 国产揄拍国内精品对白| 亚洲永久网站| 欧美资源在线观看| 国产一区二区久久精品| 久久精品99国产精品| 久久天天狠狠| 亚洲国产成人精品视频| 免费成人高清在线视频| 亚洲激情视频网| 在线一区日本视频| 国产精品久久久久999| 亚洲自拍偷拍网址| 久久全国免费视频| 亚洲国产日韩欧美在线99| 欧美成人激情视频免费观看| 亚洲日本中文字幕免费在线不卡| 在线视频欧美日韩| 国产精品一区二区在线观看网站 | 亚洲精品免费看| 亚洲网站在线观看| 国产精品视频最多的网站| 久久精品人人做人人综合| 欧美顶级少妇做爰| 亚洲一级二级| 激情综合电影网| 欧美日韩亚洲激情| 亚洲欧美三级在线| 欧美成人精品在线播放| 一区二区三区色| 国产偷国产偷精品高清尤物| 久久亚洲私人国产精品va| 亚洲精品一区二区在线| 久久国产精品一区二区三区| 亚洲激情国产| 国产欧美日韩精品一区| 欧美成年人网站| 欧美在线视频播放| 日韩视频在线一区二区| 久久黄色网页| 亚洲一二三区精品| 亚洲国产一区二区在线| 国产欧美精品在线| 欧美精品v日韩精品v国产精品| 性欧美大战久久久久久久久| 亚洲福利在线观看| 久久久久国产精品一区| 亚洲天堂免费观看| 亚洲国产老妈| 国产一区二区三区免费不卡 | 欧美—级高清免费播放| 欧美在线视频免费| 亚洲图片激情小说| 亚洲精品一二| 亚洲电影免费观看高清完整版在线观看 | 亚洲九九精品| 欧美二区乱c少妇| 久久狠狠亚洲综合| 午夜视频在线观看一区| 一本色道久久综合狠狠躁篇怎么玩| 一区二区视频免费在线观看| 国产欧美日本| 国产精品欧美一区喷水| 欧美视频你懂的| 欧美人与禽性xxxxx杂性| 久久久久久有精品国产| 午夜精品影院在线观看| 亚洲永久免费观看| 亚洲香蕉网站| 中文久久精品| 亚洲一区二区在线免费观看视频| 99精品国产高清一区二区| 亚洲看片网站| 99国内精品久久| 一区二区三区免费在线观看| 日韩一级网站| 亚洲一区二区在线免费观看| 一区二区三区日韩| 亚洲午夜高清视频| 亚洲午夜成aⅴ人片| 亚洲综合视频1区| 午夜伦欧美伦电影理论片| 亚洲欧美日韩天堂| 亚洲欧美日韩在线一区| 欧美一区二区三区久久精品茉莉花| 新狼窝色av性久久久久久| 欧美在线视频免费| 久久一本综合频道| 欧美激情第1页| 欧美日韩在线视频首页| 国产精品国产自产拍高清av| 国产精品试看| 一区二区三区在线视频观看| 91久久香蕉国产日韩欧美9色| 亚洲美女黄色片| 亚洲一区欧美一区| 久久国产黑丝| 欧美二区在线看| 一区二区免费在线观看| 欧美一区二区三区免费视| 久久久久久一区| 欧美日韩人人澡狠狠躁视频| 国产精品视频免费观看| 韩国亚洲精品| aa国产精品| 久久er精品视频| 欧美激情视频网站| 一区二区av在线| 久久久久久久综合色一本| 欧美人体xx| 国内揄拍国内精品少妇国语| 日韩一级片网址| 久久国产精品第一页| 亚洲人成高清| 欧美诱惑福利视频| 欧美美女日韩| 红桃视频成人| 亚洲在线观看视频网站| 欧美黑人多人双交| 亚洲综合精品一区二区| 蜜桃精品一区二区三区 | 久久一区二区三区四区| 欧美三级乱码| 亚洲风情亚aⅴ在线发布| 小黄鸭视频精品导航| 最新国产成人在线观看| 久久精品视频在线观看| 国产精品久久网| 亚洲伦理网站|