[project @ 2000-04-11 11:34:40 by simonmar]
[ghc-hetmet.git] / ghc / interpreter / dynamic.c
index 002bf33..1f37491 100644 (file)
@@ -9,32 +9,44 @@
  * included in the distribution.
  *
  * $RCSfile: dynamic.c,v $
- * $Revision: 1.11 $
- * $Date: 1999/10/28 14:32:06 $
+ * $Revision: 1.15 $
+ * $Date: 2000/03/23 14:54:21 $
  * ------------------------------------------------------------------------*/
 
-#include "prelude.h"
+#include "hugsbasictypes.h"
 #include "storage.h"
 #include "errors.h"
-#include "dynamic.h"
+#include "connect.h"
 
 #if HAVE_WINDOWS_H && !defined(__MSDOS__)
 
 #include <windows.h>
 
-void* getDLLSymbol(line,dll0,symbol)  /* load dll and lookup symbol */
+void* getDLLSymbol(line,dll0,symbol0) /* load dll and lookup symbol */
 Int    line;
 String dll0;
-String symbol; {
+String symbol0; {
     void*      sym;
     char       dll[1000];
+    char       symbol[100];
     ObjectFile instance;
-    if (strlen(dll0) > 996) {
-       ERRMSG(line) "Excessively long library name:\n%s\n",dll
+
+    if (strlen(dll0) > 996-strlen(installDir)) {
+       ERRMSG(line) "Excessively long library name:\n%s\n",dll0
        EEND;
     }
-    strcpy(dll,dll0);
+    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,
@@ -43,7 +55,8 @@ String symbol; {
         ERRMSG(line) "Can't open library \"%s\"", dll
         EEND;
     }
-    return GetProcAddress(instance,symbol);
+    sym = GetProcAddress(instance,symbol0);
+    return sym;
 }
 
 Bool stdcallAllowed ( void )
@@ -68,11 +81,13 @@ String symbol; {
     void*      sym;
     char       dll[1000];
     ObjectFile instance;
-    if (strlen(dll0) > 996) {
-       ERRMSG(line) "Excessively long library name:\n%s\n",dll
+    if (strlen(dll0) > 996-strlen(installDir)) {
+       ERRMSG(line) "Excessively long library name:\n%s\n",dll0
        EEND;
     }
-    strcpy(dll,dll0);
+    dll[0] = 0;
+    if (strcmp("nHandle",dll0)==0) strcat(dll,installDir);
+    strcat(dll,dll0);
     strcat(dll, ".so");
 #ifdef RTLD_NOW
     instance = dlopen(dll,RTLD_NOW);
@@ -114,7 +129,7 @@ String symbol; {
     ObjectFile instance = shl_load(dll,BIND_IMMEDIATE,0L);
     void* r;
     if (NULL == instance) {
-        ERRMSG(line) "Error while importing DLL \"%s\"", dll
+        ERRMSG(line) "Error while importing DLL \"%s\"", dll0
         EEND;
     }
     return (0 == shl_findsym(&instance,symbol,TYPE_PROCEDURE,&r)) ? r : 0;