It seems DnsServiceRegister can not work RRS feed

  • Question

  • Hi, all:

    I try to use this function to register a service.

    code portion:



        IP4_ADDRESS *ip4Address;
        IP6_ADDRESS *ip6Address;



    No matter how to fill ip4Address filed, got a address of stack variable, use new, use GlobalAlloc/LocalAlloc,

    In the register callback ip4Address  is always a nullptr.

    So can't query service information by other machine.

    Thank you for your help.

    Wednesday, July 8, 2020 3:38 AM

All replies

  • Did you also try DnsServiceConstructInstance?

    Wednesday, July 8, 2020 8:44 AM
  • Hello WuLongyue,

    IP4_ADDRESS is defined as a DWORD so you can assign it like this for example:

    	IP4_ADDRESS ip4 = 0x00000001;
    	DNS_SERVICE_INSTANCE si = { 0 };
    	si.ip4Address = &ip4;

    Please let me know if it works for you.

    Best regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, July 10, 2020 9:00 AM
  • Thank you for your reply.

    DnsServiceConstructInstance doesn't work too.

    The ip4Address is still nullptr even if uses DnsServiceConstructInstance.

    Tuesday, July 14, 2020 12:55 AM
  • Thank you for your reply.

    Your sample code doesn't work too.

    All the other field like wPort, wPriority, wWeight, pszHostName have not problem.

    Only ip4Address and ip6Address will become nullptr though I passed a valid pointer before to invoke the function.

    Tuesday, July 14, 2020 1:02 AM
  • Hello WuLongyue,

    Thanks for confirmation.

    Could you show a mini and reproducible sample? So we can do a further investigation.

    Best regards,


    "Win32 API" forum will be migrating to a new home on Microsoft Q&A !
    We invite you to post new questions in the "Win32 API" forum’s new home on Microsoft Q&A !
    For more information, please refer to the sticky post.

    Tuesday, July 14, 2020 5:30 AM