2 * "The Road goes ever on and on, down from the door where it began."
15 # define EXTERN_C extern "C"
17 # define EXTERN_C extern
20 static void xs_init _((void));
22 __declspec(dllexport) int
23 RunPerl(int argc, char **argv, char **env, void *iosubsystem)
26 PerlInterpreter *my_perl;
27 void *pOldIOSubsystem;
29 pOldIOSubsystem = SetIOSubSystem(iosubsystem);
31 PERL_SYS_INIT(&argc,&argv);
33 perl_init_i18nl10n(1);
35 if (!(my_perl = perl_alloc()))
37 perl_construct( my_perl );
38 perl_destruct_level = 0;
40 exitstatus = perl_parse( my_perl, xs_init, argc, argv, env);
42 exitstatus = perl_run( my_perl );
45 perl_destruct( my_perl );
50 SetIOSubSystem(pOldIOSubsystem);
55 extern HANDLE PerlDllHandle;
58 DllMain(HANDLE hModule, /* DLL module handle */
59 DWORD fdwReason, /* reason called */
60 LPVOID lpvReserved) /* reserved */
63 /* The DLL is attaching to a process due to process
64 * initialization or a call to LoadLibrary.
66 case DLL_PROCESS_ATTACH:
67 /* #define DEFAULT_BINMODE */
68 #ifdef DEFAULT_BINMODE
69 _setmode( _fileno( stdin ), _O_BINARY );
70 _setmode( _fileno( stdout ), _O_BINARY );
71 _setmode( _fileno( stderr ), _O_BINARY );
74 PerlDllHandle = hModule;
77 /* The DLL is detaching from a process due to
78 * process termination or call to FreeLibrary.
80 case DLL_PROCESS_DETACH:
83 /* The attached process creates a new thread. */
84 case DLL_THREAD_ATTACH:
87 /* The thread of the attached process terminates. */
88 case DLL_THREAD_DETACH:
97 /* Register any extra external extensions */
99 char *staticlinkmodules[] = {
104 EXTERN_C void boot_DynaLoader _((CV* cv));
110 SV *sv = sv_newmortal();
111 /* Make one call with zero size - return value is required size */
112 DWORD len = GetCurrentDirectory((DWORD)0,NULL);
113 SvUPGRADE(sv,SVt_PV);
115 SvCUR(sv) = GetCurrentDirectory((DWORD) SvLEN(sv), SvPVX(sv));
118 * then it worked, set PV valid,
119 * else leave it 'undef'
133 croak("usage: Win32::SetCurrentDirectory($cwd)");
134 if (SetCurrentDirectory(SvPV(ST(0),na)))
141 XS(w32_GetNextAvailDrive)
145 char root[] = "_:\\";
148 if (GetDriveType(root) == 1) {
160 XSRETURN_IV(GetLastError());
168 DWORD size = sizeof(name);
169 if (GetUserName(name,&size)) {
170 /* size includes NULL */
171 ST(0) = sv_2mortal(newSVpv(name,size-1));
181 char name[MAX_COMPUTERNAME_LENGTH+1];
182 DWORD size = sizeof(name);
183 if (GetComputerName(name,&size)) {
184 /* size does NOT include NULL :-( */
185 ST(0) = sv_2mortal(newSVpv(name,size));
197 DWORD size = sizeof(name);
198 if (GetUserName(name,&size)) {
200 DWORD sidlen = sizeof(sid);
202 DWORD dnamelen = sizeof(dname);
204 if (LookupAccountName(NULL, name, &sid, &sidlen,
205 dname, &dnamelen, &snu)) {
206 XSRETURN_PV(dname); /* all that for this */
217 DWORD flags, filecomplen;
218 if (GetVolumeInformation(NULL, NULL, 0, NULL, &filecomplen,
219 &flags, fsname, sizeof(fsname))) {
220 if (GIMME == G_ARRAY) {
221 XPUSHs(sv_2mortal(newSVpv(fsname,0)));
222 XPUSHs(sv_2mortal(newSViv(flags)));
223 XPUSHs(sv_2mortal(newSViv(filecomplen)));
238 osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
239 if (GetVersionEx(&osver)) {
240 XPUSHs(newSVpv(osver.szCSDVersion, 0));
241 XPUSHs(newSViv(osver.dwMajorVersion));
242 XPUSHs(newSViv(osver.dwMinorVersion));
243 XPUSHs(newSViv(osver.dwBuildNumber));
244 XPUSHs(newSViv(osver.dwPlatformId));
255 XSRETURN_IV(IsWinNT());
262 XSRETURN_IV(IsWin95());
266 XS(w32_FormatMessage)
273 croak("usage: Win32::FormatMessage($errno)");
275 if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
276 &source, SvIV(ST(0)), 0,
277 msgbuf, sizeof(msgbuf)-1, NULL))
288 PROCESS_INFORMATION stProcInfo;
289 STARTUPINFO stStartInfo;
290 BOOL bSuccess = FALSE;
293 croak("usage: Win32::Spawn($cmdName, $args, $PID)");
295 cmd = SvPV(ST(0),na);
296 args = SvPV(ST(1), na);
298 memset(&stStartInfo, 0, sizeof(stStartInfo)); /* Clear the block */
299 stStartInfo.cb = sizeof(stStartInfo); /* Set the structure size */
300 stStartInfo.dwFlags = STARTF_USESHOWWINDOW; /* Enable wShowWindow control */
301 stStartInfo.wShowWindow = SW_SHOWMINNOACTIVE; /* Start min (normal) */
304 cmd, /* Image path */
305 args, /* Arguments for command line */
306 NULL, /* Default process security */
307 NULL, /* Default thread security */
308 FALSE, /* Must be TRUE to use std handles */
309 NORMAL_PRIORITY_CLASS, /* No special scheduling */
310 NULL, /* Inherit our environment block */
311 NULL, /* Inherit our currrent directory */
312 &stStartInfo, /* -> Startup info */
313 &stProcInfo)) /* <- Process info (if OK) */
315 CloseHandle(stProcInfo.hThread);/* library source code does this. */
316 sv_setiv(ST(2), stProcInfo.dwProcessId);
319 XSRETURN_IV(bSuccess);
326 XSRETURN_IV(GetTickCount());
330 XS(w32_GetShortPathName)
336 croak("usage: Win32::GetShortPathName($longPathName)");
338 shortpath = sv_mortalcopy(ST(0));
339 SvUPGRADE(shortpath, SVt_PV);
340 /* src == target is allowed */
341 if (GetShortPathName(SvPVX(shortpath), SvPVX(shortpath), SvCUR(shortpath)))
351 char *file = __FILE__;
353 newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
355 /* XXX should be removed after checking with Nick */
356 newXS("Win32::GetCurrentDirectory", w32_GetCwd, file);
358 /* these names are Activeware compatible */
359 newXS("Win32::GetCwd", w32_GetCwd, file);
360 newXS("Win32::SetCwd", w32_SetCwd, file);
361 newXS("Win32::GetNextAvailDrive", w32_GetNextAvailDrive, file);
362 newXS("Win32::GetLastError", w32_GetLastError, file);
363 newXS("Win32::LoginName", w32_LoginName, file);
364 newXS("Win32::NodeName", w32_NodeName, file);
365 newXS("Win32::DomainName", w32_DomainName, file);
366 newXS("Win32::FsType", w32_FsType, file);
367 newXS("Win32::GetOSVersion", w32_GetOSVersion, file);
368 newXS("Win32::IsWinNT", w32_IsWinNT, file);
369 newXS("Win32::IsWin95", w32_IsWin95, file);
370 newXS("Win32::FormatMessage", w32_FormatMessage, file);
371 newXS("Win32::Spawn", w32_Spawn, file);
372 newXS("Win32::GetTickCount", w32_GetTickCount, file);
373 newXS("Win32::GetShortPathName", w32_GetShortPathName, file);
375 /* XXX Bloat Alert! The following Activeware preloads really
376 * ought to be part of Win32::Sys::*, so they're not included
381 * InitiateSystemShutdown
382 * AbortSystemShutdown
383 * ExpandEnvrironmentStrings