Page 1 of 2
Get IP Address
Posted: Fri Nov 05, 2021 6:03 pm
by OhioJoe
In VO I used the following to get the computer's IP address:
Code: Select all
_DLL FUNCTION GetIPAddress(cHost AS STRING) AS STRING PASCAL:VO28INET.GetIPAddress
Which of course created the following error after conversion to XSharp
Code: Select all
Unable to load DLL 'VO28INET': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
Does anyone know of an XSharp equivalent ? I figured I'd ask first before cutting and pasting someone else's C# code
Thank you
Get IP Address
Posted: Fri Nov 05, 2021 6:07 pm
by wriedmann
Hi Joe,
you can find an anwer here:
https://stackoverflow.com/questions/132 ... name-to-ip
But you could instead add the VOInternetClasses.DLL to your application and use that.
Wolfgang
Get IP Address
Posted: Fri Nov 05, 2021 8:49 pm
by Juraj
Hi Joje,
in my X# app i use this:
LOCAL hostName:=System.Net.Dns.GetHostName() AS STRING
LOCAL cIP:= System.Net.Dns.GetHostByName(hostName).AddressList[1].ToString() AS STRING
Juraj
Get IP Address
Posted: Fri Nov 05, 2021 11:25 pm
by FFF
Hi Juray,
the second line provokes here: warning VN3030: GetHostByName is obsoleted for this type, please use GetHostEntry instead.
http://go.microsoft.com/fwlink/?linkid=14202
I tried to use this, and it works
, only difference ist, for "ByName" i get an IP4, with "Entry" an IP 6 address back.
Get IP Address
Posted: Sat Nov 06, 2021 1:23 pm
by Juraj
Hi Karl,
I used it in one of the first of my XSharp application. Despite the warning, the program worked OK, so I did not solve it
Juraj
Get IP Address
Posted: Sat Nov 06, 2021 2:06 pm
by robert
Karl,
> warning VN3030
Are you using Vulcan?
Robert
Get IP Address
Posted: Sat Nov 06, 2021 5:17 pm
by FFF
Robert,
ups - yes, silly me hasn't noticed - this test app was really old
Changed it to X#/VO, swapped references, added VOInternetClasses.dll, compiles fine, albeit with the corresponding XS0618 warning - and it fails at runtime, because it can't find the latter (V 2.6.0.0), even when it is copied into bin.
Why?
Get IP Address
Posted: Sat Nov 06, 2021 11:24 pm
by OhioJoe
The following function compiles without warnings.
Code: Select all
FUNCTION XGetIPAddress( ) AS STRING STRICT
LOCAL cHostName := System.Net.Dns.gethostname() AS STRING
LOCAL cIP := System.Net.Dns.gethostbyname(cHostName).AddressList[1].ToString() AS STRING
RETURN cIP // returns 192.168 ....
Thanks, Juraj. And Wolfgang and Fabrice and Robert.
That AddressList member is an array, which means it could return several IP addresses. I tested it here and it returned only one. But perhaps a more complete solution would be to loop AddressList and potentially return several IPs.
Get IP Address
Posted: Sat Nov 06, 2021 11:56 pm
by Chris
Hi Karl,
FFF wrote:Robert,
ups - yes, silly me hasn't noticed - this test app was really old
Changed it to X#/VO, swapped references, added VOInternetClasses.dll, compiles fine, albeit with the corresponding XS0618 warning - and it fails at runtime, because it can't find the latter (V 2.6.0.0), even when it is copied into bin.
Why?
This dll depends on VOWin32APILibrary.dll and XSHarp.code.dll and XSharp.RT.dll, have you included those as well?
.
Get IP Address
Posted: Sun Nov 07, 2021 9:10 am
by FFF
Yes, i have. Even made a new X# runtime app, added VOSDK classes, Win32Api and VoInternet, copiles flawless, but fails, now with wrong format...
- GetIP.PNG (133.26 KiB) Viewed 931 times
- GetIP2.PNG (18.3 KiB) Viewed 931 times