#include #include #include #include static PerlInterpreter *my_perl = NULL; static __attribute__((constructor)) void init() { int num = 2; char *args[] = { "", "init.perl" }; PERL_SYS_INIT3((int *)NULL,(char ***)NULL,(char ***)NULL); my_perl = perl_alloc(); perl_construct(my_perl); PL_exit_flags |= PERL_EXIT_DESTRUCT_END; perl_parse(my_perl, NULL, num, args, (char **)NULL); perl_run(my_perl); } static __attribute__((destructor)) void quit() { if (my_perl) { PL_perl_destruct_level = 1; perl_destruct(my_perl);printf("1st\n"); perl_free(my_perl);printf("2nd\n"); PERL_SYS_TERM();printf("3rd\n"); } } // the following are functions to invoke in perl script extern __declspec(dllexport) void about() { dSP; SV *err_tmp; ENTER; SAVETMPS; PUSHMARK(SP); PUTBACK; call_pv("about", G_VOID|G_DISCARD|G_EVAL|G_NOARGS); SPAGAIN; err_tmp = ERRSV; if (SvTRUE(err_tmp)) { printf ("[error about]%s\n", SvPV_nolen(err_tmp)); POPs; } PUTBACK; FREETMPS; LEAVE; }