Hi, monks

I've been writing a watchdog with Win32::Process::List. the script itself is extremely simple, monitor processes running and spawn a new one if the process which was monitor quit.

the interesting is where I browse in the W::P::L XS code

.......... pe32.dwSize = sizeof( PROCESSENTRY32 ); if( !Process32First( hProcessSnap, &pe32 ) ) { printError(wszMsgBuff,&err ); sv_upgrade(perror,SVt_PVIV); sv_setpvn(perror, (char*)wszMsgBuff, strlen(wszMsgBuff)); sv_setiv(perror,(IV) err); SvPOK_on(perror); XPUSHs(sv_2mortal(newSViv(-1))); CloseHandle( hProcessSnap ); } else { do { sprintf(temp, "%d", pe32.th32ProcessID); if(debug==1) { printf("Temp: %s\n",pe32.szExeFile); } if(hv_store(rh,temp,strlen(temp),newSVpv(pe32.szExeF +ile, strlen(pe32.szExeFile)), 0)==NULL) //if(hv_store(rh,pe32.szExeFile,strlen(pe32.szExeFil +e),newSVuv(pe32.th32ProcessID), 0)==NULL) { printf("can not store %s in hash!\n", pe32.szExe +File); } } while( Process32Next( hProcessSnap, &pe32 ) ); CloseHandle( hProcessSnap ); .....
and here is the definition of structure PROCESSENTRY32
typedef struct tagPROCESSENTRY32 { DWORD dwSize; DWORD cntUsage; DWORD th32ProcessID; ULONG_PTR th32DefaultHeapID; DWORD th32ModuleID; DWORD cntThreads; DWORD th32ParentProcessID; LONG pcPriClassBase; DWORD dwFlags; TCHAR szExeFile[MAX_PATH]; } PROCESSENTRY32, *PPROCESSENTRY32;
As above szExeFile is a TCHAR arary, and actually, in my computer, it's a WCHAR array. the author of W::P::L put a wchar_t into a sv directly by sv_setpv. and it seems right when I check typemap under ExtUtils:
wchar_t * T_PV ....... ....... T_PV sv_setpv((SV*)$arg, $var);
But wield is, when I put the similar c code in VS2010, it complains:
: error C2664: 'Perl_sv_setpv' : cannot convert parameter 3 from 'WCHA +R [260]' to 'const char *const ' (I think it more makes sense tho)

So what is perl/XS does to make building this module correctly?





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 wchar_t*, char* and perl XS 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.