[ros-dev] CreateFile, typecasts and PICE loader
Murphy, Ged (Bolton)
MurphyG at cmpbatteries.co.uk
Fri Aug 4 10:20:14 CEST 2006
Felipe Villarroel wrote:
> Its ok to typecast the char* to LPCWSTR? as in
> file = CreateFile((LPCWSTR) SrcFileNames[i],GENERIC_READ , 0,
> NULL, OPEN_EXISTING, 0, 0); ?
No. If you wanted to use an ASCI where a Unicode char was expected, you
would have to first convert it to Unicode using a function like
However, CreateFile actually expects LPCTSTR as it's first parameter. It is
then converted to LPCSTR or LPCWSTR dependant on whether you have Unicode
defined. (In your case, you must have)
If this is the case, and you are using TCHAR within your code, then what is
the reason for the char? Maybe it's a value returned from a network read?
Could it be a TCHAR?
My first approach would be to see why it's a char, and not a TCHAR (or
WCHAR), and check whether you can change it in the source (perhaps it's just
something the PICE devs missed)
Secondly, if it must remain a char, but you still want to have Unicode
defined (as we mentioned, not having Unicode defined will call the ASCI
version, which will be fine for your char as it's first member is LPSTR),
then you could call the ASCI version of CreateFile exclusively by calling
> and also i have another question. Currently in the source
> (main.c) we assume in line 368 that sizeof(DWORD) ==
> sizeof(INT) and the compiler issues a warning. Its ok to
> typecast this too?
I'm assuming from '(PINT)&nStabLen' that you have a DWORD which you are
typecasting to an INT.
Whilst a DWORD and an INT are of the same size, a DWORD is an unsigned long,
and an INT is signed, which means typecasting from DWORD to INT could result
in data loss if nStabLen is a very high value i.e. more than an INT can
hold. (check your limits.h for this value, it's 2147483647 for 4 byte ints)
Is making nStabLen a DWORD not an option?
> Also, i'm a native spanish speaker. I would be happy to help
> in anyway i could.
Pop into IRC. There is always plenty for people to do ;)
More information about the Ros-dev