?? ???? ????? ???? ?? ?? ???? ????? Microsoft Visual Basic .NET ?? Microsoft Visual Basic 2005 ???????? ??????? ?? Microsoft Visual Basic 6.0 ??? ?? ???? ??? ?? ????? ?? ????
.NET ?????? ?? COM exposing ?? ??? ?????????????
?? ?? ?? Microsoft .NET ??????? ??? ???????? ???? (COM) ??????????? ??? ?????? ?????? ???? ????? ???, ??????-??? ?? ????? COM ?????? ?????????? ?? ????? ????? ???????? ?????? (
????,
???????,
struct,
????? ????) ?? COM ??????? ????????? ?? ??? ???????? ?? ?? ????????????? ?? ???? ????:
- ??????? ????????? ?? ?????? ??? ?? ?????? ???? ??? ??????????? ?????
COM interop ?? ???? ?? ??? ??????? ?? ???? ???? ???? ?? ??????? ??? ??? ???????? ?? ????: ????? ???? ?? ??? ??? ??????? ?? ?????? ????? ??? ???????, ?? ?????? ??????? ?????? ????? ?? ?????? ?????? ??? ?? ??????????? ???? ?? ??? ??????? ???
- ???? ?? ??? ??? COM ?? ??????? ???? ?? ??? ?? ??? ???????? ?????? ????? ????? ???? ????????? ?????? ?? ??????? ??? ??????? ??? ?? ??????? ???? ?? ??? ?????? ????????? ??? ?????, ???? ????????? ?????? COM. ??? ??? ???
- ??? ?????? ????? (???????, ???, ????? ?? ???????) ?? ???? ?? ??? ??? COM ?? ??????? ???? ?? ??? ?????? ????? ????? ????????? ?????? ?? ????? ???? ?? ????????? COM. ???? ?? ??? ????? ???? ?? ??? ???????? ??? ??, ??? ????????? ?????? ?? ????? ????? ??? ?????ComVisibleAttribute??? ???? ??? ?? ?????? ?? ???????? ?????? ?? ????? ??????? ?? ????? COM ??????? ????????? ?? ?????? ?? ??? ????????
- ?????? COM. Managed ?? ?????? ?? ???? ???? ?? ??? ?? ????????? ??????? constructor ???? ?????, ????????? ?????? COM. ??? ??? ??? ???????, ????????? ??????? constructor (??? constructor ???? ?? ????), ???? COM ??????? ?????? ?? ??? ?????? ???? ????? ?? ????? COM ??????? ?????? ????? ?? ?? ???? ??? ??? ?????? ???? ??? ??? ???? ?? ?? ??????? COM ??????? ?? ??? ???? ??? ??? ?? ?? ???????? ?? ??? ?? ???? ?? ??????? overloaded constructors ????? ?? ???? ??? ???????, constructors ???? ?? ??????? ?? ???? ?? ???? ?? ?? ??? ???????? (.NET) ????
- ?????? ??? ???? ???? ?? ????? ? ? COM ??????? ?? .NET ??????? ?????? ?? ??? ?????????? ??? ???? ????
- ?????COMClass???????? ??? Visual Basic 2005 ?? Visual Basic .NET ???? When you
add a new class that you intend to expose to COM applications, consider using
theCOMClasstemplate that is provided by Visual Basic .NET or by Visual Basic
2005. TheCOMClasstemplate creates a class that includes theCOMClassAttributeattribute and generates GUIDs for the CLSID, the Interface ID,
and the Event ID that are exposed by your type. ??? ??,COMClasstemplate creates a public constructor without parameters. This is
the easiest way to create a new class that follows the guidelines for creating
COM callable types.
COM interop ?? ??? .NET ??????? ??????? ?? ??? ?? ?? ???? ?????? ????????? ??? ??? ??
??????????? ???????? ??? ?? ??? ???????? ???? ?? ??? Visual Basic 6.0, ?? ??? ?????? ?? ?? ?? ??????? COM interop ?? ??? ??????? ???? ?? ???? ?????? ????????? ????? ????? ?? ??????? ?????? ?? ?? ???? ???????? ???????? ?? ???? ??? COM ??????? ????????? interacts ??????? ?? ???? ?????? ????????? COM ??????? ????????? ?? ??? ??????? ??? exposed ???????? ?? ???? ??? ?????? ?? ??????? ?? ?????? ???? ???
??? ???? ?? ??? ????????? ?? ?????? ???? ????? ??? ?? ?? ??? ??? ?? ?????? ???????? ?? ?? ????? ???????? ???
????? ???????? ?? Microsoft Visual Studio .NET ?? Microsoft Visual Studio 2005 ???????? ??? ?? ???? ?????? ????????? ????? ?? ?? registers ??? ??????? ????????? ?? ????? ???
COM Interop ?? ??? ???????????????? ?? ??? ??? ????? ????? ??
configuration???. ??? ?? ?????
COMClass???????? ?? ?? ?? ????, Visual Studio .NET ????? ?? Visual Studio 2005 ????: ??? ???? ??
COM Interop ?? ??? ?????????? ?????. ?????? ???? ?? ???? ?? ???
COM Interop ?? ??? ???????Visual Studio .NET ??? ?? Visual Studio 2005 ??? ??? ????? ????? ??, ????? ????? ?? ???? ????:
- Visual Studio .NET ?? Visual Studio 2005 ??????? ?????
- ?????? ?? ?????? ?? COM interop ?? ??? ??????? ???? ????? ??? ?? ????????? ??????
- ????? ????????????? ??,?????? Explorer.
- ?????? Explorer ???, ????????? COM interop ?? ??? ?????, ?? ???? ??? ???? ????? ??? ??? ????-????????.
- ????? ????,??????????? ???????? ????, ?? ???? ??????????? ???
???:Visual Studio 2005, ??? ????? ?????????? ????????? ????.. - ?? ??? ???? ?? ??? ????? ????COM ?? ??? ??????? Interop??? ?????. ?? ?????? ???? ????? ????????? ??????????? ??? ????? ???
- ????? ????,OK??? ???? ?? ?????? ?????????? ????? ?? ??????? ?? ??? ?? ..
??? Visual Studio .NET ?? Visual Studio 2005 ??????? ???? ?? ?? ??? ???? ??? ???????? ??? ?? ????? ?? ???????? ??????? ?? ??? ?????? ????????? (.tlb) ????? ?? ??????? ???? ?? ???, ??????? ??????? ????? ?? ????? (RegAsm.exe) ?? ???
/ TLB?????. ?? ?? ?? ????? ???? ?????
/ Codebase??? ???????? ??????? ??? ?? ???? ??????? ?? ?? ???????? ??????? ??? ????? ?? ???? ???? ?????? ??? ???? ?? ??? ???????? ????? ????????? (EXE)?
?? ???? ??????? ???? ????????? ?? ???? ??, ?? ?? ????????? ?? ????? ????? ?? ??? ?????? ??? ???? ????????? ???? ??????? ???? ???? ??? ???? assemblies ????? ????????? (EXE) ?? ??? ??????? ??? ??????? ???? ?? ??? ??????? ??? ?? ???? ???? COM ??????? ?????????, ?? ??? ?? ?? ???? ?? ?? ??????? ?? ????????? ?? ??? ??????? ??? ????? ???
A shared assembly is available for use by multiple applications on the
computer. To create a shared assembly, you must sign the assembly with a strong
name and install the assembly into the Global Assembly Cache (GAC) on the
destination computer.
For more information about how to sign the
assembly with a strong name and install the assembly into the Global Assembly
Cache (GAC), visit the following Microsoft Web site:
You should use both the
/tlb:switch and the
/Codebaseswitch when you register the assembly. The
/tlb:switch generates and registers a type library, and the
/Codebaseswitch registers the location of the managed assembly in the
Windows registry. If you do not use the
/Codebaseswitch and the assembly has not been installed into the Global
Assembly Cache (GAC), you must put a copy of the assembly into the folder of
each COM client application (EXE) so that the assembly can be located by the
common language runtime (CLR).
To generate and register a type library
and register the location of the managed assembly, type the following command
at the command prompt:
RegasmAssemblyName.dll/tlb:FileName.tlb/codebase
Create a COM callable assembly in Visual Basic .NET
- Visual Studio .NET ?? Visual Studio 2005 ??????? ?????
- ????? ???????????? ??,????? ????-????? ????, ?? ???? ????????????.
- ?? ???????????????? ??????????? ????,????? ??? ?????????.
???:In Visual Studio2005 clickVisual Basic?? ???????????????? ??????. - ?? ???????????????????? ????,Class
Library.
- Name the project TestProj, and then clickOK.
By default, Class1 is created. - ????? ????????????? ??,Solution
Explorer.
- ????-????? ????Class1.vb?? ????-????? ????, ?? ???? ????????. ????? ????,OKto confirm the deletion of
the Class1.vb source file.
- ????? ????????????????? ??,Add
Class.
- ?? ???????????????????? ????,COM
Class.
- Name the class COMClass1.vb, and then click?????
COMClass1 is created with the following code.<ComClass(ComClass1.ClassId, ComClass1.InterfaceId, ComClass1.EventsId)> _
Public Class ComClass1
#Region "COM GUIDs"
' These GUIDs provide the COM identity for this class
' and its COM interfaces. If you change them, existing
' clients will no longer be able to access the class.
Public Const ClassId As String = "6DB79AF2-F661-44AC-8458-62B06BFDD9E4"
Public Const InterfaceId As String = "EDED909C-9271-4670-BA32-109AE917B1D7"
Public Const EventsId As String = "17C731B8-CE61-4B5F-B114-10F3E46153AC"
#End Region
' A creatable COM class must have a Public Sub New()
' without parameters. Otherwise, the class will not be
' registered in the COM registry and cannot be created
' through CreateObject.
Public Sub New()
MyBase.New()
End Sub
End Class - Add the following function to COMClass1.
Public Function myFunction() As Integer
Return 100
End Function - ?????? Explorer ???, ???? ?????????????? ?? ????? ????-????? ????, ?? ???? ??????.
- ?? ?????????????????? ???????? ????,?????.
- ?????? ???? ??COM Interop ?? ??? ?????????? ????? ????? ??, ?? ???? ??? ????? ????OK.
- ????? ????????????? ??,??????? ??????????????? ????? ???
- Visual Basic 6.0 ?? ??????? ?????
- ????? ???????????? ??,??? ?????????, ?? ???? ??? ?? ??? ???? ?? ??? ????? ???????? EXE???????? ?????????????? ????? ?? ??????? ?? ??? ?? ..
???????? ??? ??, Form1 ??? ???? ??????? ?? ???? ??? - ????? ????????????????? ??,??????.
- ??????????? ?????????? ???, ????? ?? ??? ???-????? ????TestProj?? ????-????? ????, ?? ???? ???OK.
- ??????? ?? ??? ??? ???? ??? ???????
- ???-????? ????Command1??? ?? ????? ?? ??? ??????
- ????? ??? ??????Command1_Click??????
Dim myObject As TestProj.COMClass1
Set myObject = New TestProj.COMClass1
MsgBox myObject.myFunction
- ????? ????????????? ??,???????.
- ???? ??? ????? ?????
?? 100 ????????? ???? ?? ?? ???? ????? ?? ????? ??????
???? ??????? ?? ???, Microsoft ?? ????? ??? ???? ?? ????::
???? ID: 817248 - ????? ???????: 05 ?????? 2010 - ??????: 2.0
???? ???? ???? ??:
- Microsoft Visual Basic 2005
- Microsoft Visual Basic .NET 2003 Standard Edition
- Microsoft Visual Basic .NET 2002 Standard Edition
- Microsoft Visual Basic 6.0 Professional Edition
- Microsoft .NET Framework 2.0
- Microsoft .NET Framework 1.1
- Microsoft .NET Framework 1.0
| kbvs2005applies kbvs2005swept kbnamespace kbdll kbcominterop kbinterop kbautomation kbhowtomaster kbmt KB817248 KbMthi |
???? ?????? ??????????????????: ?? ???? ?? ???? ??????? ?? ????? ?? Microsoft ????-?????? ?????????? ?????? ?????? ???? ??? ??. Microsoft ???? ??? ????-???????? ?? ????-???????? ????? ?????? ?? ???? ???????? ???? ?? ???? ????? ????? ??? ?? ??? ?????? ?? ???? ???? ???? ??? ????? ??. ???????, ????-???????? ???? ????? ???? ???? ???? ???. ?????, ????????, ?????-???? ?? ??????? ?? ???????? ?? ???? ???, ???? ?? ??? ?????? ???? ???? ??? ????? ??? ?? ???? ??. Microsoft ??????? ??? ???? ?? ?????? ?? ??????????, ????????? ?? ??? ?????? ?? ???? ????? ?? ???? ???????? ?? ??? ???? ????? ?? ??? ????????? ???? ??. Microsoft ????-?????? ?????????? ?? ????? ?????? ?? ?? ??? ??.
?????????? ?? ??????? ????????? ??????? ??:
817248
(http://support.microsoft.com/kb/817248/en-us/
)