CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced:
Perl and tn3270

 



daveirwin
New User

Jul 26, 2002, 7:36 PM

Post #1 of 8 (1715 views)
Perl and tn3270 Can't Post

I'm not advanced but I think this an advanced question.
Can someone tell me how to do either of the following:

Find a module allowing perl to screen scrap a tn3270 emulator via ehllapi
or
Import ehllapi.dll to do the above
or
link to a C library which has the functionality. I have
some C code that interprets simple instructions ie "GET varName, 15, 10, 20 (meaning read the text at row 15, column 10 for 20 characters into the variable varName)

Is there a way I can wrap up this functionality into a perl module or other access the functions from perl?

Thanks,
Dave


mhx
Enthusiast

Jul 27, 2002, 12:27 AM

Post #2 of 8 (1712 views)
Re: [daveirwin] Perl and tn3270 [In reply to] Can't Post

I don't know of any already existing module to do this. If you don't find it at [url=http://search.cpan.org]CPAN, you'll most probably have to write your own module.

Since you want to interface to an already existing DLL, you "just" have to write an XS extension (a Perl module written in XS instead of Perl) for Perl. XS is mostly like C, so if you've got a good background in C, you won't have a lot of trouble using XS. (At least, that's what I experienced.)

At http://www.perldoc.com (or using your perldoc program) you'll find [url=http://www.perldoc.com/perl5.8.0/pod/perl.html#Internals-and-C-Language-Interface]all the information you need about how to hack your own XS module. The [url=http://www.perldoc.com/perl5.8.0/pod/perlxstut.html]Perl XS Tutorial is a good place to start. If you've got a basic module running, just load the DLL and interface to the functions you need.

If you've got more specific questions (or any problems), feel free to ask.

-- mhx

At last with an effort he spoke, and wondered to hear his own words, as if some other will was using his small voice. "I will take the Ring," he said, "though I do not know the way."

-- Frodo



daveirwin
New User

Jul 30, 2002, 7:27 AM

Post #3 of 8 (1701 views)
Re: [mhx] Perl and tn3270 [In reply to] Can't Post

Is the inline::C module a possibility for doing this. Unfortunately I am not an experienced C programmer (not really at perl for that matter...)

Are there limitations to XS? The functions I'm trying to wrap up are spread out throughout several .h, .lib, and .c files.



Thanks,

Dave


mhx
Enthusiast

Jul 30, 2002, 3:27 PM

Post #4 of 8 (1695 views)
Re: [daveirwin] Perl and tn3270 [In reply to] Can't Post


In Reply To
Is the inline::C module a possibility for doing this.


I'm not sure whether it is or not, simply because I haven't used it yet. From my own experience, I can only tell you that XS isn't that hard, especially if you only have to write an interface to an existing library.


In Reply To
Unfortunately I am not an experienced C programmer (not really at perl for that matter...)


I'd say some basic knowledge of C should be sufficient if all you want to do is interfacing. Playing 'round with Perl's data structures on the C level is a bit more sophisticated, but I guess you won't have to deal with that.


In Reply To
Are there limitations to XS?


None that I knew of. It's even platform-independent, as long as your C library is. Anything that you can do with C you can use with XS. (Because XS is just an intermediate step to make your life as an interface writer a bit easier. After all, it's still C that's being compiled into a dynamically loadable Perl extension.)

If you should have any problems with building your XS module just ask.

-- mhx

At last with an effort he spoke, and wondered to hear his own words, as if some other will was using his small voice. "I will take the Ring," he said, "though I do not know the way."

-- Frodo



fashimpaur
User / Moderator

Jul 31, 2002, 4:20 AM

Post #5 of 8 (1688 views)
Re: [daveirwin] Perl and tn3270 [In reply to] Can't Post

Dave,

If you are using Win32, you can use Win32::API if you know the functions
the DLL provides. It is simpler than using an XS extension. You can find more
information about it at http://aspn.activestate.com/ASPN/CodeDoc/Win32-API/API.html.

Hope that helps,
Dennis

$a="c323745335d3221214b364d545".
"a362532582521254c3640504c3729".
"2f493759214b3635554c3040606a0",
print unpack"u*",pack "h*",$a,"\n\n";


mhx
Enthusiast

Aug 1, 2002, 3:09 AM

Post #6 of 8 (1682 views)
Re: [fashimpaur] Perl and tn3270 [In reply to] Can't Post

Yes, this may indeed be a lot simpler than writing XS, thanks for the hint!
However, this depends a lot on the interface of the DLL. From the Win32::API manpage:


Quote
Note, however, that this module can't do anything (parameters input and output is limited to simpler cases), and anyway a regular XS extension is always safer and faster.


But you should give it a try to see whether it works or not. You can still write XS if it doesn't. Wink

-- mhx

At last with an effort he spoke, and wondered to hear his own words, as if some other will was using his small voice. "I will take the Ring," he said, "though I do not know the way."

-- Frodo



daveirwin
New User

Aug 2, 2002, 10:57 AM

Post #7 of 8 (1676 views)
Re: [mhx] Perl and tn3270 [In reply to] Can't Post

I am trying the win32:api approach and eventually found enough docs to get this far...



use Win32;
use Win32::API;

# register hllapi module saahlapi.dll
$hllapi = new Win32::API("SAAHLAPI", 'HLLAPISRV')
or die Win32::FormatMessage(Win32::GetLastError);

print "$hllapi\n";



# I am stuck at the following though. Per the hllapi doc, I should call the function

# passing 2 parms "Connect" and "A" to connect to the emulator

$hllapiCall = $hllapi->Call('Connect', 'A') or die Win32::FormatMessage(Win32::GetLastError);




# If I pass the parms, it dies with the error "Wrong number of parameters, expected #0, got 2"

# If I pass 0 parameters as it expects,

$hllapiCall = $hllapi->Call() or die Win32::FormatMessage(Win32::GetLastError);


# I get windows error "The instruction at "0x1cd74135" #referenced #memory at "0x00000021"....etc

# Any suggestions?


mhx
Enthusiast

Aug 5, 2002, 5:36 AM

Post #8 of 8 (1667 views)
Re: [daveirwin] Perl and tn3270 [In reply to] Can't Post

The third argument to the Win32::API constructor is an array reference specifying the argument types of the interface function. Since you didn't pass anything here, my guess is that the Win32::API module assumes the function not to take any arguments. BTW, the fourth argument specifies the return type, which might also be needed.
Have a look at the [url=http://search-beta.cpan.org/author/ACALPINI/Win32-API-0.20/API.pm]Win32::API manpage and, if that doesn't help, at the source of the module. IIRC it's not to hard to understand. If you're stuck, try to give some more details about the DLL.

Hope this helps.

-- mhx

At last with an effort he spoke, and wondered to hear his own words, as if some other will was using his small voice. "I will take the Ring," he said, "though I do not know the way."

-- Frodo


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives