[asperl] added AS patch#9
[p5sagit/p5-mst-13.2.git] / win32 / dl_win32.xs
1 /* dl_win32.xs
2  * 
3  * Platform:    Win32 (Windows NT/Windows 95)
4  * Author:      Wei-Yuen Tan (wyt@hip.com)
5  * Created:     A warm day in June, 1995
6  *
7  * Modified:
8  *    August 23rd 1995 - rewritten after losing everything when I
9  *                       wiped off my NT partition (eek!)
10  */
11
12 /* Porting notes:
13
14 I merely took Paul's dl_dlopen.xs, took out extraneous stuff and
15 replaced the appropriate SunOS calls with the corresponding Win32
16 calls.
17
18 */
19
20 #define WIN32_LEAN_AND_MEAN
21 #ifdef __GNUC__
22 #define Win32_Winsock
23 #endif
24 #include <windows.h>
25 #include <string.h>
26
27 #include "EXTERN.h"
28 #include "perl.h"
29
30 #ifdef PERL_OBJECT
31 #define NO_XSLOCKS
32 #endif  /* PERL_OBJECT */
33
34 #include "XSUB.h"
35
36 #include "dlutils.c"    /* SaveError() etc      */
37
38 static void
39 dl_private_init(CPERLarg)
40 {
41     (void)dl_generic_private_init(THIS);
42 }
43
44 static int
45 dl_static_linked(char *filename)
46 {
47     char **p;
48     for (p = staticlinkmodules; *p;p++) {
49         if (strstr(filename, *p)) return 1;
50     };
51     return 0;
52 }
53
54 MODULE = DynaLoader     PACKAGE = DynaLoader
55
56 BOOT:
57     (void)dl_private_init(THIS);
58
59 void *
60 dl_load_file(filename,flags=0)
61     char *              filename
62     int                 flags
63     PREINIT:
64     CODE:
65     DLDEBUG(1,PerlIO_printf(PerlIO_stderr(),"dl_load_file(%s):\n", filename));
66     if (dl_static_linked(filename) == 0)
67         RETVAL = (void*) LoadLibraryEx(filename, NULL, LOAD_WITH_ALTERED_SEARCH_PATH ) ;
68     else
69         RETVAL = (void*) GetModuleHandle(NULL);
70     DLDEBUG(2,PerlIO_printf(PerlIO_stderr()," libref=%x\n", RETVAL));
71     ST(0) = sv_newmortal() ;
72     if (RETVAL == NULL)
73         SaveError(THIS_ "%d",GetLastError()) ;
74     else
75         sv_setiv( ST(0), (IV)RETVAL);
76
77
78 void *
79 dl_find_symbol(libhandle, symbolname)
80     void *      libhandle
81     char *      symbolname
82     CODE:
83     DLDEBUG(2,PerlIO_printf(PerlIO_stderr(),"dl_find_symbol(handle=%x, symbol=%s)\n",
84                       libhandle, symbolname));
85     RETVAL = (void*) GetProcAddress((HINSTANCE) libhandle, symbolname);
86     DLDEBUG(2,PerlIO_printf(PerlIO_stderr(),"  symbolref = %x\n", RETVAL));
87     ST(0) = sv_newmortal() ;
88     if (RETVAL == NULL)
89         SaveError(THIS_ "%d",GetLastError()) ;
90     else
91         sv_setiv( ST(0), (IV)RETVAL);
92
93
94 void
95 dl_undef_symbols()
96     PPCODE:
97
98
99
100 # These functions should not need changing on any platform:
101
102 void
103 dl_install_xsub(perl_name, symref, filename="$Package")
104     char *              perl_name
105     void *              symref 
106     char *              filename
107     CODE:
108     DLDEBUG(2,PerlIO_printf(PerlIO_stderr(),"dl_install_xsub(name=%s, symref=%x)\n",
109                       perl_name, symref));
110     ST(0)=sv_2mortal(newRV((SV*)newXS(perl_name, (void(*)(CPERLarg_ CV*))symref, filename)));
111
112
113 char *
114 dl_error()
115     CODE:
116     RETVAL = LastError ;
117     OUTPUT:
118     RETVAL
119
120 # end.