by Michael S. Kaplan, published on 2007/01/25 06:01 -05:00, original URI: http://blogs.msdn.com/b/michkap/archive/2007/01/25/1527214.aspx
Legolas (no relation to the elf of the same name!) asked:
Hi, I'd like to suggest something that may be in line with your recent 'convert to unicode' posts, although it's very specific, perhaps too specific. Anyway: for a print monitor, the function you pass in the MONITOR2 structure as pfnStartDocPort, gets a DOC_INFO_1 or DOC_INFO_2 structure passed as a LPBYTE. the level parameter tells me wether it's 1 or 2, but what I currently can't find: how do I know if I'll get the A or the W version? I can see nothing to indicate my preference, and if I read the docs right users of printers can pass whatever they want. I'm guessing windows is converting to the one I need, but how does it know what I need?
The answer -- it is ONLY ever Unicode.
CLUE #1: You can tell by the prototype in the documentation for StartDocPort and in winsplp.h:
BOOL (WINAPI *pfnStartDocPort)
(
HANDLE hPort,
LPWSTR pPrinterName,
DWORD JobId,
DWORD Level,
LPBYTE pDocInfo
);
See that 2nd parameter? It's an LPWSTR.SO this function can only be getting Unicode.
CLUE #2: The DOC_INFO_1 and DOC_INFO_2 structures choose their Unicodality based on the function called that gets them.
Since NT-based platforms only support DOC_INFO_1 (according to the docs) combined with the fact that the function is only in newer versions (which feeds into the fact that ANSI is not being added so much anymore) kinda conspires to requiring it all to be Unicode.
So, to indirectly answer the bigger question that Legolas posed -- to find out if a function takes Unicode or ANSI in otherwise ambiguous cases, one probably just has to do some spelunking around in the SDK and the DDK and the header files. :-)
This post brought to you by ឈ (U+1788, a.k.a. KHMER LETTER CHO)
# swautier on 25 Jan 2007 2:56 PM:
Word of the day: Unicodality
Unicodality: Property of an application or piece of code to support Unicode and/or ANSI [...]
# Michael S. Kaplan on 26 Jan 2007 11:00 AM:
Nah, you're thinking of UNICODEANSITY! :-)
# Legolas on 27 Jan 2007 7:03 AM:
Hey, thanks for replying to this so quickly. I had found that I got unicode strings through testing, but I was worried I missed something and some customer machine would suddenly give me Ansi instead. (And I did miss something, that second parameters type ;-)
I'll update my code with explicit DOC_INFO_1W and (a link to this post) on Monday!