0

I use tcl shellicon command to extract icons, as it mentioned on wiki page below, there are some international character problems in it, then I write some code to test but it doesn't work, could anyone to help me correct it.

/*
 * testdll.c
 * gcc compile: gcc testdll.c -ltclstub86 -ltkstub86 -IC:\Users\L\tcc\include -IC:\Users\L\tcl\include -LC:\Users\L\tcl\lib -LC:\Users\L\tcc\lib -DUSE_TCL_STUBS -DUSE_TK_STUBS -shared -o testdll.dll
 */
#include <windows.h>
#include <tcl.h>
#include <stdlib.h>

int TestdllCmd(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[]) {
    char * path;
    Tcl_DString ds;

    if (objc > 2) {
        Tcl_SetResult(interp, "Usage: testdll ?path?",NULL);
        return TCL_ERROR;
    }
    if (objc == 2) {
        path = Tcl_GetString(objv[objc-1]);
        path = Tcl_TranslateFileName(interp, path, &ds);
        if (path != TCL_OK) {
            return TCL_ERROR;
        }
    }
    Tcl_AppendResult(interp, ds, NULL);
    return TCL_OK;
}

int DLLEXPORT Testdll_Init(Tcl_Interp *interp) {
    if (Tcl_InitStubs(interp, "8.5", 0) == NULL) {
        return TCL_ERROR;
    }
    Tcl_CreateObjCommand(interp, "testdll", TestdllCmd, NULL, NULL);
    Tcl_PkgProvide(interp, "testdll", "1.0");
    return TCL_OK;
}

I compile it with:

gcc compile: gcc testdll.c -ltclstub86 -ltkstub86 -IC:\Users\USERNAME\tcc\include -IC:\Users\USERNAME\tcl\include -LC:\Users\USERNAME\tcl\lib -LC:\Users\USERNAME\tcc\lib -DUSE_TCL_STUBS -DUSE_TK_STUBS -shared -o testdll.dll

windows cmd shell run: tclsh testdll.tcl

load testdll
puts [testdll C:/Users/L/桌面]

the output is:

// This line isn't in the output, just to show the first line of output is a *EMPTY LINE*

    while executing
"testdll 'C:/Users/L/桌面'"
    invoked from within
"puts [testdll 'C:/Users/L/桌面']"
    (file "testdll.tcl" line 2)

In fact, I want to print a line, whose content is "C:/Users/L/桌面"

I write this dll to debug how to replace Tcl_GetString,Tcl_TranslateFileName with Tcl_FSGetNormalizedPath, Tcl_FSGetNativePath, I wonder if it's clear?

Thank you!

Kaffa
  • 1
  • 2
  • What code page are you using? See: [unicode-characters-in-windows-command-line](http://stackoverflow.com/questions/388490/unicode-characters-in-windows-command-line-how) – Brad Lanam Apr 12 '16 at 19:35
  • I want to make an extension to print the path which contains Chinese characters in it, but the code above print nothing but an error string, it can't print what I input even a normal path. I use ascii. – Kaffa Apr 12 '16 at 19:43
  • Please edit your question to include the error. Also, the `load` command works better with absolute paths. Try changing it to use an absolute path to the testdll file. – Brad Lanam Apr 12 '16 at 19:45
  • You can use `load ./testdll.dll`. – Donal Fellows Apr 14 '16 at 09:09
  • Thank you for tips, tcl load can load the dll, the international chars problem that I mentioned is the testdll.c, in which I want to print the argument including Chinese characters. But the result is that it prints a empty newline and other something like in ... – Kaffa Apr 14 '16 at 09:54
  • This is rather difficult, as part of the error message is missing. Can you redirect the output to a file, and then use an editor or hexdump the error message file so we can see the full output. – Brad Lanam Apr 18 '16 at 20:11

1 Answers1

0

Remove this:

    if (path != TCL_OK) {
        return TCL_ERROR;
    }

You are comparing a char * to an int.

The manual page for Tcl_TranslateFileName says:

However,  with  the  advent  of  the  newer Tcl_FSGetNormalizedPath 
and Tcl_FSGetNativePath, there is no longer any need to use this 
procedure.

You should probably switch to more modern API call.

Brad Lanam
  • 5,192
  • 2
  • 19
  • 29