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 NIS |
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" | |
eda5ff31 | 29 | #include "win32.h" |
565764a8 DL |
30 | |
31 | #ifdef PERL_OBJECT | |
32 | #define NO_XSLOCKS | |
33 | #endif /* PERL_OBJECT */ | |
34 | ||
0a753a76 | 35 | #include "XSUB.h" |
36 | ||
eda5ff31 GS |
37 | static SV *error_sv; |
38 | ||
39 | static char * | |
40 | OS_Error_String(void) | |
41 | { | |
42 | DWORD err = GetLastError(); | |
43 | STRLEN len; | |
44 | if (!error_sv) | |
45 | error_sv = newSVpv("",0); | |
46 | win32_str_os_error(error_sv,err); | |
47 | return SvPV(error_sv,len); | |
48 | } | |
49 | ||
0a753a76 | 50 | #include "dlutils.c" /* SaveError() etc */ |
51 | ||
52 | static void | |
565764a8 | 53 | dl_private_init(CPERLarg) |
0a753a76 | 54 | { |
1d583055 | 55 | (void)dl_generic_private_init(PERL_OBJECT_THIS); |
0a753a76 | 56 | } |
57 | ||
26b3385c DL |
58 | /* |
59 | This function assumes the list staticlinkmodules | |
60 | will be formed from package names with '::' replaced | |
61 | with '/'. Thus Win32::OLE is in the list as Win32/OLE | |
62 | */ | |
0a753a76 | 63 | static int |
64 | dl_static_linked(char *filename) | |
65 | { | |
68dc0745 | 66 | char **p; |
26b3385c DL |
67 | char* ptr; |
68 | static char subStr[] = "/auto/"; | |
69 | char szBuffer[MAX_PATH]; | |
70 | ||
71 | /* change all the '\\' to '/' */ | |
72 | strcpy(szBuffer, filename); | |
73 | for(ptr = szBuffer; ptr = strchr(ptr, '\\'); ++ptr) | |
74 | *ptr = '/'; | |
75 | ||
76 | /* delete the file name */ | |
77 | ptr = strrchr(szBuffer, '/'); | |
78 | if(ptr != NULL) | |
79 | *ptr = '\0'; | |
80 | ||
81 | /* remove leading lib path */ | |
82 | ptr = strstr(szBuffer, subStr); | |
83 | if(ptr != NULL) | |
84 | ptr += sizeof(subStr)-1; | |
85 | else | |
86 | ptr = szBuffer; | |
87 | ||
0a753a76 | 88 | for (p = staticlinkmodules; *p;p++) { |
26b3385c | 89 | if (strstr(ptr, *p)) return 1; |
68dc0745 | 90 | }; |
91 | return 0; | |
0a753a76 | 92 | } |
93 | ||
94 | MODULE = DynaLoader PACKAGE = DynaLoader | |
95 | ||
96 | BOOT: | |
1d583055 | 97 | (void)dl_private_init(PERL_OBJECT_THIS); |
0a753a76 | 98 | |
99 | void * | |
100 | dl_load_file(filename,flags=0) | |
101 | char * filename | |
102 | int flags | |
103 | PREINIT: | |
104 | CODE: | |
76e3520e | 105 | DLDEBUG(1,PerlIO_printf(PerlIO_stderr(),"dl_load_file(%s):\n", filename)); |
68dc0745 | 106 | if (dl_static_linked(filename) == 0) |
107 | RETVAL = (void*) LoadLibraryEx(filename, NULL, LOAD_WITH_ALTERED_SEARCH_PATH ) ; | |
108 | else | |
109 | RETVAL = (void*) GetModuleHandle(NULL); | |
76e3520e | 110 | DLDEBUG(2,PerlIO_printf(PerlIO_stderr()," libref=%x\n", RETVAL)); |
0a753a76 | 111 | ST(0) = sv_newmortal() ; |
112 | if (RETVAL == NULL) | |
eda5ff31 | 113 | SaveError(PERL_OBJECT_THIS_ "load_file:%s",OS_Error_String()) ; |
0a753a76 | 114 | else |
115 | sv_setiv( ST(0), (IV)RETVAL); | |
116 | ||
117 | ||
118 | void * | |
119 | dl_find_symbol(libhandle, symbolname) | |
120 | void * libhandle | |
121 | char * symbolname | |
122 | CODE: | |
76e3520e | 123 | DLDEBUG(2,PerlIO_printf(PerlIO_stderr(),"dl_find_symbol(handle=%x, symbol=%s)\n", |
68dc0745 | 124 | libhandle, symbolname)); |
0a753a76 | 125 | RETVAL = (void*) GetProcAddress((HINSTANCE) libhandle, symbolname); |
76e3520e | 126 | DLDEBUG(2,PerlIO_printf(PerlIO_stderr()," symbolref = %x\n", RETVAL)); |
0a753a76 | 127 | ST(0) = sv_newmortal() ; |
128 | if (RETVAL == NULL) | |
eda5ff31 | 129 | SaveError(PERL_OBJECT_THIS_ "find_symbol:%s",OS_Error_String()) ; |
0a753a76 | 130 | else |
131 | sv_setiv( ST(0), (IV)RETVAL); | |
132 | ||
133 | ||
134 | void | |
135 | dl_undef_symbols() | |
136 | PPCODE: | |
137 | ||
138 | ||
139 | ||
140 | # These functions should not need changing on any platform: | |
141 | ||
142 | void | |
143 | dl_install_xsub(perl_name, symref, filename="$Package") | |
144 | char * perl_name | |
145 | void * symref | |
146 | char * filename | |
147 | CODE: | |
76e3520e | 148 | DLDEBUG(2,PerlIO_printf(PerlIO_stderr(),"dl_install_xsub(name=%s, symref=%x)\n", |
68dc0745 | 149 | perl_name, symref)); |
e3b8966e | 150 | ST(0)=sv_2mortal(newRV((SV*)newXS(perl_name, (void(*)(CV* _CPERLarg))symref, filename))); |
0a753a76 | 151 | |
152 | ||
153 | char * | |
154 | dl_error() | |
155 | CODE: | |
156 | RETVAL = LastError ; | |
157 | OUTPUT: | |
158 | RETVAL | |
159 | ||
160 | # end. |