Re: #import and wchar_t

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



"Igor Tandetnik" <itandetnik@xxxxxxxx> wrote in
news:#vu9rCAVGHA.5004@xxxxxxxxxxxxxxxxxxxx:

The sample is done in VC6 where wchar_t was always a typedef for
unsigned short. The compiler did not support it as a native type. I
guess nobody noticed the discrepancy back then, and the sample was not
updated since.

The sample is also internally inconsistent - note how
SAXContentHandlerImpl uses wchar_t but SAXErrorHandlerImpl uses
unsigned short.

The easiest thing to do is probably to use unsigned short throughout.
If for some reason you really want to use wchar_t, the following
(admittedly dirty) trick should work:

#import <msxml3.dll> raw_interfaces_only \
inject_statement("#define unsigned") inject_statement("#define
short
wchar_t") #undef unsigned #undef short

Luckily, "short" is never used on its own in this particular TLB, only
in combination with unsigned.
Hi Igor,

I have another question. The SAX2 JumpStart uses mbstowcs to convert
the url from a null terminated c style string to wide character text.
Whilst this works fine when not using wchar_t as a Built-In type, it
results in a compilation error when using wchar_t as a Built-In type.

If I use wchar_t as a Built-In type, what conversion functions can I use
to convert the c style string to the appropriate format?


Peter
.



Relevant Pages

  • Re: problem with output of the program on different OS
    ... traced to these zero/near zero values. ... There was a /possibility/ of a compiler bug, ... reason for the discrepancy, we didn't know that for sure. ... including of excluding a few edge rays causes a significant change to ...
    (comp.lang.c)
  • One more reason for using std::string instead of char * in C++ programs.
    ... There are two C style string stack variables ... and one C style string heap variable. ... The compiler may or may not optimize ... the space taken up by the two stack variables by placing them at the same ...
    (comp.lang.cpp)
  • Re: One more reason for using std::string instead of char * in C++ programs.
    ... There are two C style string stack ... > and one C style string heap variable. ... > C program is compiler dependent. ... However the output is compiler dependent, but it depends on whether the ...
    (comp.lang.cpp)
  • Re: #import and wchar_t
    ... the url from a null terminated c style string to wide character text. ... results in a compilation error when using wchar_t as a Built-In type. ...
    (microsoft.public.vc.language)
  • Re: define a size_t constant
    ... I got used to thinking of size_t as a built-in type. ... I want to minimize the number of casts and warnings of my programs. ... I don't think I've never seen such a warning. ... I think your compiler is being overly ...
    (comp.lang.c)