Using MSADO15.DLL and C++ with MinGW/GCC on Windows Vista
- by Eugen Mihailescu
INTRODUCTION
Hi,
I am very new to C++, is my 1st statement.
I have started initially with VC++ 2008 Express, I've notice that GCC becomes kind of standard so I am trying to make the right steps event from the beginning.
I have written a piece of code that connects to MSSQL Server via ADO, on VC++ it's working like a charm by importing MSADO15.dll:
#import "msado15.dll" no_namespace rename("EOF", "EndOfFile")
Because I am going to move from VC++ I was looking for an alternative (eventually multi-platform) IDE, so I stick (for this time) with Code::Block (I'm using last nightly buil, SVN 6181).
As compiler I choose to use GCC 3.4.5 (ported via MinGW 5.1.6), under Vista.
I was trying to compile a simple "hello world" application with GCC that use/import the same msado15.dll (#import "c:\Program Files\Common Files\System\ADO\msado15.dll" no_namespace rename("EOF", "EndOfFile")) and I was surprised to see a lot of compile-time errors.
I was expected that the #import compiler's directive will generate a library from "msado15.dll" so it can link to it later (link-edit time or whatever). Instead it was trying to read it as a normal file (like a header file,if you like) because it was trying to interprete each line in the DLL (which has a MZ signature):
Example:
Compiling: main.cpp
E:\MyPath\main.cpp:2:64: warning: extra tokens at end of #import directive
In file included from E:\MyPath\main.cpp:2:
c:\Program Files\Common Files\System\ADO\msado15.dll:1: error: stray '\144' in program
In file included from E:\MyPath\main.cpp:2:
c:\Program Files\Common Files\System\ADO\msado15.dll:1:4: warning: null character(s) ignored
c:\Program Files\Common Files\System\ADO\msado15.dll:1: error: stray '\3' in program
c:\Program Files\Common Files\System\ADO\msado15.dll:1:6: warning: null character(s) ignored
c:\Program Files\Common Files\System\ADO\msado15.dll:1: error: stray '\4' in program
...
and so on.
MY QUESTION
Well, it is obvious that under this version of GCC the #import directive does not do the expected job (perhaps #import is not supported anymore by GCC), so finally my question:
how to use the ADO to access MSSQL database on a C++ program compiled with GCC (v3.4.5)?