Newbie question regarding data type casts.

G

Guest

Folks,

I've inherited some C++ code that I'm trying to convert from VC++ 6.0 to
VC++ 2005 and was wondering if anyone could help as I haven't done any C++
programming in several years.

The code is basically trying to populate a struct that is defined in the
sspi.h file. The compile error that I'm getting is "error C2440:
'initializing' cannot convert from wchar_t* to unsigned short*".

Here is the code to populate the struct:

const wchar_t* pszAuthority
const wchar_t* pszPrincipal
const wchar_t* pszPassword

SEC_WINNT_AUTH_IDENTITY_EX authIdent = {
SEC_WINNT_AUTH_IDENTITY_VERSION,
sizeof authIdent,
const_cast<wchar_t*>(pszPrincipal), //*****Compilie error here******
lstrlenW(pszPrincipal),
const_cast<wchar_t*>(pszAuthority), //*****Compilie error here******
lstrlenW(pszAuthority),
const_cast<wchar_t*>(pszPassword), //*****Compilie error here*****
lstrlenW(pszPassword),
SEC_WINNT_AUTH_IDENTITY_UNICODE,
0,
0};

The struct is defined as follows in the sspi.h header file

#define SEC_WINNT_AUTH_IDENTITY_EX SEC_WINNT_AUTH_IDENTITY_EXW

typedef struct _SEC_WINNT_AUTH_IDENTITY_EXW {
unsigned long Version;
unsigned long Length;
unsigned short SEC_FAR *User;
unsigned long UserLength;
unsigned short SEC_FAR *Domain;
unsigned long DomainLength;
unsigned short SEC_FAR *Password;
unsigned long PasswordLength;
unsigned long Flags;
unsigned short SEC_FAR * PackageList;
unsigned long PackageListLength;
} SEC_WINNT_AUTH_IDENTITY_EXW, *PSEC_WINNT_AUTH_IDENTITY_EXW;

I guess the question is what is the best way to "cast" a wchar_t* to a
unsigned short* so that it will compile and run correctly? Any help or
feedback would be greatly appreciated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top