The first argument needs to be a byte string as well:
msvcrt.printf(b"%s", string)
The return value of printf is the number of characters printed, which should be 12 in this case.
Edit:
If you want the string to be returned instead of printed, you can use sprintf
instead. This is dangerous and NOT recommended.
s = ctypes.create_string_buffer(100) #must be large enough!!
msvcrt.sprintf(s, b'%s', b'Hello World!')
val = s.value
I don't know why you'd want to do this though, since Python has its own string formatting. sprintf
is a dangerous method since it is susceptible to buffer overflows.
interjay
2010-04-14 10:39:01