Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 626113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:23:00+00:00 2026-05-13T19:23:00+00:00

In VB6 I’m making a call to the Windows API DnsQuery . Private Declare

  • 0

In VB6 I’m making a call to the Windows API DnsQuery.

Private Declare Function DnsQuery Lib "dnsapi" Alias "DnsQuery_A" ( _
   ByVal lpstrName As String, _
   ByVal wType As Integer, _
   ByVal Options As Long, _
   ByVal pServers As Long, _
   ppQueryResultsSet As Long, _
   ByVal pReserved As Long) As Long

Private Type VBDnsRecord
   pNext           As Long
   pName           As Long
   'Name            As String ' Commented out, see question
   wType           As Integer
   wDataLength     As Integer
   Flags           As Long
   dwTtl           As Long
   dwReserved      As Long
   ptrData         As Long
   Others(35)      As Byte
End Type

My declaration of the struct came from here. I presume Others(35) is to provide a big enough container when the actual struct that is returned is larger than expected (there are some variable-length types UNIONed in there). See the DNS_RECORD structure for more details.

So, I have 2 questions:

  1. Strings in VB are really, behind the scenes, double word pointers (4 bytes, aka a Long). For a bit I thought I could declare Name as a String since this would just place the pointer in there and work correctly (as when passing VB Strings into API calls). However, I’m guessing the application terminations I got are because it’s a C-style string and not a VB-style string, and VB looks in the memory location just before the start of the string for a length value, and gets some random garbage and blows up. Is that a reasonable guess?

  2. My call to DnsQuery works when I use am returning a DNS RR type of DNS_PTR_DATA or DNS_A_DATA, but when I try DNS_TXT_DATA it’s blowing up. Can someone else spot what I’m doing wrong? Look at Case DNS_TYPE_TEXT, and see my comments below.

    RetVal = DnsQuery(DnsName,
    QueryType, DNS_QUERY_BYPASS_CACHE,
    pServers, pDnsRecord, 0)
        If RetVal = 0 Then
           pNext = pDnsRecord
           Do While pNext <> 0
              CopyMemory DnsRecord, pNext, Len(DnsRecord)
              Select Case DnsRecord.wType
                 Case DNS_TYPE_A
                    Ptr = inet_ntoa(DnsRecord.ptrData)
                    TempString = String(lstrlen(Ptr), 0)
                    CopyMemory ByVal TempString, Ptr, Len(TempString)
                 Case DNS_TYPE_PTR, DNS_TYPE_NS, DNS_TYPE_CNAME,
    DNS_TYPE_DNAME, DNS_TYPE_MB,
    DNS_TYPE_MD, DNS_TYPE_MF,
    DNS_TYPE_MG, DNS_TYPE_MR
                    Ptr = DnsRecord.ptrData
                    TempString = String$(lstrlen(Ptr), 0)
                    CopyMemory ByVal TempString, Ptr, Len(TempString)
                 Case DNS_TYPE_TEXT, DNS_TYPE_HINFO, DNS_TYPE_ISDN,
    DNS_TYPE_TEXT, DNS_TYPE_X25
                    Dim TextData As Dns_Txt_Data
                    Ptr = DnsRecord.ptrData
                    CopyMemory VarPtr(TextData), Ptr, Len(TextData)
                    Stop
                 Case Else
                    TempString = "unhandled resource record type"
             End Select
             If Not FullRecord Then
                DnsLookup = "   " & TempString
                Exit Do
             Else
                DnsLookup = DnsLookup & " " & vbCrLf &
    DnsTypeNameFromCode(DnsRecord.wType)
    & " " & TempString
             End If
             pNext = DnsRecord.pNext
          Loop
    

    Now, when I put a breakpoint on the CopyMemory line and inspect the value of Ptr, I expect something in the millions or higher, indicating that it is a pointer, only I’m getting the value 1 (which explains why everything blows up when I try to copy from that memory location). This seems to indicate to me that instead of a pointer to the expected DNS_TXT_DATA struct, I’m getting the count of strings. When I examine Other(0) through Other(3), they all have values which make me suspect the next four bytes are a pointer. So what gives? Why is this struct just coming in “inline” but the others come in as pointers to the start of the struct?

I appreciate any help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T19:23:00+00:00Added an answer on May 13, 2026 at 7:23 pm

    1) C strings and VB strings different and you can’t just substitute one for another. You’ll need to explicitly convert the C string to a VB string. In other words, yes, your guess is reasonable.

    2) I took a quick look at the Microsoft docs, which say that DNS_TXT_DATA is a count followed by a pointer to a string (which is what you’re seeing). DNS_PTR_DATA, on the other hand, is a point to the resulting record. So what you’re describing seems to match the documentation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 390k
  • Answers 390k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer While the solution with sort: (sort {$hash{$a} <=> $hash{$b}} keys… May 15, 2026 at 1:03 am
  • Editorial Team
    Editorial Team added an answer Think of events like network packets, since they're usually handled… May 15, 2026 at 1:03 am
  • Editorial Team
    Editorial Team added an answer string[] a = { "a", "b" }; string[] b =… May 15, 2026 at 1:03 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.