Visual Basic 6.0 ??? ?? ??? Visual Basic .NET ?? Visual Basic 2005 ??????? ?? ??? ???? ?? ??? ???? ????

???? ?????? ???? ??????
???? ID: 817248 - ?? ???????? ?? ?????? ??? ?? ?? ???? ???? ???? ??.
??? ?? ??????? ???? | ??? ?? ??????? ????

?? ????? ??

?????

?? ???? ????? ???? ?? ?? ???? ????? 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 ??? ??? ????? ????? ??, ????? ????? ?? ???? ????:
  1. Visual Studio .NET ?? Visual Studio 2005 ??????? ?????
  2. ?????? ?? ?????? ?? COM interop ?? ??? ??????? ???? ????? ??? ?? ????????? ??????
  3. ????? ????????????? ??,?????? Explorer.
  4. ?????? Explorer ???, ????????? COM interop ?? ??? ?????, ?? ???? ??? ???? ????? ??? ??? ????-????????.
  5. ????? ????,??????????? ???????? ????, ?? ???? ??????????? ???

    ???:Visual Studio 2005, ??? ????? ?????????? ????????? ????..
  6. ?? ??? ???? ?? ??? ????? ????COM ?? ??? ??????? Interop??? ?????. ?? ?????? ???? ????? ????????? ??????????? ??? ????? ???
  7. ????? ????,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:
http://msdn2.microsoft.com/en-us/library/xc31ft41(vs.71).aspx
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

  1. Visual Studio .NET ?? Visual Studio 2005 ??????? ?????
  2. ????? ???????????? ??,????? ????-????? ????, ?? ???? ????????????.
  3. ?? ???????????????? ??????????? ????,????? ??? ?????????.

    ???:In Visual Studio2005 clickVisual Basic?? ???????????????? ??????.
  4. ?? ???????????????????? ????,Class Library.
  5. Name the project TestProj, and then clickOK.

    By default, Class1 is created.
  6. ????? ????????????? ??,Solution Explorer.
  7. ????-????? ????Class1.vb?? ????-????? ????, ?? ???? ????????. ????? ????,OKto confirm the deletion of the Class1.vb source file.
  8. ????? ????????????????? ??,Add Class.
  9. ?? ???????????????????? ????,COM Class.
  10. 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
  11. Add the following function to COMClass1.
       Public Function myFunction() As Integer
          Return 100
       End Function
  12. ?????? Explorer ???, ???? ?????????????? ?? ????? ????-????? ????, ?? ???? ??????.
  13. ?? ?????????????????? ???????? ????,?????.
  14. ?????? ???? ??COM Interop ?? ??? ?????????? ????? ????? ??, ?? ???? ??? ????? ????OK.
  15. ????? ????????????? ??,??????? ??????????????? ????? ???
  16. Visual Basic 6.0 ?? ??????? ?????
  17. ????? ???????????? ??,??? ?????????, ?? ???? ??? ?? ??? ???? ?? ??? ????? ???????? EXE???????? ?????????????? ????? ?? ??????? ?? ??? ?? ..

    ???????? ??? ??, Form1 ??? ???? ??????? ?? ???? ???
  18. ????? ????????????????? ??,??????.
  19. ??????????? ?????????? ???, ????? ?? ??? ???-????? ????TestProj?? ????-????? ????, ?? ???? ???OK.
  20. ??????? ?? ??? ??? ???? ??? ???????
  21. ???-????? ????Command1??? ?? ????? ?? ??? ??????
  22. ????? ??? ??????Command1_Click??????
    Dim myObject As TestProj.COMClass1
    Set myObject = New TestProj.COMClass1
    MsgBox myObject.myFunction
  23. ????? ????????????? ??,???????.
  24. ???? ??? ????? ?????

    ?? 100 ????????? ???? ?? ?? ???? ????? ?? ????? ??????

??????

???? ??????? ?? ???, Microsoft ?? ????? ??? ???? ?? ????::
????????? ??? ?? ??? interoperating
(vs.71) http://msdn2.Microsoft.com/en-us/library/sd10k43k .aspx

???

???? 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

??????????? ???

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com