Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Andy Kramek
  Where is Andy Kramek?
 Hot Springs Village
 Arkansas - United States
 Andy Kramek
 To: DENNIS JONES
  Where is DENNIS JONES?
 salina
 Kansas - United States
 DENNIS JONES
 Tags
Subject: RE: Call DLL IN VFP
Thread ID: 153655 Message ID: 155041 # Views: 7 # Ratings: 3
Version: Visual FoxPro 9 Category: Classes and Objects
Date: Saturday, December 22, 2007 11:40:09 AM         
   


Hi Dennis

> IDispatch and IUnknown are methods present in all COM objects,

Sorry to disagree with you but this is simply not true. They are actually only present in COM objects that are defined as "Automation Servers". In fact it is actually their presence which defines a COM object as an "automation server". Here is the definition from WikiPedia:

IDispatch is the interface that exposes the OLE Automation protocol. It is one of the standard interfaces that can be exposed by COM objects. The I in IDispatch refers to interface. COM distinguishes between three interface types: custom, dispatch and dual interfaces.
IDispatch derives from IUnknown and extends its set of three methods (AddRef, Release and QueryInterface) with an additional four methods – GetTypeInfoCount, GetTypeInfo, GetIDsOfNames and Invoke.


> yet It has been my experience that CreateObject() often fails with controls which work fine in VB6.

The issue with VB instantiation is usually that the COM object was not defined an automation server. This is one of the key differences between VB6 and VFP and arises because VB6 IS early bound and therefore can handle all three types of COM interface. VFP is not early bound and can only handle Dispatch and Dual (Note: and this is only because Dual interface objects expose BOTH iDispatch AND a vTable interface). Hence things that work under VB may not work under VFP because they simply do not expose the necessary interface!

>> While the Declare statement along with CreateObjectEx does work with Microsoft API's, it requires knowledge about the dll's methods and parameters ahead of time.

Exactly - and, again, this is the because there are different types of COM interface! Those that expose iDispatch can be handled directly by VFP, those that do not, MAY be usable through Early Binding (i.e. using CREATEOBJECTEX with the explicit interface id) or through the Windows API interfaces (i.e. using DECLARE). In both cases you, the programmer, need to know the exact method signature and code it accordingly.

> The class generated by dragging and dropping an interface from the Object Broswer is in fact doing something unique. Perhaps it is early binding to the control, whatever, it lets me get on with life instead of fussing over how to code a Delcare statement which may not be appropriate for the control anyway.

I am sorry to disappoint you but it is NOT doing anything "unique". All (and I use the term 'all' loosely because Markus Egger's code in the Object Browser is extremely efficient and does some very cool stuff reading the type library under the hood) that it is doing is creating the IMPLEMENTS statement from the information in the Type Library of the specified component. If there is no type library, as in Windows DLLs and non-Automation COM objects, then it simply won't work!

This discussion started because of a reference to a DLL which implements a "custom" interface and this is why your methodology would not succeed in this specific case.

Regards
Andy Kramek
Microsoft MVP (Visual FoxPro)
Tightline Computers Inc, Akron Ohio, USA

ENTIRE THREAD

Call DLL IN VFP Posted by Paul Newman @ 12/6/2007 7:04:52 PM
RE: Call DLL IN VFP Posted by DENNIS JONES @ 12/20/2007 12:22:28 AM
RE: Call DLL IN VFP Posted by Andy Kramek @ 12/20/2007 12:06:21 PM
RE: Call DLL IN VFP Posted by DENNIS JONES @ 12/20/2007 8:04:41 PM
RE: Call DLL IN VFP Posted by Andy Kramek @ 12/20/2007 9:38:33 PM
RE: Call DLL IN VFP Posted by DENNIS JONES @ 12/21/2007 12:40:19 AM
RE: Call DLL IN VFP Posted by Andy Kramek @ 12/21/2007 12:48:10 PM
RE: Call DLL IN VFP Posted by DENNIS JONES @ 12/21/2007 11:53:54 PM
RE: Call DLL IN VFP Posted by Andy Kramek @ 12/22/2007 11:40:09 AM