xiaoyafeng has asked for the wisdom of the Perl Monks concerning the following question:
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
and here is the definition of structure PROCESSENTRY32.......... 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 ); .....
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: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;
But wield is, when I put the similar c code in VS2010, it complains:wchar_t * T_PV ....... ....... T_PV sv_setpv((SV*)$arg, $var);
: 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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: wchar_t*, char* and perl XS
by BrowserUk (Patriarch) on Jul 13, 2012 at 06:18 UTC | |
by xiaoyafeng (Deacon) on Jul 13, 2012 at 13:13 UTC | |
by bulk88 (Priest) on Jul 13, 2012 at 15:03 UTC | |
by xiaoyafeng (Deacon) on Jul 14, 2012 at 03:34 UTC | |
by bulk88 (Priest) on Jul 14, 2012 at 14:05 UTC | |
by BrowserUk (Patriarch) on Jul 13, 2012 at 13:25 UTC | |
by xiaoyafeng (Deacon) on Jul 13, 2012 at 13:37 UTC | |
Re: wchar_t*, char* and perl XS
by bulk88 (Priest) on Jul 12, 2012 at 19:51 UTC | |
by Anonymous Monk on Jul 13, 2012 at 02:19 UTC | |
by bulk88 (Priest) on Jul 13, 2012 at 15:04 UTC | |
Re: wchar_t*, char* and perl XS
by syphilis (Archbishop) on Jul 13, 2012 at 03:49 UTC | |
by xiaoyafeng (Deacon) on Jul 13, 2012 at 13:03 UTC | |
Re: wchar_t*, char* and perl XS
by Anonymous Monk on Jul 12, 2012 at 16:27 UTC |
Back to
Seekers of Perl Wisdom