View Single Post
  #44   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:51:23 PM UTC, Peter T wrote:

[snip]
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



Hi Peter,
I'm at the end of my tether now: I followed your instructions (at least I
hope I did) and tried many times, but the stubborn thing is still crashing
on exactly the same line!
As a final resort and a last attempt to make it work, I'm posting below my
entire code in a hope that whatever is wrong might be noticeable to you.

[snip]

Change the return type of the gethostbyname API from As Long to LongPtr

This API is not documented in Win32API_PtrSafe.txt and not directly obvious
from its name what it should return. However it needs to match the variable
it returns to, which Randy Birch helpfully documented is an address and
hence a LongLong in Win64 (or LongPtr which morphs to a LongLong in x64):
Dim ptrHosent As LongPtr ' address of HOSENT structure

If this doesn't fix it for you upload it to a file sharing site and post
back. Actually post back anyway if only to let us know it's working!

Peter T