On 05 Nov 2002 13:42:15 -0500, Vincent Béron <vberon(a)mecano.gme.usherb.ca>
wrote :
> From what I saw in a couple of places: from funcA, do some magic on the
> parameters (convert to Unicode), then call funcW, then reconvert the
> result from Unicode to ASCII. Yes you have to convert twice, but you use
> the same function.
I'm happy with that and will call it option 4. It will work in a large
number of cases, hence the large number of places it has been used in. (I
really don't know why I left it out, but is is problably because I tought
about the following: I'm wondering about the case where it (option 4) won't
work, let's say we have,
void funcA(char ch) { WriteFile(h, &ch, sizeof(char), &num, NULL); }
and
void funcW(WCHAR ch) { WriteFile(h, &ch, sizeof(WCHAR), &num, NULL); }
If we do the char -> WCHAR conversion, we will end up writing sizeof(WCHAR)
bytes for every single character. In this simplest case, we could define a
macro,
#define WRITE_CH(ch, type) WriteFile(h, &ch, sizeof(type), &num, NULL)
and this can be used in the functions,
void funcA(char ch) { WRITE_CH(ch, char); }
and
void funcW(WCHAR ch) { WRITE_CH(ch, WCHAR); }
In the case of similar bigger/longer functions, writing the macro is
problably not the right thing to do. And this is where I end up duplicating
code, eek.
Greetings,
Jaco