Define Class Application As Session OlePublic Procedure Init EndProc Procedure MyTestProc(tcStringToShow As String) As Boolean *!* This is a test method. The code entered here will be *!* executed from Exe's inner classes, under user's interaction. EndProc EndDefineBuild this as Win32 Executable / COM Server (exe). Then run this piece of code: (vfpcomtest.prg):
Local oComObject, oEventsReceiverClass oComObject = CreateObject("Comtest.Application") oEventsReceiverClass = NewObject("myclass") llResult = EventHandler(oComObject, oEventsReceiverClass) MessageBox("Result of EventHandler(): " + Transform(llResult)) Define Class myclass As Session OlePublic Implements Iapplication In "comtest.Application" Procedure Iapplication_MyTestProc(tcStringToShow As String ) As LOGICAL * add user code here - this code is supposed to be executed automatically * whenever COM's MyTestProc procedure is executed. EndProc EndDefineAs you can see, the EventHandler() function refuses to bind the VFP COM to the local class which implements the interface. However, when I do _exactly_ the same thing with a non-VFP COM server / ActiveX, it works. Here's the example (nonvfpcomtest.prg - I have used MSComm activex control in this test):
Local oComObject, oEventsReceiverClass oComObject = CreateObject("MSCommLib.MSComm") oEventsReceiverClass = NewObject("myclass") llResult = EventHandler(oComObject, oEventsReceiverClass) MessageBox("Result of EventHandler(): " + Transform(llResult)) Define Class myclass As Session OlePublic Implements DMSCommEvents IN "MSCommLib.MSComm" Procedure DMSCommEvents_OnComm() As VOID; HELPSTRING "Occurs whenever the value of the CommEvent property changes." * add user code here EndProc EndDefineCan anyone, please, explain why is this, what I am missing and how can I achieve the ability to get some local code executed automatically whenever a method in VFP COM is executed? I have already wasted 3 days with this and I'm going nowhere. The boss gets nervous :(