Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^2: wchar_t*, char* and perl XS

by xiaoyafeng (Chaplain)
on Jul 13, 2012 at 13:13 UTC ( #981614=note: print w/ replies, xml ) Need Help??


in reply to Re: wchar_t*, char* and perl XS
in thread wchar_t*, char* and perl XS

AH!! I use cl.exe in command prompt, it compiles fine! So it means visual studio does many things underground?! Besides, I find using wcstombs can eliminate this error (in Visual studio).





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


Comment on Re^2: wchar_t*, char* and perl XS
Re^3: wchar_t*, char* and perl XS
by BrowserUk (Pope) on Jul 13, 2012 at 13:25 UTC
    So it means visual studio does many things underground?!

    Probably. I don't know because I've never used it.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    The start of some sanity?

      I've never used it.

      Sadly, I have to, I can't imagine how code C# etc without VS, and company paid money for that.... lol





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

Re^3: wchar_t*, char* and perl XS
by bulk88 (Priest) on Jul 13, 2012 at 15:03 UTC
    I've never tried use the VS GUI to compile a XS DLL since VS doesn't know what xsubpp is, plus there are many macros that are defined at the cmd line. You can compile on the command line then debug the DLL in the VS GUI. In the makefile.pl put "XSOPT => ' -nolinenumbers '," in the %config EUMM hash so you see the original C file in the debugger and not the XS file which isn't valid C code.

    On second thought, you are not using XS and are not making a DLL and have no makefile, you are embedding the Perl Interp. Choice 1, switch the project in the VS GUI from UNICODE mode to MBCS mode . See http://www.d3dcoder.net/Data/Book2/Book2Setup.pdf#5

    Choice 2, is to manually define a PROCESSENTRY32A that MS never created. From my around 2003 platform sdk.
    typedef struct tagPROCESSENTRY32W { DWORD dwSize; DWORD cntUsage; DWORD th32ProcessID; // this process ULONG_PTR th32DefaultHeapID; DWORD th32ModuleID; // associated exe DWORD cntThreads; DWORD th32ParentProcessID; // this process's parent process LONG pcPriClassBase; // Base priority of process's thre +ads DWORD dwFlags; WCHAR szExeFile[MAX_PATH]; // Path } PROCESSENTRY32W; typedef PROCESSENTRY32W * PPROCESSENTRY32W; typedef PROCESSENTRY32W * LPPROCESSENTRY32W; ......................... typedef struct tagPROCESSENTRY32 { DWORD dwSize; DWORD cntUsage; DWORD th32ProcessID; // this process ULONG_PTR th32DefaultHeapID; DWORD th32ModuleID; // associated exe DWORD cntThreads; DWORD th32ParentProcessID; // this process's parent process LONG pcPriClassBase; // Base priority of process's thre +ads DWORD dwFlags; CHAR szExeFile[MAX_PATH]; // Path } PROCESSENTRY32; typedef PROCESSENTRY32 * PPROCESSENTRY32; typedef PROCESSENTRY32 * LPPROCESSENTRY32; #ifdef UNICODE #define Process32First Process32FirstW #define Process32Next Process32NextW #define PROCESSENTRY32 PROCESSENTRY32W #define PPROCESSENTRY32 PPROCESSENTRY32W #define LPPROCESSENTRY32 LPPROCESSENTRY32W #endif // !UNICODE
    Choice 3 is to undef those last 3 lines and use the A postfix functions. Choice 4, if you HAVE to have use the wide APIs, and pass unicode into Perl language, that is a completely different topic, I suggest doing exactly what is done here https://github.com/jandubois/win32/blob/841409b37dea45266c2afb68919d80c4e5dea657/Win32.xs#L174 for converting UTF16 into "Perl Unicode".

    You can also rethink your design and make a XS module instead of embedding Perl into your own application. There has to be some Perl language code you want to run right?

      Thanks bulk88!!

      Your reply makes me clean up! VS GUI default set code to UNICODE(wide char), but gcc or cl.exe won't. So to me, choice 1 is the best, coz it keeps embeding perl(ANSI) and C CODE consistent.

      BTW. for choice 4, personally, I think it's a standard solution of converting wide chars to perl. why nobody modify it a little to suit for importing to perlAPI other than just stay in win32.xs?





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

        BTW. for choice 4, personally, I think it's a standard solution of converting wide chars to perl. why nobody modify it a little to suit for importing to perlAPI other than just stay in win32.xs?

        I have wondered that also. It should be part of Perl's Win32 Perl Standard Library in the perl interpreter, with a win32_ prefix since utf16 is so popular on Windows. You would have to bring up the problem with Perl5Porters and file a bug about there being no standard way in XS to turn a UTF16 string into a Perl Scalar.

        Here is a dump of Perl's win32 specific functions that exported from DLL from Perl 5.17, none of them are public api AFAIK, but some of them are just wrappers around C standard Library I think (On Windows a process can have many different C Standard Libraries loaded because each DLL was compiled with a different Visual Studio, you can not mix resources between different CRTs).
        // win32_abort; Index 1091; // win32_accept; Index 1092; // win32_access; Index 1093; // win32_alarm; Index 1094; // win32_ansipath; Index 1095; // win32_async_check; Index 1096; // win32_bind; Index 1097; // win32_calloc; Index 1098; // win32_chdir; Index 1099; // win32_chmod; Index 1100; // win32_chsize; Index 1101; // win32_clearenv; Index 1102; // win32_clearerr; Index 1103; // win32_close; Index 1104; // win32_closedir; Index 1105; // win32_closesocket; Index 1106; // win32_connect; Index 1107; // win32_crypt; Index 1108; // win32_dup; Index 1109; // win32_dup2; Index 1110; // win32_dynaload; Index 1111; // win32_endhostent; Index 1112; // win32_endnetent; Index 1113; // win32_endprotoent; Index 1114; // win32_endservent; Index 1115; // win32_environ; Index 1116; // win32_eof; Index 1117; // win32_errno; Index 1118; // win32_execv; Index 1119; // win32_execvp; Index 1120; // win32_fclose; Index 1121; // win32_fcloseall; Index 1122; // win32_fdopen; Index 1123; // win32_feof; Index 1124; // win32_ferror; Index 1125; // win32_fflush; Index 1126; // win32_fgetc; Index 1127; // win32_fgetpos; Index 1128; // win32_fgets; Index 1129; // win32_fileno; Index 1130; // win32_flock; Index 1131; // win32_flushall; Index 1132; // win32_fopen; Index 1133; // win32_fprintf; Index 1134; // win32_fputc; Index 1135; // win32_fputs; Index 1136; // win32_fread; Index 1137; // win32_free; Index 1138; // win32_free_childdir; Index 1139; // win32_free_childenv; Index 1140; // win32_freopen; Index 1141; // win32_fseek; Index 1142; // win32_fsetpos; Index 1143; // win32_fstat; Index 1144; // win32_ftell; Index 1145; // win32_fwrite; Index 1146; // win32_get_childdir; Index 1147; // win32_get_childenv; Index 1148; // win32_get_osfhandle; Index 1149; // win32_getc; Index 1150; // win32_getchar; Index 1151; // win32_getenv; Index 1152; // win32_gethostbyaddr; Index 1153; // win32_gethostbyname; Index 1154; // win32_gethostname; Index 1155; // win32_getnetbyaddr; Index 1156; // win32_getnetbyname; Index 1157; // win32_getnetent; Index 1158; // win32_getpeername; Index 1159; // win32_getpid; Index 1160; // win32_getprotobyname; Index 1161; // win32_getprotobynumber; Index 1162; // win32_getprotoent; Index 1163; // win32_gets; Index 1164; // win32_getservbyname; Index 1165; // win32_getservbyport; Index 1166; // win32_getservent; Index 1167; // win32_getsockname; Index 1168; // win32_getsockopt; Index 1169; // win32_gettimeofday; Index 1170; // win32_htonl; Index 1171; // win32_htons; Index 1172; // win32_inet_addr; Index 1173; // win32_inet_ntoa; Index 1174; // win32_ioctl; Index 1175; // win32_ioctlsocket; Index 1176; // win32_isatty; Index 1177; // win32_kill; Index 1178; // win32_link; Index 1179; // win32_listen; Index 1180; // win32_longpath; Index 1181; // win32_lseek; Index 1182; // win32_malloc; Index 1183; // win32_mkdir; Index 1184; // win32_ntohl; Index 1185; // win32_ntohs; Index 1186; // win32_open; Index 1187; // win32_open_osfhandle; Index 1188; // win32_opendir; Index 1189; // win32_os_id; Index 1190; // win32_pclose; Index 1191; // win32_perror; Index 1192; // win32_pipe; Index 1193; // win32_popen; Index 1194; // win32_printf; Index 1195; // win32_putc; Index 1196; // win32_putchar; Index 1197; // win32_putenv; Index 1198; // win32_puts; Index 1199; // win32_read; Index 1200; // win32_readdir; Index 1201; // win32_realloc; Index 1202; // win32_recv; Index 1203; // win32_recvfrom; Index 1204; // win32_rename; Index 1205; // win32_rewind; Index 1206; // win32_rewinddir; Index 1207; // win32_rmdir; Index 1208; // win32_seekdir; Index 1209; // win32_select; Index 1210; // win32_send; Index 1211; // win32_sendto; Index 1212; // win32_setbuf; Index 1213; // win32_sethostent; Index 1214; // win32_setmode; Index 1215; // win32_setnetent; Index 1216; // win32_setprotoent; Index 1217; // win32_setservent; Index 1218; // win32_setsockopt; Index 1219; // win32_setvbuf; Index 1220; // win32_shutdown; Index 1221; // win32_sleep; Index 1222; // win32_socket; Index 1223; // win32_spawnvp; Index 1224; // win32_stat; Index 1225; // win32_stderr; Index 1226; // win32_stdin; Index 1227; // win32_stdout; Index 1228; // win32_str_os_error; Index 1229; // win32_strerror; Index 1230; // win32_tell; Index 1231; // win32_telldir; Index 1232; // win32_times; Index 1233; // win32_tmpfile; Index 1234; // win32_uname; Index 1235; // win32_ungetc; Index 1236; // win32_unlink; Index 1237; // win32_utime; Index 1238; // win32_vfprintf; Index 1239; // win32_vprintf; Index 1240; // win32_wait; Index 1241; // win32_waitpid; Index 1242; // win32_write; Index 1243;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://981614]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (14)
As of 2014-09-18 12:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (114 votes), past polls