Perl on Windows - use Perl as DLL

Discussion in 'Perl Misc' started by Snorik, Aug 28, 2009.

  1. Snorik

    Snorik Guest

    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...
    Snorik, Aug 28, 2009
    #1
    1. Advertising

  2. Snorik

    Guest

    , Aug 29, 2009
    #2
    1. Advertising

  3. Snorik

    Guest

    On 29 Aug., 13:13, ""
    <> wrote:
    > On 28 Aug., 16:46, Daniel Molina Wegener <> wrote:
    >
    > > Look at the perlembed manual page.

    >
    > > http://www.perl.com/doc/manual/html/pod/perlembed.html

    >
    > 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?
    , Aug 29, 2009
    #3
  4. Snorik

    Guest

    On 29 Aug., 16:12, Christian Winter <> wrote:
    > 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)?
    , Aug 29, 2009
    #4
  5. Snorik

    Guest

    On 29 Aug., 17:18, Christian Winter <> wrote:
    > wrote:
    > > On 29 Aug., 16:12, Christian Winter <> wrote:
    > >> 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];

    >
    > > main();

    >
    > > 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.
    , Aug 29, 2009
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Anushi
    Replies:
    5
    Views:
    8,625
  2. =?Utf-8?B?SmVmZiBLZXNpbmdlcg==?=

    Common Web functions dll (Used to use MTS, what do I use in .NET

    =?Utf-8?B?SmVmZiBLZXNpbmdlcg==?=, Dec 28, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    448
    charlie
    Apr 30, 2005
  3. jb
    Replies:
    2
    Views:
    323
  4. Replies:
    2
    Views:
    502
    Larry Bates
    Mar 9, 2007
  5. H. Simpson
    Replies:
    4
    Views:
    244
    H. Simpson
    Aug 3, 2004
Loading...

Share This Page