56cba541b9e9e2f8cf004918744908e1967f8524
[p5sagit/p5-mst-13.2.git] / win32 / perllib.c
1 /*
2  * "The Road goes ever on and on, down from the door where it began."
3  */
4
5
6 #include "EXTERN.h"
7 #include "perl.h"
8 #include "XSUB.h"
9
10 static void xs_init _((void));
11
12 __declspec(dllexport) int
13 RunPerl(int argc, char **argv, char **env, void *iosubsystem)
14 {
15     int exitstatus;
16     PerlInterpreter *my_perl;
17     void *pOldIOSubsystem;
18
19     pOldIOSubsystem = SetIOSubSystem(iosubsystem);
20
21     PERL_SYS_INIT(&argc,&argv);
22
23     perl_init_i18nl10n(1);
24
25     if (!(my_perl = perl_alloc()))
26         return (1);
27     perl_construct( my_perl );
28     perl_destruct_level = 0;
29
30     exitstatus = perl_parse( my_perl, xs_init, argc, argv, env);
31     if (!exitstatus) {
32         exitstatus = perl_run( my_perl );
33     }
34
35     perl_destruct( my_perl );
36     perl_free( my_perl );
37
38     PERL_SYS_TERM();
39
40     SetIOSubSystem(pOldIOSubsystem);
41
42     return (exitstatus);
43 }
44
45 extern HANDLE PerlDllHandle;
46
47 BOOL APIENTRY
48 DllMain(HANDLE hModule,         /* DLL module handle */
49         DWORD fdwReason,        /* reason called */
50         LPVOID lpvReserved)     /* reserved */
51
52     switch (fdwReason) {
53         /* The DLL is attaching to a process due to process
54          * initialization or a call to LoadLibrary.
55          */
56     case DLL_PROCESS_ATTACH:
57 /* #define DEFAULT_BINMODE */
58 #ifdef DEFAULT_BINMODE
59         setmode( fileno( stdin  ), O_BINARY );
60         setmode( fileno( stdout ), O_BINARY );
61         setmode( fileno( stderr ), O_BINARY );
62         _fmode = O_BINARY;
63 #endif
64         PerlDllHandle = hModule;
65         break;
66
67         /* The DLL is detaching from a process due to
68          * process termination or call to FreeLibrary.
69          */
70     case DLL_PROCESS_DETACH:
71         break;
72
73         /* The attached process creates a new thread. */
74     case DLL_THREAD_ATTACH:
75         break;
76
77         /* The thread of the attached process terminates. */
78     case DLL_THREAD_DETACH:
79         break;
80
81     default:
82         break;
83     }
84     return TRUE;
85 }
86
87 /* Register any extra external extensions */
88
89 char *staticlinkmodules[] = {
90     "DynaLoader",
91     NULL,
92 };
93
94 EXTERN_C void boot_DynaLoader _((CV* cv));
95
96 static void
97 xs_init()
98 {
99     char *file = __FILE__;
100     dXSUB_SYS;
101     newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
102 }
103