in reply to Re^11: 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?

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

  • Comment on Re^12: Perl calls C calls Perl CallBack: How Perl callback use the same interpreter/context as Perl caller?

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

    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.

Re^13: Perl calls C calls Perl CallBack: How Perl callback use the same interpreter/context as Perl caller?
by salva (Canon) on Jul 09, 2014 at 08:52 UTC
    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.