Skip to content

Commit 1dbaa4f

Browse files
committed
WIP: try Windows support for TCL dynamic loading
Try adding defines etc for using LoadLibrary on Windows to get the TCL / Tk routines.
1 parent 64f01dd commit 1dbaa4f

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

src/_tkagg.cpp

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,6 @@ static PyMethodDef functions[] = {
267267
#ifdef DYNAMIC_TKINTER
268268
// Functions to fill global TCL / Tk function pointers from tkinter module.
269269

270-
#include <dlfcn.h>
271-
272270
#if PY3K
273271
#define TKINTER_PKG "tkinter"
274272
#define TKINTER_MOD "_tkinter"
@@ -288,6 +286,29 @@ char *fname2char(PyObject *fname)
288286
#define fname2char(s) (PyString_AsString(s))
289287
#endif
290288

289+
#if defined(_MSC_VER)
290+
#include <windows.h>
291+
#define LIB_PTR_TYPE HMODULE
292+
#define LOAD_LIB(name) LoadLibrary(name)
293+
FARPROC _dfunc(LIB_PTR_TYPE lib_handle, const char *func_name)
294+
{
295+
// Load function `func_name` from `lib_handle`.
296+
// Set Python exception if we can't find `func_name` in `lib_handle`.
297+
// Returns function pointer or NULL if not present.
298+
299+
char message[100];
300+
301+
FARPROC func = GetProcAddress(lib_handle, func_name);
302+
if (func == NULL) {
303+
sprintf(message, "Cannot load function %s", func_name);
304+
PyErr_SetString(PyExc_RuntimeError, message);
305+
}
306+
return func;
307+
}
308+
#else
309+
#include <dlfcn.h>
310+
#define LIB_PTR_TYPE void*
311+
#define LOAD_LIB(name) dlopen(name, RTLD_LAZY)
291312
void *_dfunc(void *lib_handle, const char *func_name)
292313
{
293314
// Load function `func_name` from `lib_handle`.
@@ -303,8 +324,9 @@ void *_dfunc(void *lib_handle, const char *func_name)
303324
}
304325
return func;
305326
}
327+
#endif
306328

307-
int _func_loader(void *lib)
329+
int _func_loader(LIB_PTR_TYPE lib)
308330
{
309331
// Fill global function pointers from dynamic lib.
310332
// Return 1 if any pointer is NULL, 0 otherwise.
@@ -328,7 +350,7 @@ int load_tkinter_funcs(void)
328350
// Load tkinter global funcs from tkinter compiled module.
329351
// Return 0 for success, non-zero for failure.
330352
int ret = -1;
331-
void *tkinter_lib;
353+
LIB_PTR_TYPE tkinter_lib;
332354
char *tkinter_libname;
333355
PyObject *pModule = NULL, *pSubmodule = NULL, *pString = NULL;
334356

@@ -348,7 +370,7 @@ int load_tkinter_funcs(void)
348370
if (tkinter_libname == NULL) {
349371
goto exit;
350372
}
351-
tkinter_lib = dlopen(tkinter_libname, RTLD_LAZY);
373+
tkinter_lib = LOAD_LIB(tkinter_libname);
352374
if (tkinter_lib == NULL) {
353375
PyErr_SetString(PyExc_RuntimeError,
354376
"Cannot dlopen tkinter module file");

0 commit comments

Comments
 (0)