Mix Perl and C++/CLI
Perl is a language with many features to manipulate string. I always want to embed Perl into C program. But a conclusion in perlembed shocks me:
Corollary: you can't use Perl from your C program unless Perl has been compiled on your machine, or installed properly--that's why you shouldn't blithely copy Perl executables from machine to machine without also copying the lib directory.
I posted this on perlmonks and got excellent advice from Corion , and know in windows, all you need is just copy perl dll with c program. ;)
As monks help, I made a toy program embedded perl, and works fine! Thanks, perl! thanks perl community!
post main code here below, hope it could help guys who want to embed perl like me. ;)
#include "stdafx.h"
#include "Form1.h"
#pragma unmanaged
#include "perl.h"
#include "EXTERN.h"
#pragma managed
using namespace perl_form;
PerlInterpreter *my_perl;
[STAThreadAttribute]
int main(array
{
char *embed[] = {"", "-e", 0};
char *argss[] = { NULL };
PERL_SYS_INIT3((int *)NULL,(char ***)NULL,(char ***)NULL);
my_perl = perl_alloc();
perl_construct(my_perl);
PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
// Enabling Windows XP visual effects before any controls are created
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
// Create the main window and run it
Application::Run(gcnew Form1());
perl_destruct(my_perl);
perl_free(my_perl);
PERL_SYS_TERM();
return 0;
}
Leave a comment