views:

456

answers:

2

I found a great C++/ODBC example here...

The project I downloaded builds great and everything works. However, when I copy the .cpp and .h files into another project, I seem to have a linking problem.

The SQLConnect function in sql.h is the one I want. When I right-click this function in the easyodbc.h file in the project I downloaded, it jumps to the declaration in sql.h. Life is good.

However, in the project I created, when I do this it jumps to a UNICODE definition in sqlucode.h. This seems to be causing problems and my test project crashes.

I don't have an #include for sqlucdode.h anywhere in my project, yet it still resolves the declaration to the one in sqlucode.h. How can I prevent this? Thanks.

+1  A: 

Seems like you have a preprocessor problem rather than a linking problem.

You probably have a preprocessor definition for UNICODE (or _UNICODE) in your project file. In Visual C++ 2005 and 2008 you can fix this by going to your project properties and changing Character Set from Use Unicode Character Set to Use Multi-Byte Character Set. When you apply this setting, Visual Studio fixes up the right preprocessor and linker settings for you.

If you have an earlier version of Visual Studio you can still fix it by changing the preprocessor definitions for UNICODE and _UNICODE to _MBCS - it's just you'll have to find them yourself.

EDIT: I just downloaded that example code and tried it - good news, it's exactly as I guessed, change to a multibyte character set and you'll be fine.

snowcrash09
where/how exactly would I add this define? I've tried a few things but I'm still getting build errors: error C2664: 'SQLConnectW' : cannot convert parameter 2 from 'SQLCHAR *' to 'SQLWCHAR *'
Dave Swersky
It depends what version of Visual C++ you're using - can you specify?
snowcrash09
That did it! I also had to open the project by itself- I had a solution with other C# projects in it, for some reason that made it resolve to sqlucode.h even with the project set to MBCS. Thanks!!!
Dave Swersky
No problem, glad it worked ;-)
snowcrash09
A: 

Thanks a lot for the information on changing the character set. In case there are others who had the same problem, and if you are using VC9, You have to go to Project Properties > Configuration Properties > General and change the value of the Character Set property.

What should I do if I need to keep UNICODE and _UNICODE preprocessor directives? Are these directives required if I need to read multilingual text from the database?

Ramesh M