Perl on Windows - use Perl as DLL

S

Snorik

Hello everyone,

is it possible to use the perl interpreter as DLL to pass arguments
(scriptname, arguments and so on) in the windows way of loadLibrary(),
sendMessage:lparam:wparam: closeLibrary()?

I am normally using perl on Solaris, or just as scripting language,
but now I would like to embed perl in some other language...
 
C

claus.kick

Look at the perlembed manual page.

Hello,

ok, thanks for that, but I think that is not quite what I am looking
for.

This:

http://docs.activestate.com/activeperl/5.8/Components/Windows/PerlEz....

is I think what I need.

I had been wondering whether there were better ways than doing (sorry
for the Java)

Runtime.getRuntime().exec(new String[] {"perl.exe", "script.pl",
"arg1", "arg2"});

Ok progress:

I can load the library, create an interpreter, but calling PerlEzCall1
(...) fails with: 5 -> Function call caused an exception
I figure my error is not knowing what to pass as pFunction - pointer
name of the function to call.

What do I have to pass as function parameter?
 
C

claus.kick

(e-mail address removed) schrieb:


http://docs.activestate.com/activeperl/5.8/Components/Windows/PerlEz....
is I think what I need.
I had been wondering whether there were better ways than doing (sorry
for the Java)
Runtime.getRuntime().exec(new String[] {"perl.exe", "script.pl",
"arg1", "arg2"});
Ok progress:
I can load the library, create an interpreter, but calling PerlEzCall1
(...) fails with: 5 -> Function call caused an exception
I figure my error is not knowing what to pass as pFunction - pointer
name of the function to call.
What do I have to pass as function parameter?

The name of the function. If you're just trying to run a script,
you don't have to invoke PerlEzCall at all, the script will be
executed when you call PerlEzCreate. What you won't have is
a capturing facility for STDOUT and STDERR, so in case you need
that, invoking a command line perl or linking the interpreter
directly as in perlembed might be more convenient in the long run.
PerlEzCall is used to invoke a specific function, seehttp://www.perlmonks.org/?node_id=571371
for an example.

I am sorry to ask in such a stupid way, but do you mean "sub routine"
with "function"?

Wouldnt it be possible to basically create a main() sub routine in a
script like this:

#!c:\perl\bin

my $name = $ARGV[0];

main();

sub main
{
print "hello world: ".$name."!\n";
}


and hence be able to have STDOUT and STDERR (thats probably what
lpBuffer is for)?
 
C

claus.kick

(e-mail address removed) schrieb:
http://docs.activestate.com/activeperl/5.8/Components/Windows/PerlEz....
is I think what I need.
I had been wondering whether there were better ways than doing (sorry
for the Java)
Runtime.getRuntime().exec(new String[] {"perl.exe", "script.pl",
"arg1", "arg2"});
Ok progress:
I can load the library, create an interpreter, but calling PerlEzCall1
(...) fails with: 5 -> Function call caused an exception
I figure my error is not knowing what to pass as pFunction - pointer
name of the function to call.
What do I have to pass as function parameter?
The name of the function. If you're just trying to run a script,
you don't have to invoke PerlEzCall at all, the script will be
executed when you call PerlEzCreate. What you won't have is
a capturing facility for STDOUT and STDERR, so in case you need
that, invoking a command line perl or linking the interpreter
directly as in perlembed might be more convenient in the long run.
PerlEzCall is used to invoke a specific function, see
http://www.perlmonks.org/?node_id=571371
for an example.
I am sorry to ask in such a stupid way, but do you mean "sub routine"
with "function"?
Exactly.



Wouldnt it be possible to basically create a main() sub routine in a
script like this:
#!c:\perl\bin

my $name = $ARGV[0];

sub main
{
print "hello world: ".$name."!\n";
}
and hence be able to have STDOUT and STDERR (thats probably what
lpBuffer is for)?

lpBuffer is the storage for the sub's return value, i.e. if your sub
read:
sub main
{
return "hello world";}

then lpBuffer would contain the string "hello world". Anything you
print to STD(OUT|ERR) will be invisible, unless you redirect it
explicitely in the perl code.

OK, thanks for pointing that out.
A downside of this kind of invokation is that the size of lpBuffer
is defined before the invokation, so there IMHO is no (or better, no
both easy and sensible way) to capture arbitrarily long return values,
making it neccessary to be very thorough in defining possible return
values for subs called this way.

I have been wondering about that.
One thing that comes to my mind is just to return a pointer (plus
size)
and have the calling language read the return value.

Or the easy solution: just return a temporary file name.

Thank you very much for your help - I still get Error 5 (Function call
caused an exception - sounds very generic) but that is just me doing
something wrong with calling the DLL.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top