-ObjectFile loadLibrary(fn)
-String fn; {
- return dlopen(fn,RTLD_NOW | RTLD_GLOBAL);
+void* getDLLSymbol(line,dll0,symbol0) /* load dll and lookup symbol */
+Int line;
+String dll0;
+String symbol0; {
+ void* sym;
+ char dll[1000];
+ char symbol[100];
+ ObjectFile instance;
+
+ if (strlen(dll0) > 996-strlen(installDir)) {
+ ERRMSG(line) "Excessively long library name:\n%s\n",dll0
+ EEND;
+ }
+ dll[0] = 0;
+ if (strcmp("nHandle",dll0)==0) strcat(dll,installDir);
+ strcat(dll,dll0);
+ strcat(dll, ".dll");
+
+ if (strlen(symbol0) > 96) {
+ ERRMSG(line) "Excessively long symbol name:\n%s\n",symbol0
+ EEND;
+ }
+ strcpy(&(symbol[1]),symbol0);
+ symbol[0] = '_';
+
+ instance = LoadLibrary(dll);
+ if (NULL == instance) {
+ /* GetLastError allegedly provides more detail - in practice,
+ * it tells you nothing more.
+ */
+ ERRMSG(line) "Can't open library \"%s\"", dll
+ EEND;
+ }
+ sym = GetProcAddress(instance,symbol0);
+ return sym;