From: Joseph M. Newcomer on
All SQL documentation that specifies LPSTR/LPCSTR is erroneous. The header files for all
the SQL APIs define -W versions that take LPWSTR/LPCWSTR parameters. In fact, in a couple
cases the documentation erroneously specifes an LPSTR when the header says LPCSTR or an
LPCSTR when the header says LPSTR.

I have now added all of these to my Errors and Omissions document.
joe
On Wed, 7 Jan 2009 15:57:14 -0800, "Tom Serface" <tom(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?
>
>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.
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
From: Mihai N. on

> My project is _UNICODE defined. However, a file I got from codeproject
> is not.

You must always define both UNICODE and _UNICODE.
UNICODE controls the Win API, _UNICODE controls the CRT API.

To move something to Unicode you can also give a try to this:
http://www.mihai-nita.net/article.php?artID=tounicode



--
Mihai Nita [Microsoft MVP, Visual C++]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email
From: Mihai N. on
> TCHAR szBuf[2001];
> WORD cbBufMax = 2000 * sizeof(TCHAR);

Cleaner code trick:
TCHAR szBuf[2001];
WORD cbBufMax = _countof(szBuf) - 1;

This way you don't care about sizeof(TCHAR) and you don't deal
with magic numbers in many places.


_countof is a template thing available in newer VS versions.
If there is any chance that the code will need to be compiled
on VS 6, I usually do something like this:

#ifndef _countof
#define _countof(array) (sizeof(array)/sizeof(array[0]))
#endif

The nice part about the template version is that it complains if
applied on a pointer.



--
Mihai Nita [Microsoft MVP, Visual C++]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email
From: David Ching on

"Mihai N." <nmihai_year_2000(a)yahoo.com> wrote in message
news:Xns9B8CD781BB774MihaiN(a)207.46.248.16...
>> TCHAR szBuf[2001];
>> WORD cbBufMax = 2000 * sizeof(TCHAR);
>
> Cleaner code trick:
> TCHAR szBuf[2001];
> WORD cbBufMax = _countof(szBuf) - 1;
>
> This way you don't care about sizeof(TCHAR) and you don't deal
> with magic numbers in many places.
>
>
> _countof is a template thing available in newer VS versions.
> If there is any chance that the code will need to be compiled
> on VS 6, I usually do something like this:
>
> #ifndef _countof
> #define _countof(array) (sizeof(array)/sizeof(array[0]))
> #endif
>
> The nice part about the template version is that it complains if
> applied on a pointer.
>

OK I'm confused:

WORD cbBufMax = 2000 * sizeof(TCHAR); // <-- in UNICODE, this is
4000

but

TCHAR szBuf[2001];
WORD cbBufMax = _countof(szBuf) - 1; // <-- in UNICODE, this is
2000


So these are not equivalent in UNICODE (but they are in non-UNICODE).


Thanks,
David

From: Tom Serface on
I believe countof gives you the size of the array regardless of the size of
the items in the array whereas sizeof gives you the sizeof the item. I
think in the case of OP's function it wants the length of the buffer in
bytes rather than chars. That's why I used sizeof in this case.

Tom

"David Ching" <dc(a)remove-this.dcsoft.com> wrote in message
news:A6C7B9A3-DC41-432F-8463-600F5E487D6F(a)microsoft.com...
>
> "Mihai N." <nmihai_year_2000(a)yahoo.com> wrote in message
> news:Xns9B8CD781BB774MihaiN(a)207.46.248.16...

> OK I'm confused:
>
> WORD cbBufMax = 2000 * sizeof(TCHAR); // <-- in UNICODE, this is
> 4000
>
> but
>
> TCHAR szBuf[2001];
> WORD cbBufMax = _countof(szBuf) - 1; // <-- in UNICODE, this is
> 2000
>
>
> So these are not equivalent in UNICODE (but they are in non-UNICODE).
>
>
> Thanks,
> David