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

???? ?????? ???? ??????
???? ID: 245115 - ?? ???????? ?? ?????? ??? ?? ?? ???? ???? ???? ??.
??? ?? ??????? ???? | ??? ?? ??????? ????

?? ????? ??

??????

???? ?? ????? ???? ?? ??? ??? ??????? ????? ?? ???? ?????????, ???? ????????, ????????????? ?? maintainability ??? ?? ????? ?? ???????? ?? ???? ????

?? ???? ?????? ??????? ??????? ?? ??? ???????? ?? ?????? ?? ????? ???? ??, ?? ???????? ???? ?? ????? ?????? weighs.

???? ???????

??????? ?? ??/???? ?? ?????????? ??? ?? ??? communicates ?? ???? ???? ?????????? ??? Microsoft ?? ????? ?? ????????? ???? ??, ?? ????????? ??? ???????? ???? (COM)? ?? ??????? ?????-??? ????? ??????????? ?? ??? Visual Basic ?? Visual Basic ???? ?????? ??? ????? ?? ??? ???? ??, ?? ??????? ????????? ?? ???? ??? ??????? ?? ??? ???

Historically, ??????? ???????? IDispatch ?? ?????? ???? ???? ??? ???????? ?? ???????? ?? ??????? ??????? ?? ??? ???? ?? ??? ??????? ?? ?????? ???? ?? ?? ????? ?? ????? ??? ?? ??? ???????? ?? ??? ??? ???? ????? ??? ?? ??? ?? ????? ??????? ??????? ???; ??? ????????? ??? ???????? ?? ??? ???? ????? ??, ??? ??, ????????? ??????????? virtually COM ????????, ?? ?? ?? IDispatch ?? ?????? ???? ?? (?? ????? ???? ???? ?? ???? ?? ?? ??? ?????) ???? ?? ??? ?? ???? ??? ?? ???? ???? ?? ????? ?? ???? ????? ???????? Automating ??? ?? ????? ???????? ??????? ?? ?????? ???? ???

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

???????? ??? ??????? ???? ???? ?? ?? ???????? ??? (?????? ?? ?????) ?? ??? ?????????? ?????? ???? ?? ?????? ??? ?? ??? ???? ?? ?? ????????? ??? ?? ????????? ?????? ????, ?? ??? ?????? ??? ??? ??? ????? ???? ?????? ?? ???? ??? ?? ????????? ?? ???? ??? ?? ?? ??? ???

????????? ?? ????? ???, ?? ??? ??? ?? ???????? ???????? ?? ??? ?? "????????" ?? ?????? ???? ??? ?? ???? ??? ???????? ??? ?? ?? ??? ???? "?????? 12, ????? x ???? ????? ?? ??? ?????." ???? ??? ???????? ?? ??? ?? ??? imagine ?? ???? ????? ??????? ?? ?? ?? ?? ???????? ???? ?? ?? ??, ????? before ???????? ??? ?? ????, ??? ??? ???????? ?? ??? ????? ?? ??? ????? ???? ????? ?? ???????? ??? ??? ????? ?????? ???????? ????? ???? ??? ?? ???? ?? ???? "?????" ???? ?? ???? ???????? ?? ???? ????? ?? ?????? ?? ??? ???????? ?? ??? ????????? ?????

?????????? ???????? ???? ???? ??? ???? ??? ?? ??? ?? ??? ?? pulled ?? ??? ??? ??? ?? ????"." ???? ?? ???? ???? ?? ???????? ?? ???????? ??? act ?????? ?? ????? ?? ?? ?????? ??? (?? ?????? offsets, ???? precise ???? ?? ???) ?? ??? ?? ???? ??? ???? "???? ?? ???" ?? ?????? ?? ??? ???? ???? ??? COM ????????, ??? ?? ??? ?????? ????? ???? (v ?????? ?????? ??) ?? ?? ?????? ??? ???????? ?????? held. ?? ??? COM ?????? ????? ??, ??? v ?????? ?? ?????? ?? ????? ???

COM ???????? ?? ?????? ??? ??? ???? ??? ?? ?????? ?? ???? ???????? ?? ???? ??, ?? ?? ???? ?????????? ???? ?? v-???? ?? ???? ??? ?? ???? V-?????? ?? ?????? ???? ?? ??? ???? ???? ???????? ????????? ????? ?????? ?? ?? ???????? ?? ??? ?? ???? ??? ???? COM ???????? ?? ????? ?????? ?? ??? ???? ?? ??? ?? ???? ?????? ??? ???????????? ?? ??? ?? ???? ?? ???? ?? ?? ?????? ????? ?? ????? ?? ?????? ?? ??? ??? ?? ????????? ???? ?? ??, ?? ????? ??, ???? ?? ???? ??? ?? ???? ?????? ?? ????????? ???? ?? ??? ????? ???

+-[Code]------------+  +.................................[COM Object]...+
|                   |  : +-------------+                                :
|Set obj = Nothing -|--->| obj pointer |                                :
|                   |  : +-|-----------+                                :
+-------------------+  :   |   +-----------------+                      :
                       :   +-->| v-table pointer |                      :
                       :       +--|--------------+                      :
                       :          |                                     :
                       :          |  +----------------------------+     :
                       :  (3rd)   |  | Function 1 Address pointer |     :
                       : (Offset) |  +----------------------------+     :
                       :          |  | Function 2 Address pointer |     :
                       :          |  +----------------------------+     :
                       :          +->| Function 3 Address pointer |     :
                       :             +----------------------------+     :
                       +................................................+

				
???? ???? ?? ???? COM ???????? ?????? ??? ?????? ?????? ??? ??? COM ???????? ?? IUnknown inherit ??, ??????? ???? ??? ???????????? ?? ?????? ??? IUnknown ???? ?? ??? ??????? ??? ???? ?? ?? ???? ???????? ?? ???? ???? ?? ???????? ??, ???? ??? ??? ????? ?????? v-?????? ??? (IUnknown::release)?

Fortunately, ?? ????? ?? ??? Visual Basic ?????? ???? ?????? ???? Visual Basic ?????????? ?? ??? ??? ??? ???? ??? ?? v-?????? ?? ??? ???? ??? ???? ?? ???? ?????, ?? ?????? ?? ?? ??? COM ???????? ????? ???, ?? ?? ?? ?? ??? ??? ???????? ?? ??? ?? ?????? ??? ?????????? ???

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

??? ?? ?????? ???? ?? early ?? ??? ??? ???? (?? ??????-v) ???????? ??? ??? COM ????????, ?? ??? ?? ??????? ?? ???????? takes ???? ?? ??? COM ???????? IUnknown ???????? ?? ??? ???? ???? ??? ????? ?? ???????? ?? ???? ?????? ?? ???? ??? ????? ???? ???? ???? ??? ???? ???? ???? ?? ???? ?????? ???? ?? ???? ???????? ?? ??? ?????????? ????? ????? ?????? ???? V-?????? ??? ???? ????? assumed ???? ???? ?? ???? ??, ??? ???? ???? ?? ??? ?????? ??? ???? ?? ??? ?????? ??????? ????

?????? ??, ????? ?? ???? ?? ?? ????? ??? ?? ???? ??? ???? v-?????? ???????? ?? ??? ??? ???? ?? ?????? ????? ??? ?? ????, ?? ????? ?? ???????? ????? ??????? ?? ???? ?????-???????? ????????? ?? ??? ??? ???? IUnknown ??????? ??? ???? ?? ?? ?? ???? "?????-????????." ?????? meant ????????: ??

???? ???????? ?? ????? ???????? ?? ????? ????, ?? ????? ??? ?? ???? ???? v-?????? ??? ?? ??? ???? ?? ???????? ??? Visual Basic ??? ?? ?? ???? ??? ??? ???? ?? ??? ?????? ????????? ????????, ???? ??????? (v-??????), ?? ???????? ?? ??? ?? ???? ??? ?? ??? ?????? ?? ????? ???? ?? ?? ?? ?????? ?????? ??????? ?? ?? ??? ??, ?? ??? ?? ?? ???? ???????? ?? ???? ??????? ??????, ???? ?? ??? ?? ??? ??? ????? ??? ??? ?? ????? ?? ???? ?? ???????? v-?????? ?? ????? ?? ??? ??? ?????? ?? ???, ??? ?? ???????? Microsoft Office Excel ????? ???????? ?? ????? ???? ?? ??? wanted, ?? ???? Project|References ????? ?? "Microsoft Excel 8.0 ???????? ?????????" ???? ?? ??? ??? ?????? ??????, ?? ???? ??? ???? ?? ?????? "Excel.application." ?? ???? ?? ??? ??? ????? ???? ??? ?? ??, ??? ??? ??? ?? ???????? ?? ???? ???? ?? ??? ???? ???? ?? ???? early ?????:
' Set reference to 'Microsoft Excel 8.0 Object Library' in
' the Project|References dialog (or Tools|References for VB4 or VBA).

' Declare the object as an early-bound object
  Dim oExcel As Excel.Application

  Set oExcel = CreateObject("Excel.Application")

' The Visible property is called via the v-table
  oExcel.Visible = True
				
?? ???? ?? ???, ????? ???? ??? ?? ???? ????? ?? ?? ??????? ??? ?? ????? ???? ????? ???? ???????? ????? ??????? ??? ???? ??? ?????? ?? ???, ??? ???? ???? Excel ?? ?? ?? ???? ??????? ?? ???, ?? ?????: "??????" ?? ???? ???????? ?? altogether ??? ???? ?? ????

Late binding

COM includes IDispatch. Objects that implement IDispatch are said to have a dispinterface (if it is the only interface they support) or dual interface (if they also have a custom interface that you can early bind to). Clients that bind to IDispatch are said to be "late bound" because the exact property or method they are calling is determined at run time using the methods of IDispatch to locate them. Going back to the book example earlier, think of it as being like a footnote that directs you to the table of contents where you have to "look up" the page number at "read time" rather than having it already printed there in the text.

The magic of the interface is controlled by two functions: GetIDsOfNames and Invoke. The first maps function names (strings) to an identifier (called a dispid) that represents the function. Once you know the ID for the function you want to call, you can call it using the Invoke function. This form of method invocation is called "late binding."

Again, in Visual Basic the way you specify how the object is bound is by your object declaration. If you declare an object variable as "Object" you are, in fact, telling Visual Basic to use IDispatch, and are therefore late binding:
' No reference to a type library is needed to use late binding.
' As long as the object supports IDispatch, the method can 
' be dynamically located and invoked at run-time.

' Declare the object as a late-bound object
  Dim oExcel As Object

  Set oExcel = CreateObject("Excel.Application")

' The Visible property is called via IDispatch
  oExcel.Visible = True
				
As you can see, the rest of your code is the same. The only difference between early binding and late binding (in terms of the code you write) is in the variable declaration.

It is important to note that what is "late bound" is the function being called and not the way it is called. From the earlier discussion on binding in general, you should notice that IDispatch itself is "early bound:" that is to say that Visual Basic makes the call to set the Visible property through a v-table entry (IDispatch::Invoke) as it would any COM call. The COM object itself is responsible for forwarding the call to the correct function to make Excel visible. This indirection allows the Visual Basic client to be compiled (that is, bound to a valid function address) but still not know the exact function that will actually do the work.

Dispid binding

Some Automation clients (most noticeably MFC and Visual Basic 3.0, but also Visual Basic 5.0 and 6.0 with respect to ActiveX Controls) use a hybrid form of late binding called dispid binding. If the COM object is known at design time, the dispids for the functions that are called can be cached and passed directly to IDispatch::Invoke without the need to call GetIDsOfNames at run time. This can greatly increase performance, because instead of making two COM calls per function, you only need to make one.

Dispid binding is not an option you can normally choose in Visual Basic 5.0 or 6.0. It is used for objects that are referenced in a type library but do not contain a custom interface (that is, for objects that have a dispinterface only) and for aggregated ActiveX Controls but, in general, Visual Basic uses early binding any place you would normally use dispid binding.

Which form of binding should I use?

The answer to this question depends as much on the design of your project as anything else. Microsoft recommends early binding in almost all cases. However, there may be reasons for choosing late binding.

Early binding is the preferred method. It is the best performer because your application binds directly to the address of the function being called and there is no extra overhead in doing a run-time lookup. In terms of overall execution speed, it is at least twice as fast as late binding.

????? ???????? ?? ?????? ?? ??????? ???? ??? ?? ???? ??? ??? ?????? ??? ?????? ????????? ?? ??? ??? ??, ?? Visual Basic ???????? ????? ?? ??? ??? ?? ??? ??? ??? ???? ?? ??? IntelliSense ?????? ???? ??? | Visual Basic ?? ???? ???? ??? ??? ???????? ?? ???? ?????? ?? ????? ??? ??? ???? ??, ?? ???? ??? ?????? ?? ???? ?? ??? ?? ?? ??? ???? ?????

??? ???????? ???? ?? ???????? ?? ???? ??????? ????? ???? ?? ??????-??? ?? ????????? ??? ??? ?? ?????? ??? ??? ???? ????????? seeks ?????? ????? ?? ?????? ?? ?????? ?? ??? (Visual Basic 6.0 ?? ????? ?? ??????? ???? ?? ??? ???????? ?? ??? ??? ???? ?? ???CallByName?????? ?? ??? ???) ?? ?? ??? ???????? ?? ????? ???? ?? ???????? ??? ??? ???????? ?? ?? ??? ?? ?? improperly ??????? ?? ???? ??????? ????????? ?? ??? adapted ??? ?? ?? ???? ????????? ?? ??? ?????? ???????? ?? ?? ???? ?? ??? ?????? ???

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

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

??? ?? ????? ????? ???? ?? ?? ?? ??? ?? ?? ???? ???? ????? ????? ?? ??? ??????????? ????, ?? ?? ????? ?? ?? ????? ??????? ??-????, ?? ??? ???????? ?? ??? ?? (??? ?????? ???) ??? ??? ????????? ?? ??? ???? ?? ?? ???? ?? ??? ????? ????? ????? ????? ???? ?? ??? ?????? ???? ????? ??? ??????? ?? assured ???? ??? ?? ????? ??????? ????? ?? ?? ???? ??????? ?????? ?? ??????? ??????? ??? ????? ???? ?? ??? gracefully ???? ?? ???? ?? ?? ?? ?????? ?? ??? ???? ?? ??? ??? ???????? ?? ????? ?????

Microsoft Office ??????????? ??? ??? COM ??????? ?? ?? ????? ?????? ???? Office ????????? ?????????? ?? ??????????? ?? ??? ????? shortcomings ????????? ?? ??? ??? ?????? ?? ??? ???? ???????? ?? ??????? ???? ?????? ??? ?? ???? Office ????????? ?? ???????? ???? ?? ???????? ??, ?? ?? ??????? ?? ???? ?? ?? ?? early ?? ??? ????? ??????????? ??????? ?? ?????? ?? ?? ???? ??????? ??????? ?? ?????? ?? ??????? ???? ?? ???? ?? ?????? ?? ???, ???? Excel 95, Excel 97, Excel 2000 ?? Excel 2002 ?? ???????? ???? ??? ????? ??, ??? ?? ????? ???? ????? ?????? ????????? Excel 95 (XL5en32.olb) ?? ??? ??? ??? ????????? ?? ??? ?????? ???? ???? ?? ????

Office ????????? ?? demonstrate ?? ?? ??? ????? ??????? ?? ???????? ???? ?? ??? ???????????? marshalling ??? ?????? suffer ?? ???? ???? ??? ???????????? ?? ??? ??????? ?? ????? ???? ?? ??? ???? ??? ?? ??? IDispatch ?? ????? ?????Office ?? ??? ????? ???? ??? ?????? ???? ???? ?? ???? ??????? ?? ??? ????????? ?? ???, Microsoft ???????? ??? ???? ????? ?? ??? ????? ???? ?????? ?? ????? ????:
247579?? ???? ?? ?? Office ??????????? ?? ???????? ???? ?? ??? DISPID ???????? ?? ????? ????

??????

COM ?? ???? ??? ???? ??????? ?? ??? v-??????, ??, ??????? ?? ????? ?? ??? ?? ????? ????? ????? ????????:
Rogerson, Dale,?????? COMMSPRESS, ISBN: 1-57231-349-8?

Curland, Matt,????? Visual Basic 6DevelopMentor, 0201707128?

???

???? ID: 245115 - ????? ???????: 03 ?????? 2010 - ??????: 2.0
???? ???? ???? ??:
  • Microsoft Office Ultimate 2007
  • Microsoft Office Enterprise 2007
  • Microsoft Office Professional 2007
  • Microsoft Office Professional Plus 2007
  • Microsoft Office Standard 2007
  • Microsoft Office Home and Student 2007
  • Microsoft Office Basic 2007
  • Microsoft Office XP Developer Edition
  • Microsoft Office 2000 Developer Edition
  • Microsoft Visual Basic 5.0 Professional Edition
  • Microsoft Visual Basic 6.0 Professional Edition
  • Microsoft Visual Basic 5.0 Enterprise Edition
??????: 
kbautomation kbinfo kbmt KB245115 KbMthi
???? ?????? ????????
??????????: ?? ???? ?? ???? ??????? ?? ????? ?? Microsoft ????-?????? ?????????? ?????? ?????? ???? ??? ??. Microsoft ???? ??? ????-???????? ?? ????-???????? ????? ?????? ?? ???? ???????? ???? ?? ???? ????? ????? ??? ?? ??? ?????? ?? ???? ???? ???? ??? ????? ??. ???????, ????-???????? ???? ????? ???? ???? ???? ???. ?????, ????????, ?????-???? ?? ??????? ?? ???????? ?? ???? ???, ???? ?? ??? ?????? ???? ???? ??? ????? ??? ?? ???? ??. Microsoft ??????? ??? ???? ?? ?????? ?? ??????????, ????????? ?? ??? ?????? ?? ???? ????? ?? ???? ???????? ?? ??? ???? ????? ?? ??? ????????? ???? ??. Microsoft ????-?????? ?????????? ?? ????? ?????? ?? ?? ??? ??.
?????????? ?? ??????? ????????? ??????? ??:245115

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

 

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