Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Comm Port access
Message
General information
Forum:
Visual FoxPro
Category:
Object Oriented Programming
Miscellaneous
Thread ID:
00231862
Message ID:
00231971
Views:
98
>Ed
>I have heard of using a wrapper for the vfpcom.dll. I guess I am having trouble writting it. Do I replace mscommlib.mscomm with vfpcom.dll. Would you have some code hints?

Sure; it's actually not tough to do at all. There are three objects involved in getting the wrapper to work; the COM object itself, a VFP native class containing code for each event youy want to handle, and VFPCOM, which glues the two together. You'll need to create an instance of the MSCOMM control, an instance of your wrapper class, and an instance of VFPCOM.Comutil. Your wrapper will be used to expose the OnComm Event. You need to do the following to get your wrapper to respond to the OnComm event:

oMSCOMM = CREATEOBJ('MSCommlib.MSComm')
oMyWrapper = CREATEOBJ('MyOnCommEventWrapper')
oVFPCOM=CREATEOBJ('VFPCOM.ComUtil')
oVFPComm.BindEvents(oMSCOMM,oMyWrapper)

An OnComm event in the MSComm32 COM Object will trigger the OnComm method code in your wrapper class, which now can determine how to deal with the event with VFP Code. Once the port is open, you can respond to receive and send events without continuously polling. You'll want to take a look at the VFPCOM.HTM Help file that is extracted when you install VFPCOM, and the sample VB code for the MSCOMM32 control event topic to see simple examples of event handling with the MSCOMM32 control; the translation from VB to VFP is pretty straightforward.

In the case of the MSCOMM Control, there's only one event to worry about; VFPComm can be used to export a shell program to serve as the basis for a non-visual VFP class:

oMSCOMM = CREATEOBJ('MSCommlib.MSComm')
oVFPCOM=CREATEOBJ('VFPCOM.ComUtil')
oVFPComm.ExportEvents(oMSCOMM,'MyWrapper.PRG')

The exported class from VFPCOM for MSCommlib.MsComm is pretty simple:
DEFINE CLASS DMSCommEvents AS custom


	PROCEDURE OnComm
	* Add user code here
	ENDPROC


ENDDEFINE
You still need to get handshaking etc. right for your comm app; this just makes it easy to attach VFP code to a COM event.

hth,
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform