in reply to Re^10: Perl calls C calls Perl CallBack: How Perl callback use the same interpreter/context as Perl caller?
in thread Perl calls C calls Perl CallBack: How Perl callback use the same interpreter/context as Perl caller?

Sure, you start the argument declarations for your C function prototypes with pTHX/pTHX_, and then pass then as the first argument aTHX/aTHX_. For instance:
/* Your C function declarations */ int foo(pTHX) { ... } int bar(pTHX_ int a) { ... } /* In your XS code */ int foo_result = foo(aTHX); int bar_result = bar(aTHX_ 21);
  • Comment on Re^11: Perl calls C calls Perl CallBack: How Perl callback use the same interpreter/context as Perl caller?
  • Select or Download Code

Replies are listed 'Best First'.
Re^12: Perl calls C calls Perl CallBack: How Perl callback use the same interpreter/context as Perl caller?
by itamarat (Acolyte) on Jul 09, 2014 at 08:18 UTC

    Hi,

    Thanks for your responses!

    We use WIN32::API module to load the C DLL functions. I don't understand where should I use the code you have suggested. Please forgive me for trivial questions... I'm a FW guy, and in my first steps of learning the Perl guts.


    Thanks!

    Itamar

      You should be writing your C code as an XS file (perlxs). Perl (well, DynaLoader) will then take care of loading your extension, setting you up with the Perl interpreter and doing all the work.

      Most likely, perlxstut contains enough to get you started.

      As Corion says in his post, the common way to do that is to write an XS extension. That would probably make all your problems related to the Perl context go away.

      If you want to stick to Win32::API, that module provides Win32::API::Callback for passing Perl subs as callbacks to C functions.