After a long time learning python I finally managed to make some breakthroughs:
I'm using the following code to connect to a personal communications terminal:
from ctypes import *
import sys
PCSHLL32 = windll.PCSHLL32
hllapi = PCSHLL32.hllapi
def connect_pcomm(presentation_space):
function_number = c_int(1)
data_string = c_char_p(presentation_space)
lenght = c_int(4)
ps_position = c_int(0)
hllapi(byref(function_number), data_string, byref(lenght), byref(ps_position))
And so far so good. It does connect to the terminal and I can use other functions to send keys to the screen, disconnect, etc etc etc.
My problem is with function 5, as defined by the IBM documentation:
http://publib.boulder.ibm.com/infocenter/pcomhelp/v5r9/index.jsp?topic=/com.ibm.pcomm.doc/books/html/emulator_programming08.htm
''The Copy Presentation Space function copies the contents of the host-connected presentation space into a data string that you define in your EHLLAPI application program.''
The code I wrote to do this (which is not that special):
def copy_presentation_space():
function_number = c_int(5)
data_string = c_char_p("")
lenght = c_int(0)
ps_position = c_int(0)
hllapi(byref(function_number), data_string, byref(lenght), byref(ps_position))
The main problem is the data_string var is supposed to be: "Preallocated target string the size of your host presentation space."
Since I wasn't exactly aware of what this means I simply tried to run the code. And pythonw.exe crashed. Epically. The terminal window proceeded to crash too. It didn't give any type of error, it simply said that it stopped working.
Now, my main question is, how can I preallocate the string like it's mentioned on the IBM ref. material?
Can I simply add a 'print data_string' after copying the screen to see the information, or do I need to use some ctypes to be able to view the copied information?
EDIT:
I forgot to mention that I don't need to use that function, I could just use this one:
Copy Presentation Space to String (8)
I tried to use it, but the data_string variable never changes value.
EDIT2:
Following kwatford suggestion, I changed the line
data_string = c_char_p("")
To
data_string = create_string_buffer(8000)
Now the function will not crash and returns a value of 0, meaning that: "'The host presentation space contents were copied to the application program. The target presentation space was active, and the keyboard was unlocked.' But when I try to print the variable data_string I still get an empty result.