VenkatB

Hi,

I get the following errors when i convert to Visual Studio 2005. Inclusion of ODBCSS.h causes the problem.

-- Start Error Message

1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\ODBCSS.h(430) : error C2371: 'WCHAR' : redefinition; different basic types

1> C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\winnt.h(266) : see declaration of 'WCHAR'

-- End Error Message

Can you please tell me what is wrong Any help is appreciated.

Regards,

Venkat



Re: Visual C++ General wchar redefinition in ODBCSS.h

Prasad Somwanshi

Make sure windows.h or afxwin.h( if its MFC app) is included before this include. Ideal sequence would be.

#include <afxcmn.h> //if MFC

#include <sql.h>

#include <odbcss.h>

or

#include <windows.h>

#include <sql.h>

#include <odbcss.h>





Re: Visual C++ General wchar redefinition in ODBCSS.h

VenkatB

Thanks for the reply.

The include files listed above doesn't fix te problem. In my opinion, winnt.h has WCHAR wrongly defined.

winnt.h definition of WCHAR -

ifndef _MAC
typedef wchar_t WCHAR; // wc, 16-bit UNICODE character
#else
// some Macintosh compilers don't define wchar_t in a convenient location, or define it as a char
typedef unsigned short WCHAR; // wc, 16-bit UNICODE character
#endif

while odbcss.h has WCHAR defined as

#ifdef UNICODE
typedef wchar_t DBCHAR;
#else
typedef char DBCHAR;
#endif

where DBCHAR is

#define DBCHAR WCHAR
I have marked the confilcting definitions in red




Re: Visual C++ General wchar redefinition in ODBCSS.h

Prasad Somwanshi

In my opinion, winnt.h has WCHAR wrongly defined.

No, it is not.

 

ifndef _MAC
typedef wchar_t WCHAR; // wc, 16-bit UNICODE character
#else

Here wchar_t will  be called as WCHAR.

#ifdef UNICODE
typedef wchar_t DBCHAR;
#else
typedef char DBCHAR;
#endif
here wchar_t will be called as DBCHAR(watch UNICODE preprocessor).
 
So only possible problem could be include sequence.
Again, I suggest you to try this is simple application.




Re: Visual C++ General wchar redefinition in ODBCSS.h

VenkatB

DBCHAR is defined as WCHAR.

#define DBCHAR WCHAR (ocdb.h)

I have unicode turned off and my OS is non MAC.

Under the above mentioned conditions.

winnt.h defines WCHAR as type wchar_t

while odbcss.h defines WCHAR as char.

In my opinion winnt.h definition is wrong because it doesn't take into account non-unicode setup.





Re: Visual C++ General wchar redefinition in ODBCSS.h

TilakGopi

Hi,

including as follows

#include <sql.h>

#include <odbcss.h>

is not creating any problem(in VS2005).

So, Try as Prasad said.If the problem is not solved still, it's better to post the code.

Thanx,

Ch.T.Gopi Kumar






Re: Visual C++ General wchar redefinition in ODBCSS.h

VenkatB

Hi,

A new project works fine but Im working on an older project. All i did was convert from VS 2003 to VS 2005. When i Google redefinition of wchar in odbcss.h, i get couple hits but no one has posted a solution :(
I just started comparing precompiled header file and project settings with a new vs2005 project.

Thank you.

Regards,

Venkat





Re: Visual C++ General wchar redefinition in ODBCSS.h

VenkatB

OK i found out a way to reproduce this problem in VS 2005.

Create a new MFC extended DLL project using VS 2005 ( dll may not be necessary to reproduce issue).

Add include files listed by Prasad.

Change "Character Set" option to "Not Set" and build. WCHAR redefinition errors are encountered.

This proves my point. Winnt.h has a bug.

Regards,

Venkat

 





Re: Visual C++ General wchar redefinition in ODBCSS.h

baerol

Got exactly the same error.

In VC8 version of afxdisp.h, there are these new lines :

...

#ifndef __AFXOCC_H__
#include <afxocc.h>
#endif

....

These lines don't exist in VC7 version of afxdisp.h ....

And afxocc.h includes ocdb.h, which conflicts with odbcss.h.

In VC7, ocdb.h was not included.

In a new VC8 MFC Project, if I use the following #define before #include <afxdisp.h>, the compilation works (even if not in UNICODE) :

#define __AFXOCC_H__
#include <afxdisp.h> // Classes MFC Automation

But I don't know if there's a side-effect....