itamarat has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I'm embedding PERL into an MSVC DLL project. I know how to call a C functions from PERL (PERL --> C) and I know how to call PERL functions from C (C --> PERL).

The system scheme is: PERL --> C DLL --> PERL callback (i.e., the PERL is calling a function from the MSVC DLL. Then, the DLL is calling a PERL callback)

The PERL callback should work in the same context (the same interpreter?) as the PERL code which called the MSVC DLL in the first place.

How should it be done? Can I choose the PERL interpreter I'm using? It seemed to me that the way of allocating a PERL interpreter is not the way (see code below).
Thank you for your help, Best regards, Itamar

/*============================================= * start Perl Interpreter *============================================*/ PERL_SYS_INIT3(&argc,&argv,&env); my_perl= perl_alloc(); perl_construct(my_perl); PL_exit_flags |= PERL_EXIT_DESTRUCT_END; perl_parse(my_perl, NULL, 2, my_argv, (char **)NULL); perl_run(my_perl);

Replies are listed 'Best First'.
Re: Embedding PERL into an MSVC project - How to choose interpreter?
by BrowserUk (Patriarch) on Feb 16, 2014 at 18:57 UTC

    Take a look at Perl crash during perl_clone, but be warned it is a long and complicated thread that goes through a large learning curve before arriving at some useful information. You'll need to read deep (level 20+) to find the good stuff.

    Update: The code in teh second block of this post was the final and most well tested iteration of my code.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      Hi,

      Thanks for your response, I'll start to dig in :)


      Best regatrds,

      Itamar
Re: Embedding PERL into an MSVC project - How to choose interpreter?
by syphilis (Archbishop) on Feb 17, 2014 at 00:38 UTC
    PERL is calling a function from the MSVC DLL. Then, the DLL is calling a PERL callback

    With Inline::C (or XS) you can have perl call a C sub that in turn calls a perl sub. This is documented in the perlcall documentation.
    And here is an Inline::C demo from the Inline::C-Cookbook.

    I think this is a simpler solution than separately building a dll that embeds the perl interpreter that has loaded the dll.
    But then ... maybe this alternative approach is not applicable to the problem you need to solve.

    Cheers,
    Rob
      Hi,

      As you guessed correctly, it is not possible on my system, because of its current design and structure.


      Thanks and best regards,

      Itamar