.NET provides three ways to import a COM component

xiaoxiao2021-04-11  1.7K+

.NET provides three ways to import a COM component: - Adding Reference Features By Visual Studio .NET - Transplanting By Command Line - TLBIMP.EXE - Using System.Runtime.InteropServices.TypelibConverter class programming Import The first way of function is not required, and it is very simple. In the third way I will explain the use of the PIA to illustrate the use of this method. However, my level is not high, you don't ask too much. ^ _ ^ Specifies to go forward, this article focuses on the second way. We can use the simplest call way to provide this tool directly: TLBIMP Testobj.dll. However, you need to remind you that if we use this way to import a COM component, we will "sacrifice" the original COM component, which is very dangerous. Personally, the simplest call mode is TLBIMP TESTOBJ.DLL /OUT: Interop.Testobjlib.dll. In this way, a COM Interop named Interop.Testobjlib.dll will be generated after execution. A simple example will be given below to explain the entire process. 1, first with a simple written in VB ActiveX Dll'Project name is TestObjList, class name is TestObjOption Explicit Public Function Add (ByVal iValue As Integer) As Integer Add = iValue 1End Function 2, use the command-line tools to import COM component TLBIMP TestObjLib.dll /out:interop.TestObjLib.dll 3, the test code write period of a call to this component in the .Net Windows Forms using interop.TestObjLib; private void button1_Click (object sender, System.EventArgs e) {TestObjClass obj = new Testobjclass (); int Num = 1; messagebox.show (obj.add (num) .tostring ());} A point in this point, when tlbimp.exe is generating an inter galable accessory, the name of the class in the original COM Behind the "Class". When calling, please pay attention.

转载请注明原文地址:https://www.9cbs.com/read-133544.html

New Post(0)