implements iDemoEvents in idemo.dllI can't see where the iDemoEvents interface is defined. And, in the sample IDEMO.PRG, the cCallBack class is instantiated before the iDemo COM server.
CLEAR ALL IF PROGRAM() != "IDEMO" ?"this file MUST BE NAMED 'idemo.prg'" RETURN ENDIF IF .t. IF FILE("idemo.dll") DECLARE integer DllUnregisterServer IN idemo.dll DllUnregisterServer() CLEAR DLLS ENDIF BUILD PROJECT idemo FROM idemo BUILD DLL idemo from idemo recomp endif clear oCallback = NEWOBJECT("cCallback") && the event callback ostock=newOBJECT("idemo.idemo") && the business COM obj ostock.setcallback(oCallBack) && like BindEvents ?ostock.BuyStock("MSFT",10000 ) && invoke a method ostock.setcallback(.null.) && like UnBindEvents ?ostock.BuyStock("MSFT",20000 ) && this one doesn't fire events *This is the actual implementation of the event interface DEFINE CLASS cCallback as session implements iDemoEvents in idemo.dll procedure iDemoEvents_BeforeBuyStock(cStock as String, qty AS Number) ?program(),cstock,qty procedure iDemoEvents_AfterBuyStock(cStock as String, qty AS Number) ?program(),cstock,qty enddefine *the rest of this file is used in the COM server DEFINE CLASS idemo as session olepublic oc = .null. PROCEDURE init this.SetCallBack(.null.) && set callback to default PROCEDURE setcallback(oC as Variant) IF ISNULL(oc) && dummy instance that does nothing: virtual function this.oc = NEWOBJECT("DemoEvents") else IF VARTYPE(oc) != 'O' COMRETURNERROR(PROGRAM(),"callback must be obj") ENDIF this.oc = GETINTERFACE(oC,"iDemoEvents","idemo.idemo") endif procedure MyDoCmd(cCmd as String) as Variant &cCmd procedure MyEval(cExpr as String) as Variant return &cExpr procedure BuyStock(cStock as String, qty AS Number) as Boolean this.oc.BeforeBuyStock(cStock, qty) *here we buy the stock this.oc.AfterBuyStock(cStock, qty) FUNCTION Error(nError, cMethod, nLine) COMreturnerror(cMethod+' err#='+str(nError,5)+' line='+; str(nline,6)+' '+message(),_VFP.ServerName) && this line is never executed enddefine *Just an interface definition that should be implemented by outside callers DEFINE CLASS DemoEvents as session olepublic procedure BeforeBuyStock(cStock as String, qty AS Number) procedure AfterBuyStock(cStock as String, qty AS Number) enddefine