Hi monks,

I've tried to embed perl into a winform program written in C++/CLI recently. but got stuck with an conflict between managed style main function and PERL_SYS_INIT3 macro. the issue is compiler always complain if I put PERL_SYS_INIT3 into managed main body.(of course, it can't find any argc,argv adress in CLI). However what make me surprised, if I comment it everything seems OK. I mean, program could be compiled, and run correctly. Below is partial codes:

int main(array<System::String ^> ^args) { //PERL_SYS_INIT3(0,'ss','dd'); my_perl = perl_alloc(); perl_construct(my_perl); PL_exit_flags |= PERL_EXIT_DESTRUCT_END; // Enabling Windows XP visual effects before any controls are crea +ted 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; }

here is said in perl api:

The macros PERL_SYS_INIT3() and PERL_SYS_TERM() provide system-specific tune up of the C runtime environment necessary to run Perl interpreters; they should only be called once regardless of how many interpreters you create or destroy. Call PERL_SYS_INIT3() before you create your first interpreter, and PERL_SYS_TERM() after you free your last interpreter. So what these 2 macros do behind? it does tune up? will it bring some issues when I comments it?

thanks in advance!

In addition, perl_destruct(my_perl) can't be uncommented too,otherwise it will throw:

First-chance exception at 0x7c84cd02 in perl_form.exe: 0xC0000005: Acc +ess violation writing location 0x00000014. A first chance exception of type 'System.AccessViolationException' occ +urred in perl_form.exe An unhandled exception of type 'System.AccessViolationException' occur +red in perl_form.exe Additional information: Attempted to read or write protected memory. T +his is often an indication that other memory is corrupt.

UPDATE:

thank patcat88, it's like that PERL_SYS_INIT3 JUST run InitializeCriticalSection (&(*Perl_Gperlio_mutex_ptr (0))); So I pass NULL to it and by far everything seems ok. I'll do more tests.

int main(array<System::String ^> ^args) { 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 crea +ted 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; }




I am trying to improve my English skills, if you see a mistake please feel free to reply or /msg me a correction


In reply to what do PERL_SYS_INIT3() and PERL_SYS_TERM() do? by xiaoyafeng

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.