Need help Macro crashes Excel 2013 64bit.

I have the following code in Excel 2013 64Bit and it keeps crashing the App. What I’m i doing wrong.

 

Thank you

 

It crashes at the following code.

Call CopyMemory(uRecord, pNext, Len(uRecord))”

 

 

Full Code==============

Option Explicit

 

Private Declare PtrSafe Function DnsQuery Lib “dnsapi” Alias “DnsQuery_A” (ByVal strname As String, ByVal wType As Integer, ByVal fOptions As Long, ByVal pServers As LongLong, ppQueryResultsSet As Long, ByVal pReserved As Long) As Long

Private Declare PtrSafe Function DnsRecordListFree Lib “dnsapi” (ByVal pDnsRecord As Long, ByVal FreeType As Long) As Long

Private Declare PtrSafe Function lstrlen Lib “kernel32” (ByVal straddress As Long) As Long

Private Declare PtrSafe Sub CopyMemory Lib “kernel32” Alias “RtlMoveMemory” (Destination As Any, ByVal Source As Long, ByVal Length As Long)

Private Declare PtrSafe Function inet_ntoa Lib “ws2_32.dll” (ByVal pIP As Long) As Long

Private Declare PtrSafe Function inet_addr Lib “ws2_32.dll” (ByVal sAddr As String) As Long

 

Private Const DnsFreeRecordList         As Long = 1

Private Const DNS_TYPE_A                As Long = &H1

Private Const DNS_TYPE_PTR              As Long = &HC

Private Const DNS_QUERY_BYPASS_CACHE    As Long = &H8

 

Private Type VBDnsRecord

    pNext           As Long

    pName           As LongPtr

    wType           As Integer

    wDataLength     As Integer

    flags           As Long

    dwTel           As Long

    dwReserved      As Long

    prt             As Long

    others(35)      As Byte

End Type

 

Sub DNS_Resolve()

Dim strDName As String

Dim strDNames As Variant

 

Dim a, b

a = 2

b = 2

 

While Not IsEmpty(Worksheets(“Sheet1”).Cells(a, 1))

strDName = Trim(Worksheets(“Sheet1”).Cells(a, 1))

strDNames = Split(strDName, “.”)

strDName = strDNames(3) + “.” + strDNames(2) + “.” + strDNames(1) + “.” + strDNames(0)

strDName = strDName + “.in-addr.arpa”

Worksheets(“Sheet1”).Cells(a, 2) = Resolve2(strDName, “8.8.8.8”)

    a = a + 1

Wend

 

While Not IsEmpty(Worksheets(“Sheet1”).Cells(b, 3))

strDName = Worksheets(“Sheet1”).Cells(b, 3)

Worksheets(“Sheet1”).Cells(b, 4) = Resolve(strDName, “8.8.8.8”)

    b = b + 1

Wend

 

MsgBox (“Complete”)

 

End Sub

 

Private Function Resolve(sAddr As String, Optional sDnsServers As String) As String

    Dim pRecord     As Long

    Dim pNext       As Long

    Dim uRecord     As VBDnsRecord

    Dim lPtr        As Long

    Dim vSplit      As Variant

    Dim laServers() As Long

    Dim pServers    As LongLong

    Dim sName       As String

 

    If LenB(sDnsServers) <> 0 Then

        vSplit = Split(sDnsServers)

        ReDim laServers(0 To UBound(vSplit) + 1)

        laServers(0) = UBound(laServers)

        For lPtr = 0 To UBound(vSplit)

            laServers(lPtr + 1) = inet_addr(vSplit(lPtr))

        Next

        pServers = VarPtr(laServers(0))

    End If

 

    If DnsQuery(sAddr, DNS_TYPE_A, DNS_QUERY_BYPASS_CACHE, pServers, pRecord, 0) = 0 Then

        pNext = pRecord

        Do While pNext <> 0

            Call CopyMemory(uRecord, pNext, Len(uRecord))

            If uRecord.wType = DNS_TYPE_A Then

                lPtr = inet_ntoa(uRecord.prt)

                sName = String(lstrlen(lPtr), 0)

                Call CopyMemory(ByVal sName, lPtr, Len(sName))

                If LenB(Resolve) <> 0 Then

                    Resolve = Resolve & ” “

                End If

                Resolve = Resolve & sName

            End If

            pNext = uRecord.pNext

        Loop

        Call DnsRecordListFree(pRecord, DnsFreeRecordList)

    End If

End Function

 

Private Function Resolve2(sAddr As String, Optional sDnsServers As String) As String

    Dim pRecord     As Long

    Dim pNext       As Long

    Dim uRecord     As VBDnsRecord

    Dim lPtr        As Long

    Dim vSplit      As Variant

    Dim laServers() As Long

    Dim pServers    As LongLong

    Dim sName       As String

 

        If LenB(sDnsServers) <> 0 Then

            vSplit = Split(sDnsServers)

            ReDim laServers(0 To UBound(vSplit) + 1)

            laServers(0) = UBound(laServers)

            For lPtr = 0 To UBound(vSplit)

                laServers(lPtr + 1) = inet_addr(vSplit(lPtr))

            Next

            pServers = VarPtr(laServers(0))

        End If

 

    If DnsQuery(sAddr, DNS_TYPE_PTR, DNS_QUERY_BYPASS_CACHE, pServers, pRecord, 0) = 0 Then

        pNext = pRecord

        Do While pNext <> 0

            Call CopyMemory(uRecord, pNext, Len(uRecord))

            If uRecord.wType = DNS_TYPE_PTR Then

                lPtr = uRecord.prt

                sName = String(lstrlen(lPtr), 0)

                Call CopyMemory(ByVal sName, lPtr, Len(sName))

                If LenB(Resolve2) <> 0 Then

                    Resolve2 = Resolve2 & ” “

                End If

                Resolve2 = Resolve2 & sName

            End If

            pNext = uRecord.pNext

        Loop

        Call DnsRecordListFree(pRecord, DnsFreeRecordList)

    End If

End Function

By: Rene

3,669 thoughts on “Need help Macro crashes Excel 2013 64bit.

  1. 인터넷 카지노

    I think this is among the most significant info for
    me. And i am glad reading your article. But should remark
    on few general things, The web site style is wonderful, the articles
    is really great : D. Good job, cheers

  2. 예스 카지노

    Do you have a spam problem on this blog; I also am a blogger,
    and I was wondering your situation; many of us have created some nice practices and we
    are looking to swap solutions with others, be
    sure to shoot me an email if interested.

  3. wildcatkpo.design.blog

    This is really interesting, You’re a very skilled blogger.
    I have joined your feed and look forward to seeking more of your great post.
    Also, I’ve shared your web site in my social networks!

  4. 모나코 카지노

    Hey I know this is off topic but I was wondering if you knew of any
    widgets I could add to my blog that automatically tweet my newest
    twitter updates. I’ve been looking for a plug-in like this for quite some time and was hoping maybe you would have some experience
    with something like this. Please let me know if you run into anything.

    I truly enjoy reading your blog and I look forward
    to your new updates.

  5. 온라인 바카라

    Do you have a spam problem on this website; I also am a blogger, and I
    was wanting to know your situation; many of us have developed some nice procedures
    and we are looking to swap solutions with others, be sure
    to shoot me an email if interested.

  6. moedah.com

    I’d like to thank you for the efforts you’ve put in penning this site. I’m hoping to see the same high-grade content from you later on as well. In fact, your creative writing abilities has encouraged me to get my very own website now 😉

  7. 바카라 사이트

    Normally I do not learn article on blogs, but I would like
    to say that this write-up very compelled me to check out and do so!
    Your writing style has been amazed me. Thank you, quite great post.

  8. genolyze

    Howdy! This post couldn’t be written much better! Looking through this article reminds me of my previous roommate! He always kept preaching about this. I’ll send this article to him. Fairly certain he’ll have a great read. Thank you for sharing!

  9. harga-jual

    I wanted to thank you for this great read!! I certainly loved every little bit of it. I have got you saved as a favorite to look at new things you post…

  10. tokoonline88.com

    Next time I read a blog, I hope that it won’t fail me as much as this one. After all, I know it was my choice to read through, but I actually thought you would probably have something interesting to say. All I hear is a bunch of whining about something that you could possibly fix if you weren’t too busy looking for attention.

  11. iamgutsclub.com

    The very next time I read a blog, I hope that it won’t fail me just as much as this one. After all, I know it was my choice to read, nonetheless I really believed you would have something helpful to talk about. All I hear is a bunch of crying about something you can fix if you weren’t too busy looking for attention.

  12. Bobbie

    I think the admin of this site is genuinely working hard
    in support of his web site, since here every information is quality based information.

  13. vivoslot apk

    I’m more than happy to uncover this great site. I want to to thank you for your time due to this fantastic read!! I definitely savored every part of it and I have you saved to fav to look at new things on your web site.

Comments are closed.