#pragma warning(disable:4786) #pragma warning(disable:4788) #pragma warning(disable:4503) #include #include #include using namespace std; #include #include #include typedef vector V_S; void addValue(V_S& argVec) { dSP; ENTER; SAVETMPS; PUSHMARK(SP); AV* array = newAV(); for (int i = 0; i < argVec.size(); i++) { SV * value = newSVpvn( (char *)argVec[i].c_str(), argVec[i].length() ); av_push(array, value); } XPUSHs(newRV((SV*)array)); PUTBACK; perl_call_pv("Test::AddValue", G_EVAL|G_SCALAR); SPAGAIN; argVec.clear(); { I32 len = 0; while( av_len(array) >= len ) { SV ** v = av_fetch(array, len, FALSE ); SV * value = NULL; if( v ) { value = *v; int len = SvLEN(value); char * dataPtr = new char[len]; memcpy( dataPtr, SvPV_nolen(value), len ); argVec.push_back(string(dataPtr, len)); delete[] dataPtr; } sv_free(av_delete(array, len, FALSE)); len++; } } av_undef(array); PUTBACK; FREETMPS; LEAVE; } void main() { V_S myVals; myVals.push_back("value11"); myVals.push_back("value12"); static PerlInterpreter* my_perl; my_perl = perl_alloc(); perl_construct(my_perl); char* argv[] = {"", "F:\\Personal\\Misc Code\\PerlFromC\\Debug\\Test.pm"}; int status = perl_parse(my_perl, NULL, 1, argv, NULL); if (status != 0) { cout << "Error in perl_parse"; return; } for (int i = 0; i < 2000; i++) { V_S copyVec = myVals; addValue(copyVec); cout << "============== After calling Perl Module ================\n"; V_S::iterator vItr; for (vItr = copyVec.begin(); vItr != copyVec.end(); vItr++) cout << "Value = " << vItr->c_str() << "\n"; } perl_destruct(my_perl); perl_free(my_perl); } #### package Test; require Exporter; @ISA = (Exporter); sub AddValue { $_[0]->[2] = "myvalue"; }