Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
It ends in hundreds of IE windows, till resources runs o
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
COM/DCOM et OLE Automation
Versions des environnements
Visual FoxPro:
VFP 9 SP1
OS:
Windows 2000 SP4
Divers
Thread ID:
01258328
Message ID:
01258345
Vues:
12
OR
* GetNicID - uses Win-32 API call to get NIC ID (physical address)

* this is the DLL declaration to access the API method
DECLARE INTEGER GetAdaptersInfo IN iphlpapi ; 
    STRING @pAdapterInfo, LONG @pOutBufLen 

LOCAL lcBuffer, lnBufsize 
lnBufsize = 0 
lcBuffer = "" 

* first call to GetAdaptorsInfo() method
* this call usually returns: ERROR_BUFFER_OVERFLOW (111)
* with lnBufsize set to the required amount of memory 
= GetAdaptersInfo(@lcBuffer, @lnBufsize) 

* build buffer string from nulls
lcBuffer = Repli(Chr(0), lnBufsize) 

* call method again
IF GetAdaptersInfo(@lcBuffer, @lnBufsize) <> 0 && ERROR_SUCCESS 
  * no joy 
  =MESSAGEBOX('WinAPI problem - GetAdaptorsInfo')
  RETURN 
ENDIF 

LOCAL lcNICName, lnAddrlen, lcAddress, ii, lcIntraIP, lcMask, lcGateway

* lcNICName is between {}
lcNICName = STREXTRACT(lcBuffer,"{","}",1,4)
* 401st byte of lcBuffer is size of NIC address string
lnAddrlen = Asc(SUBSTR(lcBuffer, 401, 1)) 
* actual NIC address starts at byte 405 of lcBuffer
lcAddress = SUBSTR(lcBuffer, 405, lnAddrlen) 
lcIntraIP = allt(SUBSTR(lcBuffer,433,15))
lcMask = allt(SUBSTR(lcBuffer,449,15))
lcGateway = allt(SUBSTR(lcBuffer,473,15))



* build decimal and hex strings from ASCII values of returned characters
lcThisID = ''
lcThisHex = ''

FOR ii = 1 TO lnAddrLen
    lcThisID = lcThisID + ;
    IIF(ii>1,',','') + ;
    ALLTRIM(STR(ASC(SUBSTR(lcAddress,ii,1))))

    lcThisHex = lcThisHex + ;
    IIF(ii>1,'-','') + ;
    RIGHT(TRANSFORM(ASC(SUBSTR(lcAddress,ii,1)),'@0'),2)
NEXT 

* display decimal and hex versions of NIC ID
?
? 'NIC Name (chr)  : '+lcNICName
? 'NIC ID (decimal): '+lcThisID
? 'NIC ID (hex)    : '+ lcThisHex 
? 'NIC IntraIP     : '+ lcIntraIP
? 'NIC Mask        : '+ lcMask
? 'NIC Gateway     : '+ lcGateway

Clear DLLS GetAdaptersInfo
>Hi all
>
>I have, with help from all the guru's here, a method to get the Internet IP address of my computer. This code is working so-so when there is a permanent internet connection, cause there are times when the code fails at IF TYPE() and/or IF VARTYPE() command.
>
>This probably is the reason when on a computer where the internet (ADSL with limited bandwidth, thus disconnected from ISP) is not permanently online. At times the method or rather the automation of IE goes crazy and it starts opening lots and lots of IE windows until the resources run out for creating more windows. Then after a while the same app and code will run OK without any problems or IE windows.
>
>Please help me solve this odd problem. The code follows. Please note the odd IF TYPE("loIE.DOCUMENT") = "O" AND TYPE("loIE.DOCUMENT.NAME") = "C" condition. I have tried to replace it with a VARTYPE() as well as try them individually but it at times returns a true and code later fails.
>
>Thanks.
>
>
LOCAL lcRetVal, loIE, loDoc, lnTimeOut, lnTSec, lnST, lnFH, lcFL, ;
>	lnX, lcIP, lnCtr
>
>
>WAIT WINDOW "Detecting Internet IP address ..." NOWAIT
>
>
>DECLARE Sleep IN kernel32 INTEGER millisec
>
>
>loIE        = CREATEOBJECT('internetexplorer.application')
>loIE.Silent = .T.			&& no dialogs
>
>lcIP      = ""
>lnTimeOut = 20
>lnTSec    = SECONDS()
>
>loIE.navigate2("www.whatismyip.com")
>
>lnCtr = 0
>
>
>*--------------------------------------------
>*  wait until complete
>*--------------------------------------------
>lnST = SECONDS()
>
>Sleep(50)
>
>
>DO WHILE .T.
>	IF NOT VERSION(5) = 700
>		*** In 7.0, the DoEvents behavior changed to stop and wait for event.
>		*** In 8.0, the behavior was changed back to 6.0 behavior.
>		DOEVENTS
>	ENDIF
>
>
>	DO CASE
>		CASE loIE.ReadyState = 4 AND NOT loIE.Busy
>			EXIT
>
>		CASE loIE.ReadyState = 3 AND SECONDS() - lnST > 5
>			EXIT
>
>		CASE SECONDS() - lnST > lnTimeOut
>			EXIT
>	ENDCASE
>
>
>	lnCtr = lnCtr + 1
>
>	WAIT WINDOW "Detecting Internet IP address (" + ALLTRIM(STR(lnCtr)) + ") ..." NOWAIT
>	
>
>	Sleep(50)
>ENDDO
>
>
>****
>**** This IF condition is a major cause of the problem, I have tried VARTYPE() also as well as the below conditions independently, no joy
>****
>IF TYPE("loIE.DOCUMENT") = "O" AND TYPE("loIE.DOCUMENT.NAME") = "C"
>	*** 21/02/2007 put in a TRY-CATCH for when object is created
>	***            but innertext is invalid
>	TRY
>		loDoc = loIE.DOCUMENT
>
>		*** now you have your doc. object in loDoc
>		MyString = loDoc.Body.InnerText &&& now you have a string with the contents
>		MyHTML   = loDoc.Body.InnerHTML &&& same, but in HTML
>
>		STRTOFILE(MyString, "InnerText.txt")
>		STRTOFILE(MyHTML  , "InnerHTML.htm")
>
>
>		lnFH = FOPEN("InnerText.txt")
>
>		DO WHILE NOT FEOF(lnFH)
>			lcFL = UPPER(FGETS(lnFH))
>
>
>			DO CASE
>				CASE lcFL = UPPER("Your IP is ")
>					lcIP = ALLTRIM(STRTRAN(lcFL, UPPER("Your IP is "), ""))
>					EXIT
>
>				CASE lcFL = UPPER("Your IP - ")
>					lcIP = ALLTRIM(STRTRAN(lcFL, UPPER("Your IP - "), ""))
>					EXIT
>
>				CASE lcFL = UPPER("Bookmark Your IP - ")
>					lcIP = ALLTRIM(STRTRAN(lcFL, UPPER("Bookmark Your IP - "), ""))
>					EXIT
>
>				CASE lcFL = UPPER("Bookmark Your IP Is ")
>					lcIP = ALLTRIM(STRTRAN(lcFL, UPPER("Bookmark Your IP Is "), ""))
>					EXIT
>			ENDCASE
>		ENDDO
>
>		= FCLOSE(lnFH)
>
>
>		DELETE FILE InnerText.txt
>		DELETE FILE InnerHTML.htm
>
>
>	CATCH
>		lcIP = ""
>	ENDTRY
>ENDIF
>
>
>lcRetVal = IIF(EMPTY(lcIP), "Not detected", lcIP)
>
>
>WAIT WINDOW "Internet IP address: " + lcRetVal + " ..." NOWAIT
>
>
>CLEAR DLLS Sleep
>
>
>RETURN lcRetVal
_______________________________________________________________
Testing displays the presence, not the absence of bugs.
If a software application has to be designed, it has to be designed correctly!
_______________________________________________________________
Vladimir Zografski
Systems Analyst
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform