top of page
Search
nathanaelkmw

Visual Foxpro Winsock Example Program: A Comprehensive Reference for Winsock Functions and Data Stru



So if you want to go client server, go client server, go MSSQL. Don't go fro winsock and starting from scratch with all communication and protocol necessary. Want to go for a simple interface just pushing in DBF files to the tablets. Fine, that's a prorietary solution, but you won't be able to use remote views then, you have to program the update of server side tables with something else, too. You're aiming for a proprietary solution only working for you, then.




Visual Foxpro Winsock Example Program



using the following code I try to get the IP addresss * Get_Card_IP Local n ows = createobject("mswinsock.winsock") if Type("ows")="O" n=ows.LocalIP Release ows Else n="" Endif Return(n) But I get the error message OLE error code etc etc: Class is not licensed for use. MsWinsck.ocx comes with VFP. How do I bypass this problem ? Demetrios, Greece Thu, 04 Nov 2004 01:41:04 GMT Demetrios Panayotakopoulo#2 / 8 Class not registered problem Hi Hamian, I was about to send the following e-mail when I found yours. I am very confused on how Microsoft treats some controls. Others work with no problem and others need special handling. After more than a day search, tryial and error and havinv read the Article Q192693 I managed it. Here is how. 1. Create Class [Enter] 2. Class Name: I typed WinSock (just to remember. It could be TEST) 3. Based On: Selected OleControl 4. Store In: I typed MyClasses. 5. Click OK 6. After a few seconds Insert Object window appears 7. Choose: Insert Control 8. ObjectType: Microsoft WinSock Control, version 7.0 9. Click OK 10. A "form like" object appears with the control in it. Close and save. 11. Create a form Test 12. At the INIT write down: ThisForm.NewObject('WinSock', 'WinSock', 'MyClasses.vcx') MyIpAddress=ThisForm.WinSock.LocalIP ... that's it 13. Don't forget to include MyClasses.vcx in your project. If you had select TEST as class Name the above would become: ThisForm.NewObject('WinSock', 'Test', 'MyClasses.vcx') The first parameter is the name of the object you want to create. So it could be: ThisForm.NewObject('oMyWinSock', 'Test', 'MyClasses.vcx') MyIpAddress=ThisForm.oMyWinSock.LocalIP The problem is that I can not use the control in a program. I have to create a form. So in order to get the IP address that what I actually did was: in the form's INIT Public MyIpAddress MyIpAddress="" ThisForm.NewObject('WinSock', 'WinSock', 'MyClasses.vcx') MyIpAddress=ThisForm.WinSock.LocalIP Return .F. && so the form will not appear. If someone of the VFP gurus could help me create a better solution I would appreciate. I hope that the above will also help others, having similar problems. Demetrios, Greece Quote:> Hi Demetrios > If the MSWinSock is ActiveX control ( not just automation > object ) you can try to put it onto OleBoundControl > visually, it seems that FoxPro forms somehow manage > licesing of MS ActiveX controls. If it not help you can > check which registry entries MSWinSock control tries to > access on initialisation ( with some Registry monitoring > tool ) and put this to clients computer regisrty ( but I > don't know if it would be legal ) > I have experienced similar problem with MSComm32 , and the > explanations that I found on Microsoft Web pages and in > these groups, confused me and astonished even more. > This has to be some kind of mess from Microsoft, I think > Damian() computer_2(); Sat, 06 Nov 2004 12:18:04 GMT Demetrios Panayotakopoulo#3 / 8 Class not registered problem Sorry, I meant Damian. I just noticed I mistyped. Sorry Again Demetrios, Greece Quote:> Hi Hamian, > I was about to send the following e-mail when I found yours. > I am very confused on how Microsoft treats some controls. > Others work with no problem and others need special handling. > After more than a day search, tryial and error and havinv read the Article > Q192693 I managed it. > Here is how. > 1. Create Class [Enter] > 2. Class Name: I typed WinSock (just to remember. It could be TEST) > 3. Based On: Selected OleControl > 4. Store In: I typed MyClasses. > 5. Click OK > 6. After a few seconds Insert Object window appears > 7. Choose: Insert Control > 8. ObjectType: Microsoft WinSock Control, version 7.0 > 9. Click OK > 10. A "form like" object appears with the control in it. Close and save. > 11. Create a form Test > 12. At the INIT write down: > ThisForm.NewObject('WinSock', 'WinSock', 'MyClasses.vcx') > MyIpAddress=ThisForm.WinSock.LocalIP > ... > that's it > 13. Don't forget to include MyClasses.vcx in your project. > If you had select TEST as class Name the above would become: > ThisForm.NewObject('WinSock', 'Test', 'MyClasses.vcx') > The first parameter is the name of the object you want to create. > So it could be: > ThisForm.NewObject('oMyWinSock', 'Test', 'MyClasses.vcx') > MyIpAddress=ThisForm.oMyWinSock.LocalIP > The problem is that I can not use the control in a program. I have to create > a form. > So in order to get the IP address that what I actually did was: > in the form's INIT > Public MyIpAddress > MyIpAddress="" > ThisForm.NewObject('WinSock', 'WinSock', 'MyClasses.vcx') > MyIpAddress=ThisForm.WinSock.LocalIP > Return .F. && so the form will not appear. > If someone of the VFP gurus could help me create a better solution I would > appreciate. > I hope that the above will also help others, having similar problems. > Demetrios, Greece > > Hi Demetrios > > If the MSWinSock is ActiveX control ( not just automation > > object ) you can try to put it onto OleBoundControl > > visually, it seems that FoxPro forms somehow manage > > licesing of MS ActiveX controls. If it not help you can > > check which registry entries MSWinSock control tries to > > access on initialisation ( with some Registry monitoring > > tool ) and put this to clients computer regisrty ( but I > > don't know if it would be legal ) > > I have experienced similar problem with MSComm32 , and the > > explanations that I found on Microsoft Web pages and in > > these groups, confused me and astonished even more. > > This has to be some kind of mess from Microsoft, I think > > Damian() Sat, 06 Nov 2004 12:31:13 GMT Rick Bea#4 / 8 Class not registered problem Demetrios, This "problem" is a variant (different OCX) of the one described in =kb%3Ben-us%3BQ139154 - "INFO: OLE Control Licensing in Visual FoxPro (Q139154)". The final example shows a way around the problem. You may want to also read =kb%3Ben-us%3BQ192693 - "BUG: License Error with ActiveX Control Added at Run-Time (Q192693)" For some actual code, the following is currently working just fine in many locations (VFP 6.0 SP5). Basically, because the VCX does the direct usage of Winsock, and it's precompiled, it doesn't create a license problem! It's a simple procedure that uses Winsock to get the IP address. (Andy is one of our programmers.) * Program....: GETIP.PRG * Version....: 1.0 * Author.....: ** Andy Goeddeke ** * Date.......: January 8, 2002 * Return IP address as char string * 02/04/2002 Changed the technique slightly to avoid the "Class not registered/licensed" errors. *!* The following DOESN'T work! *!* LOCAL loWinsock *!* loWinSock = CREATEOBJECT("MSWinsock.Winsock") *!* return loWinsock.LocalIP LOCAL oForm1, lcIP oForm1 = CREATEOBJECT("dummyform") lcIP = oForm1.Olecontrol1.LocalIP RELEASE oForm1 RETURN lcIP ************************************* DEFINE CLASS dummyform AS form DoCreate = .T. Caption = "dummyform" Name = "dummyform" PROCEDURE INIT IF .F. ** This sucks the class into the project automatically. SET CLASS TO ep_winsock ENDIF THISFORM.NewObject("olecontrol1", "ep_winsock", "ep_winsock") ENDPROC ENDDEFINE *** Where ep_winsock.vcx is (code from class browser): ************************************************** *-- Class: ep_winsock (..\classlibs\ep_winsock.vcx) *-- ParentClass: olecontrol *-- BaseClass: olecontrol *-- Time Stamp: 02/04/02 10:38:02 AM *-- OLEObject = C:\WINNT\SYSTEM32\MSWINSCK.OCX * DEFINE CLASS ep_winsock AS olecontrol Height = 100 Width = 100 Name = "ep_winsock" ENDDEFINE * *-- EndDefine: ep_winsock ************************************************** Rick Quote:> Hi, > I am comming again with a problem Class problem. > I have a clean installation with windows 2000 on which I install my > application. > I have included and registered the MSWINSCK.OCX > using the following code I try to get the IP addresss > * Get_Card_IP > Local n > ows = createobject("mswinsock.winsock") > if Type("ows")="O" > n=ows.LocalIP > Release ows > Else > n="" > Endif > Return(n) > But I get the error message > OLE error code etc etc: Class is not licensed for use. > MsWinsck.ocx comes with VFP. How do I bypass this problem ? > Demetrios, Greece Sun, 07 Nov 2004 03:52:56 GMT Demetrios Panayotakopoulo#5 / 8 Class not registered problem Thank you very much Rick. I have read those articles. But I am not very familiar with ActiveX (though I use them) and classes, sub-classes etc. I had the same problem with MSMapi32 which wouldn't run if I hadn't follow the procedure I described in my mail. Thanks for the code bellow. I will read it carefully - so I can learn something. Demetrios, Greece Quote:> Demetrios, > This "problem" is a variant (different OCX) of the one described in > =kb%3Ben-us%3BQ139154 - "INFO: > OLE Control Licensing in Visual FoxPro (Q139154)". The final example shows a > way around the problem. > You may want to also read > =kb%3Ben-us%3BQ192693 - "BUG: > License Error with ActiveX Control Added at Run-Time (Q192693)" > For some actual code, the following is currently working just fine in many > locations (VFP 6.0 SP5). Basically, because the VCX does the direct usage of > Winsock, and it's precompiled, it doesn't create a license problem! It's a > simple procedure that uses Winsock to get the IP address. (Andy is one of > our programmers.) > * Program....: GETIP.PRG > * Version....: 1.0 > * Author.....: ** Andy Goeddeke ** > * Date.......: January 8, 2002 > * Return IP address as char string > * 02/04/2002 Changed the technique slightly to avoid the "Class not > registered/licensed" errors. > *!* The following DOESN'T work! > *!* LOCAL loWinsock > *!* loWinSock = CREATEOBJECT("MSWinsock.Winsock") > *!* return loWinsock.LocalIP > LOCAL oForm1, lcIP > oForm1 = CREATEOBJECT("dummyform") > lcIP = oForm1.Olecontrol1.LocalIP > RELEASE oForm1 > RETURN lcIP > ************************************* > DEFINE CLASS dummyform AS form > DoCreate = .T. > Caption = "dummyform" > Name = "dummyform" > PROCEDURE INIT > IF .F. > ** This sucks the class into the project automatically. > SET CLASS TO ep_winsock > ENDIF > THISFORM.NewObject("olecontrol1", "ep_winsock", "ep_winsock") > ENDPROC > ENDDEFINE > *** Where ep_winsock.vcx is (code from class browser): > ************************************************** > *-- Class: ep_winsock (..\classlibs\ep_winsock.vcx) > *-- ParentClass: olecontrol > *-- BaseClass: olecontrol > *-- Time Stamp: 02/04/02 10:38:02 AM > *-- OLEObject = C:\WINNT\SYSTEM32\MSWINSCK.OCX > * > DEFINE CLASS ep_winsock AS olecontrol > Height = 100 > Width = 100 > Name = "ep_winsock" > ENDDEFINE > * > *-- EndDefine: ep_winsock > ************************************************** > Rick > > Hi, > > I am comming again with a problem Class problem. > > I have a clean installation with windows 2000 on which I install my > > application. > > I have included and registered the MSWINSCK.OCX > > using the following code I try to get the IP addresss > > * Get_Card_IP > > Local n > > ows = createobject("mswinsock.winsock") > > if Type("ows")="O" > > n=ows.LocalIP > > Release ows > > Else > > n="" > > Endif > > Return(n) > > But I get the error message > > OLE error code etc etc: Class is not licensed for use. > > MsWinsck.ocx comes with VFP. How do I bypass this problem ? > > Demetrios, Greece Sun, 07 Nov 2004 11:44:34 GMT Demetrios Panayotakopoulo#6 / 8 Class not registered problem I think that these last days I must send two posts. When I wrote "The code bellow" I meant the code I wrote in my previous post, as reply to Damian. Anyway, I have one more question. OCXs can be used only in forms ? Demetrios, Greece Quote:> Thank you very much Rick. > I have read those articles. But I am not very familiar with ActiveX (though > I use them) and classes, sub-classes etc. > I had the same problem with MSMapi32 which wouldn't run if I hadn't follow > the procedure I described in my mail. > Thanks for the code bellow. > I will read it carefully - so I can learn something. > Demetrios, Greece > > Demetrios, > > This "problem" is a variant (different OCX) of the one described in > > =kb%3Ben-us%3BQ139154 - > "INFO: > > OLE Control Licensing in Visual FoxPro (Q139154)". The final example shows > a > > way around the problem. > > You may want to also read > > =kb%3Ben-us%3BQ192693 - > "BUG: > > License Error with ActiveX Control Added at Run-Time (Q192693)" > > For some actual code, the following is currently working just fine in many > > locations (VFP 6.0 SP5). Basically, because the VCX does the direct usage > of > > Winsock, and it's precompiled, it doesn't create a license problem! It's a > > simple procedure that uses Winsock to get the IP address. (Andy is one of > > our programmers.) > > * Program....: GETIP.PRG > > * Version....: 1.0 > > * Author.....: ** Andy Goeddeke ** > > * Date.......: January 8, 2002 > > * Return IP address as char string > > * 02/04/2002 Changed the technique slightly to avoid the "Class not > > registered/licensed" errors. > > *!* The following DOESN'T work! > > *!* LOCAL loWinsock > > *!* loWinSock = CREATEOBJECT("MSWinsock.Winsock") > > *!* return loWinsock.LocalIP > > LOCAL oForm1, lcIP > > oForm1 = CREATEOBJECT("dummyform") > > lcIP = oForm1.Olecontrol1.LocalIP > > RELEASE oForm1 > > RETURN lcIP > > ************************************* > > DEFINE CLASS dummyform AS form > > DoCreate = .T. > > Caption = "dummyform" > > Name = "dummyform" > > PROCEDURE INIT > > IF .F. > > ** This sucks the class into the project automatically. > > SET CLASS TO ep_winsock > > ENDIF > > THISFORM.NewObject("olecontrol1", "ep_winsock", "ep_winsock") > > ENDPROC > > ENDDEFINE > > *** Where ep_winsock.vcx is (code from class browser): > > ************************************************** > > *-- Class: ep_winsock (..\classlibs\ep_winsock.vcx) > > *-- ParentClass: olecontrol > > *-- BaseClass: olecontrol > > *-- Time Stamp: 02/04/02 10:38:02 AM > > *-- OLEObject = C:\WINNT\SYSTEM32\MSWINSCK.OCX > > * > > DEFINE CLASS ep_winsock AS olecontrol > > Height = 100 > > Width = 100 > > Name = "ep_winsock" > > ENDDEFINE > > * > > *-- EndDefine: ep_winsock > > ************************************************** > > Rick > > > Hi, > > > I am comming again with a problem Class problem. > > > I have a clean installation with windows 2000 on which I install my > > > application. > > > I have included and registered the MSWINSCK.OCX > > > using the following code I try to get the IP addresss > > > * Get_Card_IP > > > Local n > > > ows = createobject("mswinsock.winsock") > > > if Type("ows")="O" > > > n=ows.LocalIP > > > Release ows > > > Else > > > n="" > > > Endif > > > Return(n) > > > But I get the error message > > > OLE error code etc etc: Class is not licensed for use. > > > MsWinsck.ocx comes with VFP. How do I bypass this problem ? > > > Demetrios, Greece Sun, 07 Nov 2004 12:04:19 GMT Rick Bea#7 / 8 Class not registered problem They can only be used in a "container" and the Form class is the easiest to use when hand coding it. Normally you simply drap-and-drop it on a Form in the Form/Class Designer. Rick Quote:> I think that these last days I must send two posts. > When I wrote "The code bellow" I meant the code I wrote in my previous post, > as reply to Damian. > Anyway, I have one more question. OCXs can be used only in forms ? > Demetrios, Greece > > Thank you very much Rick. > > I have read those articles. But I am not very familiar with ActiveX > (though > > I use them) and classes, sub-classes etc. > > I had the same problem with MSMapi32 which wouldn't run if I hadn't follow > > the procedure I described in my mail. > > Thanks for the code bellow. > > I will read it carefully - so I can learn something. > > Demetrios, Greece > > > Demetrios, > > > This "problem" is a variant (different OCX) of the one described in > > > =kb%3Ben-us%3BQ139154 - > > "INFO: > > > OLE Control Licensing in Visual FoxPro (Q139154)". The final example > shows > > a > > > way around the problem. > > > You may want to also read > > > =kb%3Ben-us%3BQ192693 - > > "BUG: > > > License Error with ActiveX Control Added at Run-Time (Q192693)" > > > For some actual code, the following is currently working just fine in > many > > > locations (VFP 6.0 SP5). Basically, because the VCX does the direct > usage > > of > > > Winsock, and it's precompiled, it doesn't create a license problem! It's > a > > > simple procedure that uses Winsock to get the IP address. (Andy is one > of > > > our programmers.) > > > * Program....: GETIP.PRG > > > * Version....: 1.0 > > > * Author.....: ** Andy Goeddeke ** > > > * Date.......: January 8, 2002 > > > * Return IP address as char string > > > * 02/04/2002 Changed the technique slightly to avoid the "Class not > > > registered/licensed" errors. > > > *!* The following DOESN'T work! > > > *!* LOCAL loWinsock > > > *!* loWinSock = CREATEOBJECT("MSWinsock.Winsock") > > > *!* return loWinsock.LocalIP > > > LOCAL oForm1, lcIP > > > oForm1 = CREATEOBJECT("dummyform") > > > lcIP = oForm1.Olecontrol1.LocalIP > > > RELEASE oForm1 > > > RETURN lcIP > > > ************************************* > > > DEFINE CLASS dummyform AS form > > > DoCreate = .T. > > > Caption = "dummyform" > > > Name = "dummyform" > > > PROCEDURE INIT > > > IF .F. > > > ** This sucks the class into the project automatically. > > > SET CLASS TO ep_winsock > > > ENDIF > > > THISFORM.NewObject("olecontrol1", "ep_winsock", "ep_winsock") > > > ENDPROC > > > ENDDEFINE > > > *** Where ep_winsock.vcx is (code from class browser): > > > ************************************************** > > > *-- Class: ep_winsock (..\classlibs\ep_winsock.vcx) > > > *-- ParentClass: olecontrol > > > *-- BaseClass: olecontrol > > > *-- Time Stamp: 02/04/02 10:38:02 AM > > > *-- OLEObject = C:\WINNT\SYSTEM32\MSWINSCK.OCX > > > * > > > DEFINE CLASS ep_winsock AS olecontrol > > > Height = 100 > > > Width = 100 > > > Name = "ep_winsock" > > > ENDDEFINE > > > * > > > *-- EndDefine: ep_winsock > > > ************************************************** > > > Rick > > > > Hi, > > > > I am comming again with a problem Class problem. > > > > I have a clean installation with windows 2000 on which I install my > > > > application. > > > > I have included and registered the MSWINSCK.OCX > > > > using the following code I try to get the IP addresss > > > > * Get_Card_IP > > > > Local n > > > > ows = createobject("mswinsock.winsock") > > > > if Type("ows")="O" > > > > n=ows.LocalIP > > > > Release ows > > > > Else > > > > n="" > > > > Endif > > > > Return(n) > > > > But I get the error message > > > > OLE error code etc etc: Class is not licensed for use. > > > > MsWinsck.ocx comes with VFP. How do I bypass this problem ? > > > > Demetrios, Greece Mon, 08 Nov 2004 02:37:10 GMT Demetrios Panayotakopoulo#8 / 8 Class not registered problem Aha. That's why I got an error "This object is invalid for this container" or somethoing like that when trying to do something from PRG. Thanks Rick. Demetrios, Greece Quote:> They can only be used in a "container" and the Form class is the easiest to > use when hand coding it. Normally you simply drap-and-drop it on a Form in > the Form/Class Designer. > Rick > > I think that these last days I must send two posts. > > When I wrote "The code bellow" I meant the code I wrote in my previous > post, > > as reply to Damian. > > Anyway, I have one more question. OCXs can be used only in forms ? > > Demetrios, Greece > > > Thank you very much Rick. > > > I have read those articles. But I am not very familiar with ActiveX > > (though > > > I use them) and classes, sub-classes etc. > > > I had the same problem with MSMapi32 which wouldn't run if I hadn't > follow > > > the procedure I described in my mail. > > > Thanks for the code bellow. > > > I will read it carefully - so I can learn something. > > > Demetrios, Greece > > > > Demetrios, > > > > This "problem" is a variant (different OCX) of the one described in =kb%3Ben-us%3BQ139154 - Quote:> > > "INFO: > > > > OLE Control Licensing in Visual FoxPro (Q139154)". The final example > > shows > > > a > > > > way around the problem. > > > > You may want to also read =kb%3Ben-us%3BQ192693 - - Hide quoted text -- Show quoted text - 2ff7e9595c


1 view0 comments

Recent Posts

See All

コメント


bottom of page