Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8316399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:21:18+00:00 2026-06-08T21:21:18+00:00

After a long time learning python I finally managed to make some breakthroughs: I’m

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T21:21:20+00:00Added an answer on June 8, 2026 at 9:21 pm

    You can create a preallocated string buffer using ctypes.create_string_buffer.

    However, you’ll still need to know how large the buffer is going to be. I’m not familiar with the software you’re trying to run, but it sounds like you’ll need:

    • Space for at least 25×80 Unicode characters
    • Possibly space for extended attributes for those characters

    So as a rough guess, I’d say the string should have at least 25*80*2*2 = 8000 bytes.

    I recommend reading the documentation in greater depth to determine the correct value if that doesn’t work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been using Symfony for a long time but I'm new to Symfony2. After
I received this message after long time of using the same application without programming
I am starting to learn Java a little after long time. And learning Netbeans
In my jsp page some pure java code there i.e, scriptlet. After a long
So after a long time of debugging here is whats happening. (Using Facebooks Graph
After a long time searching and trying I'm asking now for help: My situation:
After searching a long time for a performance bug, I read about denormal floating
After a long search I'm still confused about it although I found some related
How long after a document is fed to the Google Search Appliance using a
I'm currently re-engaging with Python after a long absence and loving it. However, I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.