Back to index

plt-scheme  4.2.1
delayed.inc
Go to the documentation of this file.
00001 
00002 # ifdef MZ_PRECISE_GC
00003 #  define DLL_3M_SUFFIX "3m"
00004 # else
00005 #  define DLL_3M_SUFFIX ""
00006 # endif
00007 static wchar_t *_dlldir = L"dLl dIRECTORy:" /* <- this tag stays, so we can find it again */
00008                           DLL_RELATIVE_PATH L"\0"
00009                           /* Pad with 512 characters: */
00010                           L"****************************************************************"
00011                           L"****************************************************************"
00012                           L"****************************************************************"
00013                           L"****************************************************************"
00014                           L"****************************************************************"
00015                           L"****************************************************************"
00016                           L"****************************************************************"
00017                           L"****************************************************************";
00018 static int _dlldir_offset = 14; /* Skip permanent tag */
00019 
00020 # ifdef MZ_PRECISE_GC
00021 START_XFORM_SKIP;
00022 # endif
00023 
00024 static void load_delayed_dll(HINSTANCE me, char *lib) 
00025 {
00026   /* Don't use the C library here! */
00027   wchar_t *dlldir = _dlldir + _dlldir_offset;
00028 
00029   if (dlldir[0] != '<') {
00030     if ((dlldir[0] == '\\')
00031        || ((((dlldir[0] >= 'a') && (dlldir[0] <= 'z'))
00032             || ((dlldir[0] >= 'A') && (dlldir[0] <= 'Z')))
00033            && (dlldir[1] == ':'))) {
00034       /* Absolute path */
00035     } else {
00036       /* Make it absolute, relative to this module */
00037       wchar_t *name, *s;
00038       int j, i;
00039       name = (wchar_t *)GlobalAlloc(GMEM_FIXED, 1024 * sizeof(wchar_t));
00040       GetModuleFileNameW(me, name, 1024);
00041       name[1023] = 0;
00042       s = (wchar_t *)GlobalAlloc(GMEM_FIXED, 2048 * sizeof(wchar_t));
00043       for (i = 0; name[i]; i++) { }
00044       --i;
00045       while (i && (name[i] != '\\')) {
00046        --i;
00047       }
00048       name[i+1] = 0;
00049       for (i = 0; name[i]; i++) {
00050        s[i] = name[i];
00051       }
00052       for (j = 0; dlldir[j]; j++, i++) {
00053        s[i] = dlldir[j];
00054       }
00055       s[i] = 0;
00056       dlldir = s;
00057       _dlldir = s;
00058       _dlldir_offset = 0;
00059     }
00060 
00061     {
00062       wchar_t *t;
00063       int j, i;
00064 
00065       t = (wchar_t *)GlobalAlloc(GMEM_FIXED, 2048 * sizeof(wchar_t));
00066       for (i = 0; dlldir[i]; i++) {
00067        t[i] = dlldir[i];
00068       }
00069       if (t[i-1] != '\\')
00070        t[i++] = '\\';
00071       for (j = 0; lib[j]; j++, i++) {
00072        t[i] = lib[j];
00073       }
00074       t[i] = 0;
00075 
00076       if (!LoadLibraryW(t)) {
00077        MessageBoxW(NULL, t, L"Failure: cannot load DLL", MB_OK);
00078        ExitProcess(1);
00079       }
00080     }
00081   }
00082 }