[Tutor] calling printf() in a C language DLL using ctypes.CDLL

Brad M thebigwurst at gmail.com
Tue May 8 21:30:04 EDT 2018


Hmmm, I guess then it's time for me to ask this question: Is how I do this
the way you do it?

I have been inserting lines like this:   print("The program got here!")
all over my python code whenever I want to know where the program went.

If you want to know where your program went when something went wrong or
when it triggers a if condition, how do you do it?

Thanks!



On Wed, May 9, 2018 at 8:16 AM, eryk sun <eryksun at gmail.com> wrote:

> 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 mailing list