Thread: dnsapi.dll

  1. #1
    Registered User
    Join Date
    May 2006



    I want to call dnsapi.dll and get DnsQuery_A for a specific domain..
    DNS_RECORD *pQueryRec; is where the results are stored.

    Now I want to copy pNameExchange to server:
    char *server;
    server = new char[strlen(pQueryRec->Data.MX.pNameExchange) + 1];
    strcpy(server, pQueryRec->Data.MX.pNameExchange);
    And I get:
    cannot convert parameter 1 from 'PWSTR' to 'const char *'
    for strlen and strcpy.

    I've looked what PWSTR is and couldnt find any good answers. Not sure if I should go with casting, or what else should I do?

  2. #2
    I am me, who else?
    Join Date
    Oct 2002
    You cannot use it like that. PWSTR is in windows at least a type def for a null terminated 16-bit unicode string. Meaning simple char* types of strings will not work. WCHAR is a multi-byte CHAR (depending on platforms and whatnot, this may vary, but on Win xp I am pretty sure it is). You need to use a WCHAR for this to work properly. Simply replace all references to char with WCHAR and you should be set. If this is on windows you will be fine, otherwise it could be more problematic.

  3. #3
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    It looks like you have UNICODE defined. You can either turn this off in the compiler settings, or explicitly use the DNS_RECORDA structure (probably a good idea as you are using the DnsQuery_A function).

    There is an example of using the DNS API here and another one here.

Popular pages Recent additions subscribe to a feed