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

Brad M thebigwurst at gmail.com
Tue May 8 05:39:02 EDT 2018


Hi all:

I am trying out some c based module in a .dll file on windows.

// helloworld.c
#include <stdio.h>

__declspec(dllexport) void helloworld()
{
    printf("Hello Everyone!!!");
}

I compile this by typing this in the command line:

cl /LD /I C:\python\include helloworld.c C:\python\libs\python36.lib

I get helloworld.dll for the above.



and the following is the python caller

import ctypes
mydll = ctypes.CDLL('helloworld')
mydll.helloworld()



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.

Is this possible?

Thanks!


More information about the Tutor mailing list