Skip to content
Tcl Source Code Changes To Migrating C extensions to Tcl 9
Login

Changes To Migrating C extensions to Tcl 9

Changes to "Migrating C extensions to Tcl 9" between 2025-04-25 17:24:37 and 2025-04-26 11:09:42

︙
340
341
342
343
344
345
346








347
348
349
350
351
352
353
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361







+
+
+
+
+
+
+
+







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.
The function `Tcl_UtfToWCharDString` was introduced with TCL9.
If a compilation with TCL 8.6 and TCL9 is aimed, one may use the TCL8.6 routine with compatible signature:

```
#if (TCL_MAJOR_VERSION < 9) /* In case of Tcl 8.6 */
#define Tcl_UtfToWCharDString Tcl_UtfToUniCharDString
#endif
```

And the other way around (get the default printer name):

```
DWORD BufferSize;
TCHAR *pDefaultPrinter;
Tcl_DString Printer;
︙
367
368
369
370
371
372
373


375
376
377
378
379
380
381
382
383







+
+
```

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).

Source: [TIP548](https://core.tcl-lang.org/tips/doc/trunk/tip/548.md)