318
319
320
321
322
323
324
|
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
to
```
ZbarAsyncDecodeObjCmd(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
```
### Deprecated of MS-Windows TCHAR utility functions
The MS-Windows string character type `TCHAR` is 8 bit or 16 bit, depending on preprocessor define `_UNICODE`.
This functionality is outdated today and only 16 bit string types should be used to call the MS-Windows API.
TCL 8.6 had two functions to support this, which are still present but deprecated and not documented any more.
In consequence, the following code should be replaced (with `_UNICODE` defined):
```
Tcl_Size lStr;
char *pStr;
Tcl_DString *dStr;
pStr = Tcl_GetStringFromObj(objv[PositionSPar],&lStr);
// Old
Tcl_WinUtfToTChar(pStr,lStr,dStr);
// New
Tcl_DStringInit( &sPar1 );
Tcl_UtfToWCharDString( pStr, lStr, &sPar1);
// both solutions
TextOutW(pdlg.hDC, X0, Y0, Tcl_DStringValue( &dPar1 ),
Tcl_DStringLength(&dPar1 )/sizeof(WCHAR));
```
Remark that the new function does not initialize the Dstring, but appends to it.
And the other way around (get the default printer name):
```
DWORD BufferSize;
TCHAR *pDefaultPrinter;
Tcl_DString Printer;
GetDefaultPrinter(NULL, &BufferSize);
if (BufferSize == 0) {return NULL;}
pDefaultPrinter = (TCHAR *) Tcl_Alloc(BufferSize * sizeof(TCHAR));
GetDefaultPrinter(pDefaultPrinter, &BufferSize);
// Old
Tcl_WinTCharToUtf(pDefaultPrinter, -1, &Printer);
// New
Tcl_DStringInit(&Printer);
Tcl_WCharToUtfDString(pDefaultPrinter, -1, &Printer);
// both
Tcl_Free((char *)pDefaultPrinter);
Tcl_DStringResult(interp, &Printer);
return RET_OK;
```
Remark the following difference of the old and the new function:
* The DString is not initialized allowing to append
* The size argument is in wide characters, not in bytes (e.g. `/ sizeof(WCHAR)`)
* Following the documentation, the argument `-1` was formerly not allowed for the size to read until the 0 word. This is not my observation (as seen in the upper code).
|