Page 2 of 3

Re: How to receive events from objects?

PostPosted: Mon Jun 16, 2014 1:31 am
by Antonio Linares
And here an example of use:

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

Re: How to receive events from objects?

PostPosted: Mon Jun 16, 2014 6:14 am
by Jose Dolar
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

Re: How to receive events from objects?

PostPosted: Mon Jun 16, 2014 7:40 am
by Antonio Linares
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( ... ) } )

Re: How to receive events from objects?

PostPosted: Mon Jun 16, 2014 8:27 am
by Jose Dolar
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

Re: How to receive events from objects?

PostPosted: Mon Jun 16, 2014 8:49 am
by Antonio Linares
Please check this value:

MsgInfo( oOle:__hObj )

and let me know it

Re: How to receive events from objects?

PostPosted: Mon Jun 16, 2014 2:44 pm
by Jose Dolar
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)

Re: How to receive events from objects?

PostPosted: Mon Jun 16, 2014 3:28 pm
by Antonio Linares
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.

Re: How to receive events from objects?

PostPosted: Mon Jun 16, 2014 7:11 pm
by Jose Dolar
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

Re: How to receive events from objects?

PostPosted: Mon Jun 16, 2014 9:58 pm
by Antonio Linares
Jose,

have you started the cIID with '{' ?

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

Re: How to receive events from objects?

PostPosted: Tue Jun 17, 2014 2:27 am
by Jose Dolar
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

Re: How to receive events from objects?

PostPosted: Tue Jun 17, 2014 2:55 am
by Jose Dolar
Antonio,

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

Thanks,

Jose

Re: How to receive events from objects?

PostPosted: Tue Jun 17, 2014 5:27 am
by Antonio Linares
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()

Re: How to receive events from objects?

PostPosted: Tue Jun 17, 2014 8:19 am
by Jose Dolar
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: Select all  Expand view
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

Re: How to receive events from objects?

PostPosted: Tue Jun 17, 2014 11:06 am
by Antonio Linares
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.

Re: How to receive events from objects?

PostPosted: Tue Jun 17, 2014 7:41 pm
by Jose Dolar
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