Author Topic: How to use sql*.h in C++ in mingw in C::B under WinXP?  (Read 8790 times)

Offline samsam598

  • Multiple posting newcomer
  • *
  • Posts: 15
How to use sql*.h in C++ in mingw in C::B under WinXP?
« on: December 15, 2009, 08:51:30 am »
When I tried to use sql.h sqlext.h etc reside in mingw\include,I found it is not a simple task in C++ environment.So many thing the compiler can not found:va_list,SQLHANDLE,SQLHDESC...
I was just creating a new project by new->console app->c++,using mingw.Below is the code:
Code
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <windef.h>
#include <winbase.h>
#include <windows.h>
#include <windowsx.h>
#include <sqltypes.h>
#include <sqlucode.h>
#include <sql.h>
#include <sqlext.h>
#include <iostream>
using namespace std;

int main()
{
    cout << "Hello world!" << endl;
    return 0;
}

But when I have another try in C environment,everything is fine:
Code

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>
#include <sql.h>
#include <sqlext.h>
int main()
{
    printf("Hello world!\n");
    return 0;
}

So what's wrong with what I have done?Help would be appreciated!

Regards,
Sam

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: How to use sql*.h in C++ in mingw in C::B under WinXP?
« Reply #1 on: December 15, 2009, 09:43:19 am »
Does sql.h and sqlext.h have extern "C" { } in them?
If not you should do:
Code
extern "C"
{
#include " ... "
#include " ... "
}
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

zabzonk

  • Guest
Re: How to use sql*.h in C++ in mingw in C::B under WinXP?
« Reply #2 on: December 15, 2009, 11:08:30 am »
I use th Windows SQL headers in C++ code all the time, with absolutely no problems. One thing I would observe is that your includes are different in the two samples - make them the same (apart from any C++ headers).

Also, this is not a Code::Blocks issue, so your question will probably shortly be locked. I suggest asking it somewhere like StackOverflow.

Offline samsam598

  • Multiple posting newcomer
  • *
  • Posts: 15
Re: How to use sql*.h in C++ in mingw in C::B under WinXP?
« Reply #3 on: December 15, 2009, 11:11:06 am »
Does sql.h and sqlext.h have extern "C" { } in them?
If not you should do:
Code
extern "C"
{
#include " ... "
#include " ... "
}

Thank you so much.It works now.

zabzonk

  • Guest
Re: How to use sql*.h in C++ in mingw in C::B under WinXP?
« Reply #4 on: December 15, 2009, 11:19:00 am »
Using the extern "C" should not be necessary, as the headers already do this for you. I think you have some other underlying problem in the way you are building your app.