View Single Post
  #42   Report Post  
Posted to microsoft.public.excel.programming
Peter T[_8_] Peter T[_8_] is offline
external usenet poster
 
Posts: 88
Default IP address to Hostname in Excel


"Andrey G" wrote in message
On Wednesday, November 18, 2020 at 10:02:17 AM UTC, Peter T wrote:
"Andrey G" wrote in message
...
On Thursday, November 12, 2020 at 11:37:20 AM UTC, Peter T wrote:
"Andrey G" wrote in message
Hi Peter,

I've tried running code with the last argument for CopyMemory
changed,
but
Excel still crashed. Please have a look below at the details of the
problem:

[snip]
'get the IP address
CopyMemory ptrAddress, ByVal ptrAddress, 8 '<----- Excel crashes
on this line!
CopyMemory ptrIPAddress, ByVal ptrAddress, 8
CopyMemory ptrIPAddress2, ByVal ptrIPAddress, 8

GetIPFromHostName = GetInetStrFromPtr(ptrIPAddress2)

End If

End Function
Hmm, not sure where the root of the problem is, though for me it
crashes
on
the second CopyMemory, I need to get the rest of the original example.
I'll
try and look at it over the W/E.

Peter T


Hi Peter,
Thank you very much for looking into it!
Just to be absolutely clear:
As I'd said I've inherited the file, using original code from he
http://vbnet.mvps.org/index.html?cod...byhostname.htm
Above I've posted simplified original code from he
http://vbnet.mvps.org/index.html?cod...k/iplookup.htm
In my case, Excel crashes on both occasions on CopyMemory line of
Function
GetIPFromHostName().
KR
Andrey

Sorry to take a while to get back, I got hijacked with work!

In your original code, as well as changing the lengths of the 3 pointers
from 4 to 8, also change
ptrAddress = ptrHosent + 12 ' 3x4
to
ptrAddress = ptrHosent + 24 ' 3x8

Peter T



No joy, I'm afraid - Excel is still crashing on the very same line.
I wonder if I made an error in declarations? The code I'd posted above is
the exact code I'm using.
Andrey G


I couldn't work with what you posted because it is incomplete, so I adapted
Randy Birch's originals from the links you posted and both working fine for
me in x64, with the 1224 change.

At a quick glance of what you posted 'addr' in the inet_ntoa API should be
As LongPtr not Long but there may well be others. Look for things like addr,
ptr, an h prefix for handle. These are typically what need to be changed
along with related API return types. Ensure your module is headed Option
Explicit and do debug/compile.

Note the 8-byte lengths and that 24 are specific for use with #Win64, not
#VBA7.

Peter T