From: hamishd on
Hi - sorry this is my 3rd question recently. I'm having trouble with
strings and characters and unicode in general; can anybody suggest a
good article to read which explains the basics?

My project is _UNICODE defined. However, a file I got from codeproject
is not. Their code is below, but it cannot compile.

char szBuf[2001];
WORD cbBufMax = 2000;
WORD cbBufOut;
char *pszBuf = szBuf;

SQLGetInstalledDrivers(szBuf,cbBufMax,& cbBufOut);

I would have thought changing the char's to TCHAR's would fix..
however, I still get "error C2664: 'SQLGetInstalledDriversW' : cannot
convert parameter 1 from 'char [2001]' to 'unsigned short *'"

Incidentally, I am trying to read data from an excel spreadsheet, and
trying the CSpreadSheet class from http://www.codeproject.com/KB/database/cspreadsheet.aspx.
From: David Webber on

"hamishd" <Hamish.Dean(a)gmail.com> wrote in message
news:dc1f26c5-6e3e-435a-9219-af0c908f09de(a)s9g2000prg.googlegroups.com...


> Hi - sorry this is my 3rd question recently. I'm having trouble with
> strings and characters and unicode in general; can anybody suggest a
> good article to read which explains the basics?
>
> My project is _UNICODE defined. However, a file I got from codeproject
> is not. Their code is below, but it cannot compile.
>
> char szBuf[2001];
> WORD cbBufMax = 2000;
> WORD cbBufOut;
> char *pszBuf = szBuf;
>
> SQLGetInstalledDrivers(szBuf,cbBufMax,& cbBufOut);
>
> I would have thought changing the char's to TCHAR's would fix..
> however, I still get "error C2664: 'SQLGetInstalledDriversW' : cannot
> convert parameter 1 from 'char [2001]' to 'unsigned short *'"

If you have TCHAR szBuf[2001] this should not happen.

In a UNICODE build TCHAR is WCHAR and teh function call is to SQL...W(..)
In a non-UNICODE build it is CHAR and SQL....A().

Are you sure you have used TCHAR consistently?

Dave
--
David Webber
Author of 'Mozart the Music Processor'
http://www.mozart.co.uk
For discussion/support see
http://www.mozart.co.uk/mozartists/mailinglist.htm

From: Tom Serface on
The help for SQLGetInstalledDrivers says:

BOOL SQLGetInstalledDrivers(
LPSTR lpszBuf,
WORD cbBufMax,
WORD * pcbBufOut);

Indicating that you have to use a char buffer, but it looks like it's
calling a W flavor which seems odd.... Even the error you're getting
doesn't make sense because the first You might try something like:

TCHAR szBuf[2001];
WORD cbBufMax = 2000 * sizeof(TCHAR);
WORD cbBufOut;
LPTSTR *pszBuf = szBuf; // Not sure what you're using this for exactly
maybe you intended to pass this into the function instead?

This link might have something useful for you. I admit I haven't used this
function so I'm sort of just guessing here.

http://bugs.mysql.com/bug.php?id=35776

Tom


"hamishd" <Hamish.Dean(a)gmail.com> wrote in message
news:dc1f26c5-6e3e-435a-9219-af0c908f09de(a)s9g2000prg.googlegroups.com...
> Hi - sorry this is my 3rd question recently. I'm having trouble with
> strings and characters and unicode in general; can anybody suggest a
> good article to read which explains the basics?
>
> My project is _UNICODE defined. However, a file I got from codeproject
> is not. Their code is below, but it cannot compile.
>
> char szBuf[2001];
> WORD cbBufMax = 2000;
> WORD cbBufOut;
> char *pszBuf = szBuf;
>
> SQLGetInstalledDrivers(szBuf,cbBufMax,& cbBufOut);
>
> I would have thought changing the char's to TCHAR's would fix..
> however, I still get "error C2664: 'SQLGetInstalledDriversW' : cannot
> convert parameter 1 from 'char [2001]' to 'unsigned short *'"
>
> Incidentally, I am trying to read data from an excel spreadsheet, and
> trying the CSpreadSheet class from
> http://www.codeproject.com/KB/database/cspreadsheet.aspx.

From: hamishd on
On Jan 8, 12:57 pm, "Tom Serface" <t...(a)nospam.camaswood.com> wrote:
> The help for SQLGetInstalledDrivers says:
>
> BOOL SQLGetInstalledDrivers(
>      LPSTR     lpszBuf,
>      WORD     cbBufMax,
>      WORD *     pcbBufOut);
>
> Indicating that you have to use a char buffer, but it looks like it's
> calling a W flavor which seems odd....  Even the error you're getting
> doesn't make sense because the first You might try something like:
>
>  TCHAR szBuf[2001];
>  WORD cbBufMax = 2000 * sizeof(TCHAR);
>  WORD cbBufOut;
>  LPTSTR *pszBuf = szBuf; // Not sure what you're using this for exactly
> maybe you intended to pass this into the function instead?

Sorry, that pointer is used later. No need to be there in this code
snippet.
From: hamishd on
On Jan 8, 12:31 pm, "David Webber" <d...(a)musical-dot-demon-dot-co.uk>
wrote:
> "hamishd" <Hamish.D...(a)gmail.com> wrote in message
>
> news:dc1f26c5-6e3e-435a-9219-af0c908f09de(a)s9g2000prg.googlegroups.com...
>
>
>
> > Hi - sorry this is my 3rd question recently. I'm having trouble with
> > strings and characters and unicode in general; can anybody suggest a
> > good article to read which explains the basics?
>
> > My project is _UNICODE defined. However, a file I got from codeproject
> > is not. Their code is below, but it cannot compile.
>
> > char szBuf[2001];
> > WORD cbBufMax = 2000;
> > WORD cbBufOut;
> > char *pszBuf = szBuf;
>
> > SQLGetInstalledDrivers(szBuf,cbBufMax,& cbBufOut);
>
> > I would have thought changing the char's to TCHAR's would fix..
> > however, I still get "error C2664: 'SQLGetInstalledDriversW' : cannot
> > convert parameter 1 from 'char [2001]' to 'unsigned short *'"
>
> If you have TCHAR szBuf[2001] this should not happen.
>
> In a UNICODE build TCHAR is WCHAR and teh function call is to SQL...W(..)
> In a non-UNICODE build it is CHAR and SQL....A().
>
> Are you sure you have used TCHAR consistently?

This is the entire function:

// Get the name of the Excel-ODBC driver
void CSpreadSheet::GetExcelDriver()
{
char szBuf[2001];
WORD cbBufMax = 2000;
WORD cbBufOut;
char *pszBuf = szBuf;

// Get the names of the installed drivers ("odbcinst.h" has to be
included )
if(!SQLGetInstalledDrivers(szBuf,cbBufMax,& cbBufOut))
{
m_sExcelDriver = "";
}

// Search for the driver...
do
{
if( strstr( pszBuf, "Excel" ) != 0 )
{
// Found !
m_sExcelDriver = CString( pszBuf );
break;
}
pszBuf = strchr( pszBuf, '\0' ) + 1;
}
while( pszBuf[1] != '\0' );
}

The error message is the same regardless of whether or not i use
TCHAR, WCHAR, or char.