FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour How to receive events from objects?
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: How to receive events from objects?
Posted: Mon Jun 16, 2014 01:31 AM

And here an example of use:

__axRegisterHandler( o:__hObj, {| ... | MsgInfo( ... ) } )

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 52
Joined: Thu Mar 22, 2012 05:43 PM
Re: How to receive events from objects?
Posted: Mon Jun 16, 2014 06:14 AM

Antonio,

The topic was posted sometime in 2008. :)

Sounds great that it is there, but I'm getting a link error :(.

What is the library file and where to get the MyInclude.ch?

BTW I used it this way: oOle:=OleWEvent():New(cProgId)

Regards, Saludos

Jose

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: How to receive events from objects?
Posted: Mon Jun 16, 2014 07:40 AM

Jose,

As I have explained, it seems as you don't need that library at all :-)

Simply try to use this:
__axRegisterHandler( o:__hObj, {| ... | MsgInfo( ... ) } )

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 52
Joined: Thu Mar 22, 2012 05:43 PM
Re: How to receive events from objects?
Posted: Mon Jun 16, 2014 08:27 AM

Antonio,

I didn't notice the info on the second page. I tried to follow the code in the prg sample. :)

But my application terminated after the Alert("here") :(

Error -2147220992 WINOLE/1014 Failed to obtain connection point: __AXREGISTERHANDLER Args: (P:0x484EA9C) (B:{|| ... })

Thanks,

Jose

Method Instantiate_Device(cProgID) class OPOSHardwareInterface
local oOle:='',n
::lDeviceInstantiated:=.f.
oOle:=CreateObject(cProgID)
if valtype(oOle)='O'
::lDeviceInstantiated:=.t.
alert('Here')
__axRegisterHandler( oOle:__hObj, {| a,b,c | MsgInfo( 'Test') }) && What are the parameters of the codeblock?
aadd(::aoDevices,oOle)
* aadd(::aoDevices,oOle:oOleAuto)
endif
return oOle

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: How to receive events from objects?
Posted: Mon Jun 16, 2014 08:49 AM

Please check this value:

MsgInfo( oOle:__hObj )

and let me know it

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 52
Joined: Thu Mar 22, 2012 05:43 PM
Re: How to receive events from objects?
Posted: Mon Jun 16, 2014 02:44 PM

The valtype (oOle:__hObj) is P

The value differs as shown below.

OS Error -2147220992 WINOLE/1014 Failed to obtain connection point: __AXREGISTERHANDLER Args: (P:0x2CDAD04)
OS Error -2147220992 WINOLE/1014 Failed to obtain connection point: __AXREGISTERHANDLER Args: (P:0x30DA6CC)

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: How to receive events from objects?
Posted: Mon Jun 16, 2014 03:28 PM
Jose,

Please try suplying the third parameter: cIID

function __AXREGISTERHANDLER( pDisp, bHandler [, cIID] ) --> pSink

What are the parameters of the codeblock?


"..." means "whatever it is supplied". We may get different amount of params for an event based on the used OLE object.
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 52
Joined: Thu Mar 22, 2012 05:43 PM
Re: How to receive events from objects?
Posted: Mon Jun 16, 2014 07:11 PM

Antonio,

What is cIID?

If cIID is the ole program ID (cProgID in my code) then I tried that and my up terminated.

error: WINOLE/1014 Failed to obtain connection point: __AXREGISTERHANDLER Args: (P:0x473A43C) (B:{|| ... }) (C:OPOS.POSPrinter)

Thanks,

Jose

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: How to receive events from objects?
Posted: Mon Jun 16, 2014 09:58 PM

Jose,

have you started the cIID with '{' ?

It must start with '{' and end with "}"

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 52
Joined: Thu Mar 22, 2012 05:43 PM
Re: How to receive events from objects?
Posted: Tue Jun 17, 2014 02:27 AM

Hi Antonio,

What is {cIID}? A new syntax? Looks like an array..

Anyway I tried both as shown below and still resulted to the same error

Thanks,

Jose

Method Instantiate_Device(cProgID) class OPOSHardwareInterface
local oOle:='',n,cIID
::lDeviceInstantiated:=.f.
oOle:=CreateObject(cProgID)
if valtype(oOle)='O'
::lDeviceInstantiated:=.t.
alert(valtype(oOle:__hObj))
alert('Here')
*__axRegisterHandler( oOle:__hObj, {| ...| MsgInfo( 'Test') },{cProgID}) && What are the parameters of the codeblock?
__axRegisterHandler( oOle:__hObj, {| ...| MsgInfo( 'Test') },{cIID}) && What are the parameters of the codeblock?
alert('Done')
aadd(::aoDevices,oOle)
* aadd(::aoDevices,oOle:oOleAuto)
endif
return oOle

Posts: 52
Joined: Thu Mar 22, 2012 05:43 PM
Re: How to receive events from objects?
Posted: Tue Jun 17, 2014 02:55 AM

Antonio,

Do I need to include the oleWEvents0.c and oLeWEvents.prg to my App?

Thanks,

Jose

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: How to receive events from objects?
Posted: Tue Jun 17, 2014 05:27 AM
Jose,

You don't have to include those files in your app.

Here you can read about cIID:
cIID
Specifies the Interface ID GUID of cCLSID | cPROGID when you create an early bound instance of the class. If you pass an empty string as cIID Visual FoxPro attempts to access the default interface (IID) of cCLSID | cPROGID.
Example

x = CREATEOBJECTEX("excel.application","",;
"{000208D5-0000-0000-C000-000000000046}")


The "{" and "}" are part of the name. They are not related to arrays, etc.

We are not going to use it (like the above example) in CreateObject(). We just use it from __axRegisterHandler()
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 52
Joined: Thu Mar 22, 2012 05:43 PM
Re: How to receive events from objects?
Posted: Tue Jun 17, 2014 08:19 AM
Antonio,

OK, I found cIID, but still got the following error. I also send you a screen shot of my COM viewer where I got cIID (I can't find attach option here). Please check. Thanks.

Error: OS Error -2147220992 WINOLE/1014 Failed to obtain connection point: __AXREGISTERHANDLER Args: (P:0x484F564) (B:{|| ... }) (C:{B196B284-BAB4-101A-B69C-00AA00341D07})

Thank you,

Jose

Code (fw): Select all Collapse
Method Instantiate_Device(cProgID) class OPOSHardwareInterface
local oOle:='',n
local ciid:='{B196B284-BAB4-101A-B69C-00AA00341D07}'  && <-- IconnectionPointContainer
::lDeviceInstantiated:=.f.
oOle:=CreateObject(cProgID)
if valtype(oOle)='O'
    ::lDeviceInstantiated:=.t.
if cprogid='OPOS.POSPrinter'
alert(ciid)
__axRegisterHandler( oOle:__hObj, {| ...| MsgInfo( 'Test') },ciid) && <-- IconnectionPointContainer
alert('Handler registered')
endif
    aadd(::aoDevices,oOle)
endif
return oOle
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: How to receive events from objects?
Posted: Tue Jun 17, 2014 11:06 AM
Jose,

Welcome to the nightmare of the OLE objects... :-S

Here you have the source code for __AXREGISTERHANDLER()

https://github.com/harbour/core/blob/master/contrib/hbwin/axcore.c

Check its code please, you will see there are just two places where it is checked. If it does not work, then I am afraid that very little we can do, except if you contact that OLE tech support service and show them the source code (in axcore.c) that you are using.
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 52
Joined: Thu Mar 22, 2012 05:43 PM
Re: How to receive events from objects?
Posted: Tue Jun 17, 2014 07:41 PM

Antonio,

I agree, this might be beyond Harbour as Carlos was successful using this function with a different OLE service.

Or may be it's just the version of my compiler.

I am still using Harbour 2.1. I checked the logs and there was many changes related to axcore.c to date. I hope one of these changes fixed this issue..

Thank you for your support. I appreciate it. :)

Saludos,

Jose