Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,209 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 921 people online right now. Registration is fast and FREE... Join Now!




Output compile gives strange errors

 
Reply to this topicStart new topic

Output compile gives strange errors

Muzz
post 16 Feb, 2008 - 09:01 AM
Post #1


New D.I.C Head

*
Joined: 16 Feb, 2008
Posts: 5


My Contributions


Hi everybody,

I've got some little compile issue's with one source file, My IDE is Visual C++ 2005 Express Edition with the SDK platform correctly installed.

This is the source file that has issue's continue'ing compiling (The errors are commented on the lines where they appears):

CODE
#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 *); // error C2059: syntax error : '('
typedef void WINAPI (*DNS_FREE)(PVOID, DNS_FREE_TYPE); // error C2059: syntax error : '('

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

    QLibrary lib("dnsapi");
    DNS_QUERY dnsQuery = (DNS_QUERY) lib.resolve("DnsQuery_UTF8"); //error C2143: syntax error : missing ';' before '='
    DNS_FREE dnsFree = (DNS_FREE) lib.resolve("DnsFree"); // error C2143: syntax error : missing ';' before '='
    if (dnsQuery == NULL || dnsFree == NULL) { // error C2059: syntax error : '==' AND error C2143: syntax error : missing ';' before '{'
        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;
}


Could somebody give me an quick help solving my issue?
User is offlineProfile CardPM

Go to the top of the page

NickDMax
post 16 Feb, 2008 - 09:38 AM
Post #2


2B||!2B

Group Icon
Joined: 18 Feb, 2007
Posts: 2,857



Thanked 47 times

Dream Kudos: 550
My Contributions


thinking out loud here:

let see it looks like you are using typedef to define function pointers.

so that would take the syntax:

typedef return_type (*function_Name)(argument_list);

...I wonder if the pesky WINAPI isn't getting in the way.

nope, the following works for me:
typedef void WINAPI (*foo)();


Rem out these lines and see what you get:
CODE
#define DNS_QUERY
#define DNS_FREE
#define dnsFree
#define dnsQuery

These are creating macros which are blank -- so what happens is the preprocessor makes your typedef lines look like this:
typedef DNS_STATUS WINAPI (*)(PCSTR, WORD, DWORD, PIP4_ARRAY, PDNS_RECORD *, PVOID *);
User is offlineProfile CardPM

Go to the top of the page

Muzz
post 16 Feb, 2008 - 10:05 AM
Post #3


New D.I.C Head

*
Joined: 16 Feb, 2008
Posts: 5


My Contributions


Hello, When I follow your help doing removing the 4 define's the follow generates:

QUOTE
1>------ Build started: Project: dnssrv, Configuration: Release Win32 ------
1>Compiling...
1>dnssrv_win.cpp
1>.\dnssrv\dnssrv_win.cpp(11) : error C2059: syntax error : '('
1>.\dnssrv\dnssrv_win.cpp(12) : error C2059: syntax error : '('
1>.\dnssrv\dnssrv_win.cpp(19) : error C2065: 'DNS_QUERY' : undeclared identifier
1>.\dnssrv\dnssrv_win.cpp(19) : error C2146: syntax error : missing ';' before identifier 'dnsQuery'
1>.\dnssrv\dnssrv_win.cpp(19) : error C2065: 'dnsQuery' : undeclared identifier
1>.\dnssrv\dnssrv_win.cpp(19) : error C2146: syntax error : missing ';' before identifier 'lib'
1>.\dnssrv\dnssrv_win.cpp(20) : error C2065: 'DNS_FREE' : undeclared identifier
1>.\dnssrv\dnssrv_win.cpp(20) : error C2146: syntax error : missing ';' before identifier 'dnsFree'
1>.\dnssrv\dnssrv_win.cpp(20) : error C2065: 'dnsFree' : undeclared identifier
1>.\dnssrv\dnssrv_win.cpp(20) : error C2146: syntax error : missing ';' before identifier 'lib'
1>.\dnssrv\dnssrv_win.cpp(27) : error C3861: 'dnsQuery': identifier not found
1>.\dnssrv\dnssrv_win.cpp(47) : error C3861: 'dnsFree': identifier not found
1>dnssrv - 12 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

When I do not remove that 4 defines, The follow generates:

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

Doing the
CODE
typedef DNS_STATUS WINAPI (*)(PCSTR, WORD, DWORD, PIP4_ARRAY, PDNS_RECORD *, PVOID *)
Will give the follow output when remove the both typedef's:

QUOTE
1>------ Build started: Project: dnssrv, Configuration: Release Win32 ------
1>Compiling...
1>dnssrv_win.cpp
1>.\dnssrv\dnssrv_win.cpp(15) : error C2059: syntax error : '('
1>.\dnssrv\dnssrv_win.cpp(18) : error C2143: syntax error : missing ';' before '{'
1>.\dnssrv\dnssrv_win.cpp(18) : 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 ==========


What to do?

This post has been edited by Muzz: 16 Feb, 2008 - 10:58 AM
User is offlineProfile CardPM

Go to the top of the page

Muzz
post 16 Feb, 2008 - 11:01 AM
Post #4


New D.I.C Head

*
Joined: 16 Feb, 2008
Posts: 5


My Contributions


Sorry for the late edit of my post.

This post has been edited by Muzz: 16 Feb, 2008 - 11:10 AM
User is offlineProfile CardPM

Go to the top of the page

NickDMax
post 16 Feb, 2008 - 11:05 AM
Post #5


2B||!2B

Group Icon
Joined: 18 Feb, 2007
Posts: 2,857



Thanked 47 times

Dream Kudos: 550
My Contributions


ok... I did a few more tests, and so far I am not able to reproduce your error.

my thinking is that there is a syntax error somewhere before the (*DNS_QUERY)... there is a good chance that this is caused by a macro (pesky things).

I was going to say make sure that DNS_QUERY was not defined elsewhere, but the error, "'DNS_QUERY' : undeclared identifier" indicates that it is not a macro (unless it is a macro that contains its own name).

I was going to say add in:
CODE
#ifdef DNS_QUERY
#warning DNS_QUERY is already defined.
#endif
befor the typedef, but I am pretty sure that it is not already defined.

The other macros are all defined in windns.h or windows.h... ummmph

QUOTE
In your post you olso mention that 'typedef', I've both removed the orginals and place the one there and added the four define's you asked to rem out.


so you added in the foo typedef and got those errors?

I assume that looked like this:
CODE
#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 void WINAPI (*foo)();


if this is the case, rem out the includes one at a time, starting at the top and moving down (don't take out windows.h as that will remove WINAPI).
User is offlineProfile CardPM

Go to the top of the page

Muzz
post 16 Feb, 2008 - 11:12 AM
Post #6


New D.I.C Head

*
Joined: 16 Feb, 2008
Posts: 5


My Contributions


Okay, Once agian sorry for my late edit post while your where posting your answer.

Here's my situation right now, I've done rem's on the includes (Leaved windows.h in it) would give me a lot more error's.

My source file is as follow right now:
CODE
#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:
CODE
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 ==========
User is offlineProfile CardPM

Go to the top of the page

NickDMax
post 16 Feb, 2008 - 12:19 PM
Post #7


2B||!2B

Group Icon
Joined: 18 Feb, 2007
Posts: 2,857



Thanked 47 times

Dream Kudos: 550
My Contributions


Well when I was talking about removing the headers I was only talking about the little example I gave, not your program (which obviously needs these headers to compile).

This is a syntax error... you don't give a name to the typedef (i.e. the function_name is blank):
typedef DNS_STATUS WINAPI (*)(PCSTR, WORD, DWORD, PIP4_ARRAY, PDNS_RECORD *, PVOID *)

User is offlineProfile CardPM

Go to the top of the page

Muzz
post 16 Feb, 2008 - 12:37 PM
Post #8


New D.I.C Head

*
Joined: 16 Feb, 2008
Posts: 5


My Contributions


Mhh, okay, but is my source file fixable or is it too difficult to do? Im so totally completly lost haha
User is offlineProfile CardPM

Go to the top of the page

NickDMax
post 16 Feb, 2008 - 12:57 PM
Post #9


2B||!2B

Group Icon
Joined: 18 Feb, 2007
Posts: 2,857



Thanked 47 times

Dream Kudos: 550
My Contributions


no we want to keep the original source. We just want to trouble shoot the syntax. The best thing to do is to simplify the file as much as possible (take out eveything that we can and leave in only the parts we are trouble shooting).

The syntax that you are using to define your function pointers SEEMS to be correct -- so my guess is that the error is caused either by an errant macro (which happens), or with a syntax error in one of the header files.

generally speaking we try to work out such problems by starting at the top and working our way down (a single syntax error at the top can lead the compiler to report all sorts of errors (which are not really errors) farther down in the file... so generally I start with the first error found and work my way down. We are working on getting rid of the error in the typedef lines.

SO, to attempt to work this out I would try commenting out everything but the two typedefs and the includes and see if the error still occurs. -- IF IT STILL occurs then comment out the other includes (trying to leave in windows.h and windns.h).

Simplify as much as you can, then build back up the original file.
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/21/08 07:41PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month