LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #21   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 162
Default IP address to Hostname in Excel


wrote in message
...
Sorry - I should have pointed out that the "CopyMemory" problem occurs on
both 32 and 64 bit Office IF running on 64-bit Windows. I'm familiar with
the PtrSafe construct but I've tried adjusting the data types (LongPtr,
LongLong, etc) without success. I also emailed Randy who said he'd never
tried to make it work on 64-bit OS. Another source said that anything using
winsock32.dll on 64 bit OS won't work reliably, but I don't know if that is
true. You can get a Name from an IP using WMI but if the remote computer
isn't listening on WMI the code waits a long-time before giving up, which is
no good if its along list of computers, and they may not all be running
Windows!

I can only reiterate Randy's original works fine for me in Win10 + Excel64
the with the usual adaptations for the APIs. Without knowing what you've
changed hard to suggest why yours crashes.

All the APIs should be declared with PtrSafe.
The gethostbyaddr function should return a LongPtr and its hAddr argument
should be a LongPtr

In Randy's GetHostNameFromIP function ptrHosent and hAddress should be
LongPtr

If you need to cater for Office 2007 or earlier you'll need to include the
differences for both APIs and declared variables (in your own functions)
under
#IfVBA7
ptrSafe LongPtr version..
#Else
original code.
#End If

In passing don't declare as LongLong unless you're coding exclusively for
Office64 or under #Win64.Under VBA7 LongPtr is a Long in x32 and a LongLong
in x64.

Another tip, look for arguments in APIs starting with h (or hwnd) or include
ptr. Handles and pointers are LongPtr (ie LongLong in x64) and variables
that pass or return such values should be declared as LongPtr. APIs that
return similar will return a LongPtr, and should be returned to
appropriately declared variables.

Head your module Option Explicit and do Debug / compile in both x32 and x64

In 32 bit Office Randy's original should work fine as-is even in 64bit
Windows. Make sure you copy it directly from his site. All you need to do is
change the two text-box references to strings.

Peter T


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hostname from IP address NickT Excel Worksheet Functions 1 April 9th 10 02:31 PM
How do I avoid excel change absolute address to relative address Miguel Excel Discussion (Misc queries) 3 May 10th 07 11:18 PM
Converting list of IP Addresses to list of Hostname M. Eteum Excel Worksheet Functions 0 March 23rd 06 06:16 PM
Get IP address for a remote computer based on its hostname stabilo Excel Programming 1 February 14th 06 07:08 PM
LINKING Address cells from an EXCEL spreadsheet to fill MapQuest Address Info Duane S. Meyer Excel Programming 0 August 30th 03 12:16 AM


All times are GMT +1. The time now is 02:26 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"