PDA

View Full Version : lib("dnsapi")



CHeader
15th February 2008, 19:07
Hi,

Im currently making an new DNS Server, But QT does give the follow error's while compiling:


dnsserv\dnssrv_win.cpp(10) : error C2059: syntax error : '('
dnsserv\dnssrv_win.cpp(12) : error C2059: syntax error : '('
dnsserv\dnssrv_win.cpp(19) : error C2065: 'DNS_QUERY' : undeclared identifier
dnsserv\dnssrv_win.cpp(19) : error C2146: syntax error : missing ';' before identifier 'dnsQuery'
dnsserv\dnssrv_win.cpp(19) : error C2065: 'dnsQuery' : undeclared identifier
dnsserv\dnssrv_win.cpp(19) : error C2146: syntax error : missing ';' before identifier 'lib'
dnsserv\dnssrv_win.cpp(20) : error C2065: 'DNS_FREE' : undeclared identifier
dnsserv\dnssrv_win.cpp(20) : error C2146: syntax error : missing ';' before identifier 'dnsFree'
dnsserv\dnssrv_win.cpp(20) : error C2065: 'dnsFree' : undeclared identifier
dnsserv\dnssrv_win.cpp(20) : error C2146: syntax error : missing ';' before identifier 'lib'
dnsserv\dnssrv_win.cpp(27) : error C3861: 'dnsQuery': identifier not found
dnsserv\dnssrv_win.cpp(47) : error C3861: 'dnsFree': identifier not found
Generating Code...

NMAKE : fatal error U1077: 'cl' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files\Microsoft Visual Studio 8\VC\BIN\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: 'cd' : return code '0x2'
Stop.

The source file is currently:


#include "dnssrv.h"
#include <QLibrary>
#include <windows.h>
#include <windns.h>

#ifndef DNS_QUERY_SRV
#define DNS_QUERY_SRV 0x0021
#endif

typedef DNS_STATUS WINAPI (*DNS_QUERY)(PCSTR, WORD, DWORD, PIP4_ARRAY, PDNS_RECORD *, PVOID *);
typedef void WINAPI (*DNS_FREE)(PVOID, DNS_FREE_TYPE);

QList<DnsSrv::Server> DnsSrv::resolve(const QString &name)
{
QList<DnsSrv::Server> servers;

QLibrary lib("dnsapi");
DNS_QUERY dnsQuery = (DNS_QUERY) lib.resolve("DnsQuery_UTF8");
DNS_FREE dnsFree = (DNS_FREE) lib.resolve("DnsFree");
if (dnsQuery == NULL || dnsFree == NULL) {
qDebug("Windows does not support DnsQuery");
goto failed;
}

PDNS_RECORD rr;
if (dnsQuery(name.toUtf8(), DNS_QUERY_SRV,
DNS_QUERY_STANDARD, NULL, &rr, NULL) != 0)
goto failed;

name.toLower();
for (PDNS_RECORD p = rr; p != NULL; p = p->pNext) {
if (p->wType != DNS_QUERY_SRV ||
QString((char *) p->pName).toLower() != name)
continue;

DNS_SRV_DATA *srv = &p->Data.Srv;

DnsSrv::Server res;
res.ttl = p->dwTtl;
res.priority = srv->wPriority;
res.weight = srv->wWeight;
res.port = srv->wPort;
res.target = (char *) srv->pNameTarget;
servers.append(res);
}
dnsFree(rr, DnsFreeRecordList);

failed:
lib.unload();
return servers;
}

How do I fix those error's? Im with my hands in my hair. Thank you.

jpn
15th February 2008, 21:39
Does windns.h define DNS_QUERY and DNS_FREE?

CHeader
16th February 2008, 00:46
This is really dump, I get confused. Stupid heh?

This is my header file:


#ifndef DNSSRV_H
#define DNSSRV_H

#include <QThread>
#include <QList>

class DnsSrv : public QThread {
Q_OBJECT
public:
class Server {
public:
Server();
bool operator <(const Server &rr) const;
bool operator ==(const Server &rr) const;

QString target;
int ttl;
int port;
int priority;
int weight;
};

DnsSrv(QObject *parent = 0);
virtual ~DnsSrv();

void query(const QString &name);
QList<Server> getResults() { return servers; }

signals:
void resultsReady();

private:
virtual void run();
QList<Server> resolve(const QString &name);

QString targetName;
QList<Server> servers;
};

#endif


The compile gives now:


1>dnssrv.obj : error LNK2019: unresolved external symbol "private: class QList<class DnsSrv::Server> __thiscall DnsSrv::resolve(class QString const &)" (?resolve@DnsSrv@@AAE?AV?$QList@VServer@DnsSrv@@@@ ABVQString@@@Z) referenced in function "private: virtual void __thiscall DnsSrv::run(void)" (?run@DnsSrv@@EAEXXZ)

CHeader
16th February 2008, 11:55
Im stupid, I've posted another header file that was included in dnssrv_win.cpp.

Anyway, this is the windns.h file you asked for, Its zipped because the file was too large to post here. I cannot find directly the define's of DNS_FREE and DNS_QUERY.

The follow error appears when compiling now:

QList<DnsSrv::Server> DnsSrv::resolve(const QString &name)

jpn
16th February 2008, 12:24
I'm not really a WinAPI expert so I don't know about possible side effects it causes but this at least compiles for me as soon as I comment out the WINAPI part:


// main.cpp
#include <windows.h>
#include <windns.h>

typedef DNS_STATUS /*WINAPI*/ (*DNS_QUERY)(PCSTR, WORD, DWORD, PIP4_ARRAY, PDNS_RECORD *, PVOID *);
typedef void /*WINAPI*/ (*DNS_FREE)(PVOID, DNS_FREE_TYPE);

int main()
{
}

CHeader
16th February 2008, 12:35
Well, I've did what you've tested right now, Seems to be not working now.

There's in dnssrv_win.cpp a couple of compile errors:


1>------ Build started: Project: dnsserv, Configuration: Release Win32 ------
1>Compiling...
1>dnssrv_win.cpp
1>.\dnsserv\dnssrv_win.cpp(10) : error C2143: syntax error : missing ';' before '__stdcall'
1>.\dnsserv\dnssrv_win.cpp(10) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>.\dnsserv\dnssrv_win.cpp(10) : error C2059: syntax error : '('
1>.\dnsserv\dnssrv_win.cpp(11) : error C2059: syntax error : '('
1>.\dnsserv\dnssrv_win.cpp(18) : error C2065: 'DNS_QUERY' : undeclared identifier
1>.\dnsserv\dnssrv_win.cpp(18) : error C2146: syntax error : missing ';' before identifier 'dnsQuery'
1>.\dnsserv\dnssrv_win.cpp(18) : error C2065: 'dnsQuery' : undeclared identifier
1>.\dnsserv\dnssrv_win.cpp(18) : error C2146: syntax error : missing ';' before identifier 'lib'
1>.\dnsserv\dnssrv_win.cpp(19) : error C2065: 'DNS_FREE' : undeclared identifier
1>.\dnsserv\dnssrv_win.cpp(19) : error C2146: syntax error : missing ';' before identifier 'dnsFree'
1>.\dnsserv\dnssrv_win.cpp(19) : error C2065: 'dnsFree' : undeclared identifier
1>.\dnsserv\dnssrv_win.cpp(19) : error C2146: syntax error : missing ';' before identifier 'lib'
1>.\dnsserv\dnssrv_win.cpp(25) : error C2065: 'PDNS_RECORD' : undeclared identifier
1>.\dnsserv\dnssrv_win.cpp(25) : error C2146: syntax error : missing ';' before identifier 'rr'
1>.\dnsserv\dnssrv_win.cpp(25) : error C2065: 'rr' : undeclared identifier
1>.\dnsserv\dnssrv_win.cpp(27) : error C2065: 'DNS_QUERY_STANDARD' : undeclared identifier
1>.\dnsserv\dnssrv_win.cpp(26) : error C3861: 'dnsQuery': identifier not found
1>.\dnsserv\dnssrv_win.cpp(31) : error C2146: syntax error : missing ';' before identifier 'p'
1>.\dnsserv\dnssrv_win.cpp(31) : error C2065: 'p' : undeclared identifier
1>.\dnsserv\dnssrv_win.cpp(31) : error C2146: syntax error : missing ')' before identifier 'p'
1>.\dnsserv\dnssrv_win.cpp(31) : error C2059: syntax error : ';'
1>.\dnsserv\dnssrv_win.cpp(31) : error C2227: left of '->pNext' must point to class/struct/union/generic type
1> type is ''unknown-type''
1>.\dnsserv\dnssrv_win.cpp(31) : error C2059: syntax error : ')'
1>.\dnsserv\dnssrv_win.cpp(31) : error C2143: syntax error : missing ';' before '{'
1>.\dnsserv\dnssrv_win.cpp(32) : error C2227: left of '->wType' must point to class/struct/union/generic type
1> type is ''unknown-type''
1>.\dnsserv\dnssrv_win.cpp(33) : error C2227: left of '->pName' must point to class/struct/union/generic type
1> type is ''unknown-type''
1>.\dnsserv\dnssrv_win.cpp(33) : error C2228: left of '.toLower' must have class/struct/union
1>.\dnsserv\dnssrv_win.cpp(34) : error C2044: illegal continue
1>.\dnsserv\dnssrv_win.cpp(36) : error C2065: 'DNS_SRV_DATA' : undeclared identifier
1>.\dnsserv\dnssrv_win.cpp(36) : error C2065: 'srv' : undeclared identifier
1>.\dnsserv\dnssrv_win.cpp(36) : error C2227: left of '->Data' must point to class/struct/union/generic type
1> type is ''unknown-type''
1>.\dnsserv\dnssrv_win.cpp(36) : error C2228: left of '.Srv' must have class/struct/union
1>.\dnsserv\dnssrv_win.cpp(39) : error C2227: left of '->dwTtl' must point to class/struct/union/generic type
1> type is ''unknown-type''
1>.\dnsserv\dnssrv_win.cpp(40) : error C2227: left of '->wPriority' must point to class/struct/union/generic type
1> type is ''unknown-type''
1>.\dnsserv\dnssrv_win.cpp(41) : error C2227: left of '->wWeight' must point to class/struct/union/generic type
1> type is ''unknown-type''
1>.\dnsserv\dnssrv_win.cpp(42) : error C2227: left of '->wPort' must point to class/struct/union/generic type
1> type is ''unknown-type''
1>.\dnsserv\dnssrv_win.cpp(43) : error C2227: left of '->pNameTarget' must point to class/struct/union/generic type
1> type is ''unknown-type''
1>.\dnsserv\dnssrv_win.cpp(46) : error C2065: 'DnsFreeRecordList' : undeclared identifier
1>.\dnsserv\dnssrv_win.cpp(46) : error C3861: 'dnsFree': identifier not found
1>dnsserv - 39 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


Agian olso the modified source file:


#include "dnssrv.h"
#include <QLibrary>
#include <windows.h>


#ifndef DNS_QUERY_SRV
#define DNS_QUERY_SRV 0x0021
#endif

typedef DNS_STATUS WINAPI (*DNS_QUERY)(PCSTR, WORD, DWORD, PIP4_ARRAY, PDNS_RECORD *, PVOID *);
typedef void WINAPI (*DNS_FREE)(PVOID, DNS_FREE_TYPE);

QList<DnsSrv::Server> DnsSrv::resolve(const QString &name)
{
QList<DnsSrv::Server> servers;

QLibrary lib("dnsapi");
DNS_QUERY dnsQuery = (DNS_QUERY) lib.resolve("DnsQuery_UTF8");
DNS_FREE dnsFree = (DNS_FREE) lib.resolve("DnsFree");
if (dnsQuery == NULL || dnsFree == NULL) {
qDebug("Windows does not support DnsQuery");
goto failed;
}

PDNS_RECORD rr;
if (dnsQuery(name.toUtf8(), DNS_QUERY_SRV,
DNS_QUERY_STANDARD, NULL, &rr, NULL) != 0)
goto failed;

name.toLower();
for (PDNS_RECORD p = rr; p != NULL; p = p->pNext) {
if (p->wType != DNS_QUERY_SRV ||
QString((char *) p->pName).toLower() != name)
continue;

DNS_SRV_DATA *srv = &p->Data.Srv;

DnsSrv::Server res;
res.ttl = p->dwTtl;
res.priority = srv->wPriority;
res.weight = srv->wWeight;
res.port = srv->wPort;
res.target = (char *) srv->pNameTarget;
servers.append(res);
}
dnsFree(rr, DnsFreeRecordList);

failed:
lib.unload();
return servers;
}

Maybe this oucld help solving you something?

jpn
16th February 2008, 12:53
Huh? I don't see anything else changed but you left the required <windns.h> header out?

CHeader
16th February 2008, 13:05
My mistake haha, When I include <windns.h> there are 4 error's (Mainly define's maybe?) and when I remove the include. I get 39 error's.

I've included the <windns.h> file and now this is the result:



1>------ Build started: Project: dnsserv, Configuration: Release Win32 ------
1>Compiling...
1>dnssrv_win.cpp
1>.\dnsserv\dnssrv_win.cpp(24) : error C2143: syntax error : missing ';' before '='
1>.\dnsserv\dnssrv_win.cpp(25) : error C2143: syntax error : missing ';' before '='
1>.\dnsserv\dnssrv_win.cpp(26) : error C2059: syntax error : '=='
1>.\dnsserv\dnssrv_win.cpp(26) : error C2143: syntax error : missing ';' before '{'
1>dnsserv - 4 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


The file looks like this:


#include <QLibrary>
#include "dnssrv.h"
#include <windows.h>
#include <windns.h>

#define DNS_QUERY
#define DNS_FREE

#define dnsFree
#define dnsQuery

#ifndef DNS_QUERY_SRV
#define DNS_QUERY_SRV 0x0021
#endif

//typedef DNS_STATUS WINAPI (*DNS_QUERY)(PCSTR, WORD, DWORD, PIP4_ARRAY, PDNS_RECORD *, PVOID *);
//typedef void WINAPI (*DNS_FREE)(PVOID, DNS_FREE_TYPE);

QList<DnsSrv::Server> DnsSrv::resolve(const QString &name)
{
QList<DnsSrv::Server> servers;

QLibrary lib("dnsapi");
DNS_QUERY dnsQuery = (DNS_QUERY) lib.resolve("DnsQuery_UTF8");
DNS_FREE dnsFree = (DNS_FREE) lib.resolve("DnsFree");
if (dnsQuery == NULL || dnsFree == NULL) {
qDebug("Windows does not support DnsQuery");
goto failed;
}

PDNS_RECORD rr;
if (dnsQuery(name.toUtf8(), DNS_QUERY_SRV,
DNS_QUERY_STANDARD, NULL, &rr, NULL) != 0)
goto failed;

name.toLower();
for (PDNS_RECORD p = rr; p != NULL; p = p->pNext) {
if (p->wType != DNS_QUERY_SRV ||
QString((char *) p->pName).toLower() != name)
continue;

DNS_SRV_DATA *srv = &p->Data.Srv;

DnsSrv::Server res;
res.ttl = p->dwTtl;
res.priority = srv->wPriority;
res.weight = srv->wWeight;
res.port = srv->wPort;
res.target = (char *) srv->pNameTarget;
servers.append(res);
}
dnsFree(rr, DnsFreeRecordList);

failed:
lib.unload();
return servers;
}

jpn
16th February 2008, 13:50
Take a new look at post #5. They're used as function pointers so you can't replace them with empty defines.

CHeader
16th February 2008, 15:07
Mhh. That would return me 6 errors.

CHeader
16th February 2008, 19:21
Okay. After some hours of testing and headers and stuff the follow situation is here:

My source file is as follow right now:

#include <QLibrary>
#include "dnssrv.h"
#include <windows.h>
#include <windns.h>

#ifdef DNS_QUERY
#define dnsQuery
#warning DNS_QUERY is already defined.
#endif

#ifdef DNS_FREE
#define dnsFree
#warning DNS_FREE is already defined.
#endif

#ifndef DNS_QUERY_SRV
#define DNS_QUERY_SRV 0x0021
#endif

// typedef DNS_STATUS WINAPI (*DNS_QUERY)(PCSTR, WORD, DWORD, PIP4_ARRAY, PDNS_RECORD *, PVOID *);
// typedef void WINAPI (*DNS_FREE)(PVOID, DNS_FREE_TYPE);
typedef DNS_STATUS WINAPI (*)(PCSTR, WORD, DWORD, PIP4_ARRAY, PDNS_RECORD *, PVOID *)

QList<DnsSrv::Server> DnsSrv::resolve(const QString &name)
{
QList<DnsSrv::Server> servers;

QLibrary lib("dnsapi");
DNS_QUERY dnsQuery = (DNS_QUERY) lib.resolve("DnsQuery_UTF8");
DNS_FREE dnsFree = (DNS_FREE) lib.resolve("DnsFree");
if (dnsQuery == NULL || dnsFree == NULL) {
qDebug("Windows does not support DnsQuery");
goto failed;
}

PDNS_RECORD rr;
if (dnsQuery(name.toUtf8(), DNS_QUERY_SRV,
DNS_QUERY_STANDARD, NULL, &rr, NULL) != 0)
goto failed;

name.toLower();
for (PDNS_RECORD p = rr; p != NULL; p = p->pNext) {
if (p->wType != DNS_QUERY_SRV ||
QString((char *) p->pName).toLower() != name)
continue;

DNS_SRV_DATA *srv = &p->Data.Srv;

DnsSrv::Server res;
res.ttl = p->dwTtl;
res.priority = srv->wPriority;
res.weight = srv->wWeight;
res.port = srv->wPort;
res.target = (char *) srv->pNameTarget;
servers.append(res);
}
dnsFree(rr, DnsFreeRecordList);

failed:
lib.unload();
return servers;
}

Compiling log:

1>------ Build started: Project: dnssrv, Configuration: Release Win32 ------
1>Compiling...
1>dnssrv_win.cpp
1>.\dnssrv\dnssrv_win.cpp(22) : error C2059: syntax error : '('
1>.\dnssrv\dnssrv_win.cpp(25) : error C2143: syntax error : missing ';' before '{'
1>.\dnssrv\dnssrv_win.cpp(25) : error C2447: '{' : missing function header (old-style formal list?)
1>dnssrv - 3 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========