[Tutor] calling printf() in a C language DLL using ctypes.CDLL
eryksun at gmail.com
Tue May 8 20:16:34 EDT 2018
On Tue, May 8, 2018 at 9:39 AM, Brad M <thebigwurst at gmail.com> wrote:
> I compile this by typing this in the command line:
> cl /LD /I C:\python\include helloworld.c C:\python\libs\python36.lib
You're not using Python's C API, so you only need `cl /LD helloworld.c`.
> However, this doesn't print anything on the python window.
> What I would like is to do is to be able to use printf() in my .dll
> by having the c code pop up a console window to print or
> to have something that can print() in the python window somehow.
By Python window, do you mean the IDLE GUI? If the library is loaded
in a GUI program in which stdout is invalid, it will have to manually
allocate a console via `AllocConsole` and open the screen buffer using
the reserved filename "CONOUT$". Then it can print to the opened FILE
stream using fprintf(). But I'll reiterate Alan here that this would
be unusual behavior for a shared library, unless it's specifically
intended as a UI library.
More information about the Tutor