Good day fellow monks,

I need a bit of assistance embedding a perl script into a C++ console application. I am using Microsoft Visual C++(Not by choice). I am able to embed a perl interpreter that seems to work. The following code functions properly:
#include <stdafx.h> #include <EXTERN.h> #include <perl.h> static PerlInterpreter *my_perl; int main (int argc, char **argv, char **env) { STRLEN n_a; char *embedding[] = { "", "-e", "0" }; my_perl = perl_alloc(); perl_construct( my_perl ); perl_parse(my_perl, NULL, 3, embedding, NULL); perl_run(my_perl); /** Treat $a as an integer **/ eval_pv("$a = 3; $a **= 2", TRUE); printf("a = %d\n", SvIV(get_sv("a", FALSE))); /** Treat $a as a float **/ eval_pv("$a = 3.14; $a **= 2", TRUE); printf("a = %f\n", SvNV(get_sv("a", FALSE))); /** Treat $a as a string **/ eval_pv("$a = 'rekcaH lreP rehtonA tsuJ'; $a = reverse($a);", T +RUE); printf("a = %s\n", SvPV(get_sv("a", FALSE), n_a)); perl_destruct(my_perl); perl_free(my_perl); return 0; }
However, I am unable to access prewritten perl functions. Here is the code I have been attempting to get to work:
#include "stdafx.h" #include <EXTERN.h> #include <perl.h> static PerlInterpreter *my_perl; static void call_PrintUID() { dSP ; PUSHMARK(SP) ; call_pv("PrintUID", G_DISCARD|G_NOARGS) ; } int main (int argc, char **argv, char **env) { char *embedding[] = { "", "printuid.pl" }; my_perl = perl_alloc(); perl_construct( my_perl ); perl_parse(my_perl, NULL, 3, embedding, NULL); perl_run(my_perl); call_PrintUID(); perl_destruct(my_perl); perl_free(my_perl); return 0; }

I haven't used C/C++ in a long time and was never that great at it anyways, so this is very frustrating. If anyone could help me figure out where I am going wrong I would GREATLY appreciate it. =)

Best Regards!
smack

In reply to Embedding perl into a win32 console application by smack

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.