Commit | Line | Data |
0a753a76 |
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 |
a835ef8a |
21 | #ifdef __GNUC__ |
22 | #define Win32_Winsock |
23 | #endif |
0a753a76 |
24 | #include <windows.h> |
25 | #include <string.h> |
26 | |
27 | #include "EXTERN.h" |
28 | #include "perl.h" |
565764a8 |
29 | |
30 | #ifdef PERL_OBJECT |
31 | #define NO_XSLOCKS |
32 | #endif /* PERL_OBJECT */ |
33 | |
0a753a76 |
34 | #include "XSUB.h" |
35 | |
36 | #include "dlutils.c" /* SaveError() etc */ |
37 | |
38 | static void |
565764a8 |
39 | dl_private_init(CPERLarg) |
0a753a76 |
40 | { |
565764a8 |
41 | (void)dl_generic_private_init(THIS); |
0a753a76 |
42 | } |
43 | |
565764a8 |
44 | #ifdef PERL_OBJECT |
45 | #define dl_static_linked(x) 0 |
46 | #else |
0a753a76 |
47 | static int |
48 | dl_static_linked(char *filename) |
49 | { |
68dc0745 |
50 | char **p; |
0a753a76 |
51 | for (p = staticlinkmodules; *p;p++) { |
68dc0745 |
52 | if (strstr(filename, *p)) return 1; |
53 | }; |
54 | return 0; |
0a753a76 |
55 | } |
565764a8 |
56 | #endif |
0a753a76 |
57 | |
58 | MODULE = DynaLoader PACKAGE = DynaLoader |
59 | |
60 | BOOT: |
9d8a25dc |
61 | (void)dl_private_init(THIS); |
0a753a76 |
62 | |
63 | void * |
64 | dl_load_file(filename,flags=0) |
65 | char * filename |
66 | int flags |
67 | PREINIT: |
68 | CODE: |
76e3520e |
69 | DLDEBUG(1,PerlIO_printf(PerlIO_stderr(),"dl_load_file(%s):\n", filename)); |
68dc0745 |
70 | if (dl_static_linked(filename) == 0) |
71 | RETVAL = (void*) LoadLibraryEx(filename, NULL, LOAD_WITH_ALTERED_SEARCH_PATH ) ; |
72 | else |
73 | RETVAL = (void*) GetModuleHandle(NULL); |
76e3520e |
74 | DLDEBUG(2,PerlIO_printf(PerlIO_stderr()," libref=%x\n", RETVAL)); |
0a753a76 |
75 | ST(0) = sv_newmortal() ; |
76 | if (RETVAL == NULL) |
9d8a25dc |
77 | SaveError(THIS_ "%d",GetLastError()) ; |
0a753a76 |
78 | else |
79 | sv_setiv( ST(0), (IV)RETVAL); |
80 | |
81 | |
82 | void * |
83 | dl_find_symbol(libhandle, symbolname) |
84 | void * libhandle |
85 | char * symbolname |
86 | CODE: |
76e3520e |
87 | DLDEBUG(2,PerlIO_printf(PerlIO_stderr(),"dl_find_symbol(handle=%x, symbol=%s)\n", |
68dc0745 |
88 | libhandle, symbolname)); |
0a753a76 |
89 | RETVAL = (void*) GetProcAddress((HINSTANCE) libhandle, symbolname); |
76e3520e |
90 | DLDEBUG(2,PerlIO_printf(PerlIO_stderr()," symbolref = %x\n", RETVAL)); |
0a753a76 |
91 | ST(0) = sv_newmortal() ; |
92 | if (RETVAL == NULL) |
9d8a25dc |
93 | SaveError(THIS_ "%d",GetLastError()) ; |
0a753a76 |
94 | else |
95 | sv_setiv( ST(0), (IV)RETVAL); |
96 | |
97 | |
98 | void |
99 | dl_undef_symbols() |
100 | PPCODE: |
101 | |
102 | |
103 | |
104 | # These functions should not need changing on any platform: |
105 | |
106 | void |
107 | dl_install_xsub(perl_name, symref, filename="$Package") |
108 | char * perl_name |
109 | void * symref |
110 | char * filename |
111 | CODE: |
76e3520e |
112 | DLDEBUG(2,PerlIO_printf(PerlIO_stderr(),"dl_install_xsub(name=%s, symref=%x)\n", |
68dc0745 |
113 | perl_name, symref)); |
9d8a25dc |
114 | ST(0)=sv_2mortal(newRV((SV*)newXS(perl_name, (void(*)(CPERLarg_ CV*))symref, filename))); |
0a753a76 |
115 | |
116 | |
117 | char * |
118 | dl_error() |
119 | CODE: |
120 | RETVAL = LastError ; |
121 | OUTPUT: |
122 | RETVAL |
123 | |
124 | # end. |