Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

critcl on Windows

129 views
Skip to first unread message

Kevin Walzer

unread,
Sep 9, 2015, 10:15:09 PM9/9/15
to
I'm trying to compile the following code by Pat Thoyts on Windows via
critcl, and am getting an error. I have critcl, mingw, and all relevant
Tcl libs installed via teacup or my own installation, but the
compilation is not working.

critcl::cproc AddFontResource {Tcl_Interp* interp Tcl_Obj* pathObj} ok {
Tcl_DString ds;
Tcl_Encoding unicode;
int len, r = TCL_OK;
const char *path = Tcl_GetStringFromObj(pathObj, &len);

Tcl_DStringInit(&ds);
unicode = Tcl_GetEncoding(interp, "unicode");
Tcl_UtfToExternalDString(unicode, path, len, &ds);
if (AddFontResourceExW(Tcl_DStringValue(&ds), FR_PRIVATE, NULL)
== 0) {
r = TCL_ERROR;
}
Tcl_DStringFree(&ds);
Tcl_FreeEncoding(unicode);
return r;
}

"critcl -pkg fonticon.tcl" is the command.

critcl complains that "FR_PRIVATE" is undefined.

I am probably missing a header inclusion or linker flag, but I am a bit
out of my depth on Windows at the C level and am not sure how to fix.
Can anyone point me in the right direction?

--Kevin
--
Kevin Walzer
Code by Kevin/Mobile Code by Kevin
http://www.codebykevin.com
http://www.wtmobilesoftware.com

pal...@yahoo.com

unread,
Sep 9, 2015, 11:04:22 PM9/9/15
to
Try adding something like

critcl::ccode {
#include <windows.h>
}

assuming you haven't already.

/Ashok

Kevin Walzer

unread,
Sep 10, 2015, 10:57:33 PM9/10/15
to
On 9/9/15 11:04 PM, pal...@yahoo.com wrote:
> Try adding something like
>
> critcl::ccode {
> #include <windows.h>
> }
>
> assuming you haven't already.
>
> /Ashok

I added this, but it causes a metric ton of errors--too many to list. I
may have to try another approach, or give up on using custom fonts and
just stick with bitmaps for icons. I'm using 64-bit, and ffidl doesn't
seem to support that.

Christian Gollwitzer

unread,
Sep 11, 2015, 12:45:43 AM9/11/15
to
Am 10.09.15 um 04:15 schrieb Kevin Walzer:
> I'm trying to compile the following code by Pat Thoyts on Windows via
> critcl, and am getting an error. I have critcl, mingw, and all relevant
> Tcl libs installed via teacup or my own installation, but the
> compilation is not working.
>
> critcl::cproc AddFontResource {Tcl_Interp* interp Tcl_Obj* pathObj} ok {
> Tcl_DString ds;
> Tcl_Encoding unicode;
> int len, r = TCL_OK;
> const char *path = Tcl_GetStringFromObj(pathObj, &len);
>
> Tcl_DStringInit(&ds);
> unicode = Tcl_GetEncoding(interp, "unicode");
> Tcl_UtfToExternalDString(unicode, path, len, &ds);
> if (AddFontResourceExW(Tcl_DStringValue(&ds), FR_PRIVATE, NULL)
> == 0) {
> r = TCL_ERROR;
> }
> Tcl_DStringFree(&ds);
> Tcl_FreeEncoding(unicode);
> return r;
> }
>
> "critcl -pkg fonticon.tcl" is the command.

Is this the only function in your library? Because then you could reduce
the level of complexity by kicking out critcl and trying to compile the
package manually - here it hardly does anything besides adding the init
function. To check if this is the only problem, you could also replace
FR_PRIVATE by its numeric value for now (which is 0x10 according to
https://msdn.microsoft.com/en-us/library/dd183327%28v=vs.85%29.aspx )

Christian

s.effe...@googlemail.com

unread,
Sep 11, 2015, 4:41:51 AM9/11/15
to
Hi Kevin,

I tried this with Visual Studio Express 2012 and MinGW 4.9.2 on Win7, the problem seems to be that gdi32 is not linked to. In addition, MinGW doesn't seem to set the _WIN32_WINNT macro which must be at least 0x0500; not necessary for VStudio of course, but it doesn't do any harm.

Add this code in front of your cproc:

critcl::ccode {
#define _WIN32_WINNT 0x0500
#include <windows.h>
}

critcl::clibraries -lgdi32


-- Stephan

Kevin Walzer

unread,
Sep 14, 2015, 7:39:48 AM9/14/15
to
On 9/9/15 10:15 PM, Kevin Walzer wrote:
> I am probably missing a header inclusion or linker flag, but I am a bit
> out of my depth on Windows at the C level and am not sure how to fix.
> Can anyone point me in the right direction?

apn reporting in the chat today that twapi can accomplish what I
want...will report back on this later.

Kevin Walzer

unread,
Sep 14, 2015, 8:02:30 PM9/14/15
to
On 9/14/15 7:39 AM, Kevin Walzer wrote:
> apn reporting in the chat today that twapi can accomplish what I
> want...will report back on this later.


Turns out it's this easy with twapi:

package require twapi
twapi::AddFontResourceEx /path/to/iconic_stroke.ttf
label .b -text \u2699 -font {Iconic 22}
pack .b

A label with a font icon (cog) displays nicely.

Thanks to Ashok P. Nadkarni for the awesome Twapi package! This is
immediately in my indispensible toolbox.
0 new messages