Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Does CreateObject('MSMQ.MSMQEvent') ever work?
Message
De
29/01/2013 09:41:48
 
 
À
28/01/2013 14:34:10
Information générale
Forum:
Visual FoxPro
Catégorie:
COM/DCOM et OLE Automation
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows 7
Divers
Thread ID:
01564356
Message ID:
01564498
Vues:
46
>>>Hello All,
>>>
>>>I have been trying to get a VFP app to use MSMQ (Message Queuing). I have read the article from Microsoft http://msdn.microsoft.com/en-us/library/ms917361.aspx and downloaded the sample code. Using this code, I can see the queue, read the messages, etc. What I can't get to work is MSMQEvent (example below).
>>>
>>>o = CreateObject('MSMQ.MSMQEvent') returns an empty object.
>>>
>>>Has anyone ever used this successfully in VFP? Maybe it has never worked. So far all I've been able to find is an unanswered post on Foxite from 2002 by Steve Craft.
>>>
>>>If anyone can just confirm whether this will ever work with VFP or not I'd greatly appreciate it.
>>>
>>>This is straight from the MS site...
>>>
>>>Working with MSMQ Events and Asynchronous Message Reading
>>>
>>>Applications such as Visual Basic® allow you to bind to events of COM objects. Visual FoxPro 6.0 supports this with ActiveX controls, but not with COM objects such as an ADO Recordset. This means you will not have the ability to bind a VFP object to a COM object and have user code executed when an event of the COM object is triggered.
>>>The new VFPCOM utility (see above) addresses this critical need. You can now have VFP code executed when a message arrives in a particular queue. MSMQ triggers an event that VFP can respond to. The advantage here is that your application can now handle reading messages in the queue asynchronously. Instead of having some object using up lots of processor time consumed in an endless DO WHILE loop, you can have your dormant objects awaken only when a message arrival event occurs.
>>>The process of setting up a queue for asynchronous reading of messages is as follows:
>>>Create your VFP MSMQ events class to handle reading of messages as they arrive in queues. This class needs to contain Arrived and ArrivedError methods to handle the message arrival events.
>>>Use VFPCOM to bind an instance of your VFP MSMQ events class to an instance of an MSMQEvent object. This is done with VFPCOM’s BindEvents method.
>>>Open the queue and call its EnableNotification method passing the MSMQEvent object you just setup with BindEvents.
>>>Note You must leave the queue open and the BindEvents call intact, otherwise your event connection loses scope and will fail.
>>>The following class definition is a sample template that can be used for your event binding. Notice that you can use the AppSpecific property to special case handling for certain messages.
>>>DEFINE CLASS foxevent AS custom
>>> Procedure Arrived(oQueue,Cursor)
>>> oMsgRec = oQueue.PeekCurrent(,,0)
>>> ? “Message Arrived Event: “+TRANS(oMsgRec.AppSpecific)
>>> IF oMsgRec.AppSpecific = 33 &&get only this one
>>> oMsgRec = oQueue.ReceiveCurrent(,,,0)
>>> oMsgRec = oQueue.PeekCurrent(,,0)
>>> oQueue.EnableNotification(oMSMQEvent,MQMSG_CURRENT,1000)
>>> ELSE
>>> oQueue.EnableNotification(oMSMQEvent,MQMSG_NEXT,1000)
>>> ENDIF
>>> ENDPROC
>>>
>>> Procedure ArrivedError(Queue,ErrorCode,Cursor)
>>> ? “Message Arrived Error”
>>> ENDPROC
>>>ENDDEFINE
>>>Once you have your class defined, you can set things up for asynchronous reading of messages. The remainder of the code below shows how to set up the event handler. This is also a simple way to test the event handling by adding a bunch of messages.
>>>* Setup up event handler to receive the messages
>>>oMSMQEvent = create(“msmq.msmqevent”)
>>>oComUtil = create(“vfpcom.comutil”)
>>>oFoxEvents = create(“foxevent”)
>>>oComUtil.BindEvents(oMSMQEvent,oFoxEvents)
>>>oRecQueue = oQueueInfo.Open(MQ_RECEIVE_ACCESS,MQ_DENY_NONE)
>>>oRecQueue.EnableNotification(oMSMQEvent,MQMSG_CURRENT,1000)
>>>
>>>* Add a bunch of new message
>>>oSendQueue = oQueueInfo.Open(MQ_SEND_ACCESS, MQ_DENY_NONE)
>>>oMsg = create(“msmq.msmqmessage”)
>>>oMsg.AppSpecific = 11
>>>oMsg.Send(oSendQueue)
>>>oMsg.AppSpecific = 22
>>>oMsg.Send(oSendQueue)
>>>oMsg.AppSpecific = 33
>>>oMsg.Send(oSendQueue)
>>>oMsg.AppSpecific = 44
>>>oMsg.Send(oSendQueue)
>>>oMsg.AppSpecific = 55
>>>oMsg.Label = “Message55”
>>>oMsg.Body = “This is body of message 55.”
>>>oMsg.Send(oSendQueue)
>>>oSendQueue.Close
>>
>>
>>Check Event Binding for COM Objects in HELP.
>
>
>I replaced oComUtil.BindEvents(oMSMQEvent,oFoxEvents)
>
>with
>
>EventHandler(oMSMQEvent, oFoxEvents)
>
>and get the error " EventHandler object FOXEVENT does not IMPLEMENT an interface". I read up on Define Class IMPLEMENTS but quite honestly this is all way over my head. I've also looked through some of my old VFP books (Office Automation, What's New in Nine, 1002 things...), no luck there either.
>
>Any additional help would be greatly appreciated.

See if this article helps you understand IMPLEMENTS and EventHandler(). The right book for it is "What's New in VFP 7."

Tamar
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform