Python Forum
DLL printf not working - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: DLL printf not working (/thread-1422.html)



DLL printf not working - mperemsky - Jan-02-2017

I have just installed python 3.6 (32-bit), eclipse, and PyDev. I am going through the Gray Hat Python book (which uses 2.5) and cannot get the dll call for printf to work properly. I have tried to find a solution to no avail.

The code is as follows. It will only print the first character of the output string to the console.

from ctypes import *

msvcrt = cdll.msvcrt
msvcrt.printf

message_string = "Hello World!\n"
msvcrt.printf("Testing: %s", message_string)

Output:
T



RE: DLL printf not working - Larz60+ - Jan-02-2017

I get the same result - You should report it to python.org as a bug

This doesn't work in any python 3 version (I tried 3 of them)
I am guessing that it might not be a bug, but have to do with text automatically being utf-8
in python. See http://stackoverflow.com/questions/8452961/convert-string-to-ascii-value-python


RE: DLL printf not working - mperemsky - Jan-02-2017

(Jan-02-2017, 05:21 AM)Larz60+ Wrote: I get the same result - You should report it to python.org as a bug

This doesn't work in any python 3 version (I tried 3 of them)
I am guessing that it might not be a bug, but have to do with text automatically being utf-8
in python. See http://stackoverflow.com/questions/8452961/convert-string-to-ascii-value-python


I just installed Python 2.7 and ran the same code and I got the expected results. I will send a message as you suggested.


RE: DLL printf not working - Larz60+ - Jan-02-2017

Quote:
Quote:I am guessing that it might not be a bug, but have to do with text automatically being utf-8

in python
I just installed Python 2.7 and ran the same code and I got the expected results. I will send a message as you suggested.


Don't think it's a bug