Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default IP address to Hostname in Excel

Agreed - thanks Randy and apologies for the confusion re Windows/Office versions :)

Simon
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default IP address to Hostname in Excel

On Friday, April 14, 2017 at 12:39:40 AM UTC+1, wrote:
Agreed - thanks Randy and apologies for the confusion re Windows/Office versions :)

Simon


Dear all,
At work, I've inherited the file that's using Randy Birch's code from he http://vbnet.mvps.org/index.html?cod...byhostname.htm.
Recently, all machines have been up-dated to Office 64 bit and the code stopped working.
I've tried everything from Peter T suggestions above, but, still, as soon as the code gets to line: CopyMemory ptrName, ByVal ptrName, 4, Excel crashes.
I feel particularly stupid, as it looks that some people in this conversation have actually managed to adjust original code to 64 bit, following Peter T's advice.
Any help will be greatly appreciated!

Andrey G
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 88
Default IP address to Hostname in Excel

"Andrey G" wrote in message
On Friday, April 14, 2017 at 12:39:40 AM UTC+1,
wrote:
Agreed - thanks Randy and apologies for the confusion re Windows/Office
versions :)

Simon


Dear all,
At work, I've inherited the file that's using Randy Birch's code from
he http://vbnet.mvps.org/index.html?cod...byhostname.htm.
Recently, all machines have been up-dated to Office 64 bit and the code
stopped working.
I've tried everything from Peter T suggestions above, but, still, as soon
as the code gets to line: CopyMemory ptrName, ByVal ptrName, 4, Excel
crashes.
I feel particularly stupid, as it looks that some people in this
conversation have actually managed to adjust original code to 64 bit,
following Peter T's advice.
Any help will be greatly appreciated!

Andrey G


What were my 'suggestions above'...?

It looks like you're attempting to copy a pointer which in x64 will be an
8-bit LongLong, or a 4-bit Long in x32

Try declaring this conditional constant, either as public in a normal module
or as private in the module you call CopyMemory

#If Win64 Then
Public Const gcPtrBytes As Long = 8
#Else
Public Const gcPtrBytes As Long = 4
#End If

and
CopyMemory ptrName, ByVal ptrName, gcPtrBytes

Only a guess with not much to go on!

Peter T




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 538
Default IP address to Hostname in Excel

Peter T wrote:

"Andrey G" wrote in message
On Friday, April 14, 2017 at 12:39:40 AM UTC+1,
wrote:
Agreed - thanks Randy and apologies for the confusion re
Windows/Office versions :)

Simon


Dear all,
At work, I've inherited the file that's using Randy Birch's code from
he
http://vbnet.mvps.org/index.html?cod...byhostname.htm.
Recently, all machines have been up-dated to Office 64 bit and the code
stopped working.
I've tried everything from Peter T suggestions above, but, still, as
soon as the code gets to line: CopyMemory ptrName, ByVal ptrName, 4,
Excel crashes.
I feel particularly stupid, as it looks that some people in this
conversation have actually managed to adjust original code to 64 bit,
following Peter T's advice.
Any help will be greatly appreciated!

Andrey G


What were my 'suggestions above'...?

It looks like you're attempting to copy a pointer which in x64 will be
an 8-bit LongLong, or a 4-bit Long in x32


<pedantic=on 8-byte LongLong, 4-byte Long </pedantic=off

Try declaring this conditional constant, either as public in a normal
module or as private in the module you call CopyMemory

#If Win64 Then
Public Const gcPtrBytes As Long = 8
#Else
Public Const gcPtrBytes As Long = 4
#End If

and
CopyMemory ptrName, ByVal ptrName, gcPtrBytes

Only a guess with not much to go on!

Peter T


API calls declared PtrSafe?

#If Win64 (or #If Vba7)
Declare Sub PtrSafe CopyMemory etc.

--
- I just hope you know what you're doing.
- I hope that same thing, on occasion.
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 88
Default IP address to Hostname in Excel

"Auric__" wrote in message

It looks like you're attempting to copy a pointer which in x64 will be
an 8-bit LongLong, or a 4-bit Long in x32


<pedantic=on 8-byte LongLong, 4-byte Long </pedantic=off


Good catch!

PT




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default IP address to Hostname in Excel

On Tuesday, November 10, 2020 at 5:24:49 PM UTC, Peter T wrote:
"Andrey G" wrote in message
On Friday, April 14, 2017 at 12:39:40 AM UTC+1,
wrote:
Agreed - thanks Randy and apologies for the confusion re Windows/Office
versions :)

Simon


Dear all,
At work, I've inherited the file that's using Randy Birch's code from
he http://vbnet.mvps.org/index.html?cod...byhostname.htm.
Recently, all machines have been up-dated to Office 64 bit and the code
stopped working.
I've tried everything from Peter T suggestions above, but, still, as soon
as the code gets to line: CopyMemory ptrName, ByVal ptrName, 4, Excel
crashes.
I feel particularly stupid, as it looks that some people in this
conversation have actually managed to adjust original code to 64 bit,
following Peter T's advice.
Any help will be greatly appreciated!

Andrey G

What were my 'suggestions above'...?

It looks like you're attempting to copy a pointer which in x64 will be an
8-bit LongLong, or a 4-bit Long in x32

Try declaring this conditional constant, either as public in a normal module
or as private in the module you call CopyMemory

#If Win64 Then
Public Const gcPtrBytes As Long = 8
#Else
Public Const gcPtrBytes As Long = 4
#End If

and
CopyMemory ptrName, ByVal ptrName, gcPtrBytes

Only a guess with not much to go on!

Peter T


Peter,
Firstly, thank you very much for a prompt reply - I was afraid that this thread might be dead.
When I said "your suggestions" I meant: 1. All APIs were declared with PtrSafe 2. Arguments in APIs starting with h (or hwnd) or include
ptr declared as LongPtr.
Unfortunately, API calls are not my strong point.
I will try to change the pointer to 8 bit, as you advised, when I get to work PC.

Cheers,
Andrey
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 538
Default IP address to Hostname in Excel

Andrey G wrote:

Firstly, thank you very much for a prompt reply - I was afraid that this
thread might be dead.


Best thing to do is to make a new thread, and mention the subject of the
thread you want to reference (e.g. "see also the thread from January 2009,
subject 'Why can't I?'"). Replying to a 3-year-old thread is not the way to
go.

I will try to change the pointer to 8 bit


Argh! Bytes! 8 bytes! 64 bits.

--
I curse you to lives without meaning.
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 88
Default IP address to Hostname in Excel

"Auric__" wrote in message Andrey G wrote:

Firstly, thank you very much for a prompt reply - I was afraid that this
thread might be dead.


Best thing to do is to make a new thread, and mention the subject of the
thread you want to reference (e.g. "see also the thread from January 2009,
subject 'Why can't I?'"). Replying to a 3-year-old thread is not the way
to
go.

I will try to change the pointer to 8 bit


Argh! Bytes! 8 bytes! 64 bits.



Oh dear, yes indeed bytes not bits. Hope you noticed I did at get it right,
implicitly at least, with the var-name 'gcPtrBytes' I suggested:)

Also (Andrey), again perhaps slightly pedantic, what you will be changing is
the last argument for CopyMemory, namely the length or number of bytes to
copy, from 4 in x32 to 8 in x64.

Peter T


  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default IP address to Hostname in Excel

On Wednesday, November 11, 2020 at 11:38:24 AM UTC, Peter T wrote:
"Auric__" wrote in message Andrey G wrote:

Firstly, thank you very much for a prompt reply - I was afraid that this
thread might be dead.


Best thing to do is to make a new thread, and mention the subject of the
thread you want to reference (e.g. "see also the thread from January 2009,
subject 'Why can't I?'"). Replying to a 3-year-old thread is not the way
to
go.

I will try to change the pointer to 8 bit


Argh! Bytes! 8 bytes! 64 bits.

Oh dear, yes indeed bytes not bits. Hope you noticed I did at get it right,
implicitly at least, with the var-name 'gcPtrBytes' I suggested:)

Also (Andrey), again perhaps slightly pedantic, what you will be changing is
the last argument for CopyMemory, namely the length or number of bytes to
copy, from 4 in x32 to 8 in x64.

Peter T





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:


Environment:
Windows 10 Enterprise, 64-bit
Office Professional Plus 2016, 64-bit


'Declarations

Private Declare PtrSafe Function gethostbyname Lib "wsock32.dll" _
(ByVal hostname As String) As Long

Private Declare PtrSafe Sub CopyMemory Lib "kernel32" _
Alias "RtlMoveMemory" _
(xDest As Any, _
xSource As Any, _
ByVal nbytes As LongPtr)

Private Declare PtrSafe Function lstrlenA Lib "kernel32" _
(lpString As Any) As Long

Private Declare PtrSafe Function WSAStartup Lib "wsock32.dll" _
(ByVal wVersionRequired As Long, _
lpWSADATA As WSADATA) As Long

Private Declare PtrSafe Function WSACleanup Lib "wsock32.dll" () As Long

Private Declare PtrSafe Function inet_ntoa Lib "wsock32.dll" _
(ByVal addr As Long) As Long

Private Declare PtrSafe Function lstrcpyA Lib "kernel32" _
(ByVal RetVal As String, _
ByVal Ptr As Long) As Long

Private Declare PtrSafe Function gethostname Lib "wsock32.dll" _
(ByVal szHost As String, _
ByVal dwHostLen As Long) As Long



' String sHostName is passed to GetIPFromHostName function correctly


Private Function GetIPFromHostName(ByVal sHostName As String) As String

'converts a host name to an IP address

Dim nbytes As LongPtr
Dim ptrHosent As LongPtr 'address of HOSENT structure
Dim ptrName As LongPtr 'address of name pointer
Dim ptrAddress As LongPtr 'address of address pointer
Dim ptrIPAddress As LongPtr
Dim ptrIPAddress2 As LongPtr

ptrHosent = gethostbyname(sHostName & vbNullChar)

If ptrHosent < 0 Then

'assign pointer addresses and offset

'Null-terminated list of addresses for the host.
'The Address is offset 12 bytes from the start of
'the HOSENT structure. Note: Here we are retrieving
'only the first address returned. To return more than
'one, define sAddress as a string array and loop through
'the 4-byte ptrIPAddress members returned. The last
'item is a terminating null. All addresses are returned
'in network byte order.
ptrAddress = ptrHosent + 12

'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


Crash details:
Faulting application name: EXCEL.EXE, version: 16.0.5071.1000, time stamp: 0x5f629c9d Faulting module name: ntdll.dll, version: 10.0.18362.1139, time stamp: 0x468a1bf2 Exception code: 0xc0000028

KR
Andrey
Reply
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 04:53 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"