[Tutor] calling printf() in a C language DLL using ctypes.CDLL
alan.gauld at yahoo.co.uk
Tue May 8 18:13:07 EDT 2018
I'm guessing at the answer here because I'm on vacation with no access to a pc of any kind let alone Windows. But are you running python inside an ide? If so you might find you get the expected result if you use a command prompt, since printf usually sends output to stdout.
This is another example of the rule that you should never mix display and logic. If the dll returned the string instead of printing it you could display it from python easily, but by using print you make your code dependant on a stdout being visible.
On 8 May 2018, at 23:03, Brad M <thebigwurst at gmail.com> wrote:
I am trying out some c based module in a .dll file on windows.
__declspec(dllexport) void helloworld()
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
mydll = ctypes.CDLL('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?
Tutor maillist - Tutor at python.org
To unsubscribe or change subscription options:
More information about the Tutor