Index: trunk/src/kernel32/dbglocal.cpp
===================================================================
--- trunk/src/kernel32/dbglocal.cpp	(revision 4473)
+++ trunk/src/kernel32/dbglocal.cpp	(revision 4474)
@@ -1,3 +1,3 @@
-/* $Id: dbglocal.cpp,v 1.11 2000-10-02 13:38:55 sandervl Exp $ */
+/* $Id: dbglocal.cpp,v 1.12 2000-10-10 17:14:02 sandervl Exp $ */
 
 /*
@@ -98,5 +98,4 @@
 "cvtbitmap",
 "hmmmap",
-"winfakepeldr",
 "cvtaccel",
 "cvticon",
Index: trunk/src/kernel32/dbglocal.h
===================================================================
--- trunk/src/kernel32/dbglocal.h	(revision 4473)
+++ trunk/src/kernel32/dbglocal.h	(revision 4474)
@@ -1,3 +1,3 @@
-/* $Id: dbglocal.h,v 1.11 2000-10-02 13:38:56 sandervl Exp $ */
+/* $Id: dbglocal.h,v 1.12 2000-10-10 17:14:03 sandervl Exp $ */
 
 /*
@@ -97,30 +97,29 @@
 #define DBG_cvtbitmap      75
 #define DBG_hmmmap         76
-#define DBG_winfakepeldr   77
-#define DBG_cvtaccel       78
-#define DBG_cvticon        79
-#define DBG_cvticongrp     80
-#define DBG_oslibexcept    81
-#define DBG_cpu            82
-#define DBG_process        83
-#define DBG_cvtcursor      84
-#define DBG_cvtcursorgrp   85
-#define DBG_stubs          86
-#define DBG_interlock      87
-#define DBG_toolhelp       88
-#define DBG_codepage       89
-#define DBG_debug          90
-#define DBG_oslibdebug     91
-#define DBG_registry       92
-#define DBG_queue          93
-#define DBG_hmthread       94
-#define DBG_hmprocess      95
-#define DBG_VSemaphore     96
-#define DBG_exceptstackdump 97
-#define DBG_hmfile         98
-#define DBG_hmnpipe        99
-#define DBG_hmdisk         100
-#define DBG_version        101
-#define DBG_MAXFILES       102
+#define DBG_cvtaccel       77
+#define DBG_cvticon        78
+#define DBG_cvticongrp     79
+#define DBG_oslibexcept    80
+#define DBG_cpu            81
+#define DBG_process        82
+#define DBG_cvtcursor      83
+#define DBG_cvtcursorgrp   84
+#define DBG_stubs          85
+#define DBG_interlock      86
+#define DBG_toolhelp       87
+#define DBG_codepage       88
+#define DBG_debug          89
+#define DBG_oslibdebug     90
+#define DBG_registry       91
+#define DBG_queue          92
+#define DBG_hmthread       93
+#define DBG_hmprocess      94
+#define DBG_VSemaphore     95
+#define DBG_exceptstackdump 96
+#define DBG_hmfile         97
+#define DBG_hmnpipe        98
+#define DBG_hmdisk         99
+#define DBG_version        100
+#define DBG_MAXFILES       101
 
 extern USHORT DbgEnabled[DBG_MAXFILES];
Index: trunk/src/kernel32/hmfile.cpp
===================================================================
--- trunk/src/kernel32/hmfile.cpp	(revision 4473)
+++ trunk/src/kernel32/hmfile.cpp	(revision 4474)
@@ -1,3 +1,3 @@
-/* $Id: hmfile.cpp,v 1.21 2000-09-13 21:10:59 sandervl Exp $ */
+/* $Id: hmfile.cpp,v 1.22 2000-10-10 17:14:03 sandervl Exp $ */
 
 /*
@@ -597,4 +597,9 @@
 //  }
 
+//testestest!!!!
+    dprintf(("%s", lpRealBuf));
+//testestest!!!!
+
+
   dprintf(("KERNEL32: HMDeviceFileClass::WriteFile returned %08xh\n",
            bRC));
Index: trunk/src/kernel32/initsystem.cpp
===================================================================
--- trunk/src/kernel32/initsystem.cpp	(revision 4473)
+++ trunk/src/kernel32/initsystem.cpp	(revision 4474)
@@ -1,3 +1,3 @@
-/* $Id: initsystem.cpp,v 1.17 2000-10-03 17:28:30 sandervl Exp $ */
+/* $Id: initsystem.cpp,v 1.18 2000-10-10 17:14:04 sandervl Exp $ */
 /*
  * Odin system initialization (registry, directories & environment)
@@ -7,4 +7,5 @@
  *
  * InitSystemAndRegistry creates:
+ *      - SYSTEMDIR\drivers
  *	- WINDOWSDIR\SYSTEM
  *      - WINDOWSDIR\AppData
@@ -192,4 +193,9 @@
 //   if(RegOpenKeyA(HKEY_CURRENT_USER, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", &hkey) != ERROR_SUCCESS) 
 //   {
+        //system32\drivers dir
+   	strcpy(shellpath, InternalGetSystemDirectoryA());
+   	strcat(shellpath, "\\Drivers");
+   	CreateDirectoryA(shellpath, NULL);
+
 	//SYSTEM dir
    	strcpy(shellpath, InternalGetWindowsDirectoryA());
Index: trunk/src/kernel32/initterm.cpp
===================================================================
--- trunk/src/kernel32/initterm.cpp	(revision 4473)
+++ trunk/src/kernel32/initterm.cpp	(revision 4474)
@@ -1,3 +1,3 @@
-/* $Id: initterm.cpp,v 1.47 2000-10-02 21:40:57 phaller Exp $ */
+/* $Id: initterm.cpp,v 1.48 2000-10-10 17:14:04 sandervl Exp $ */
 
 /*
@@ -120,5 +120,5 @@
             char *endofpath = strrchr(kernel32Path, '\\');
             *(endofpath+1) = 0;
-            dprintf(("kernel32 init\n"));
+            dprintf(("kernel32 init %s %s", __DATE__, __TIME__));
             _ctordtorInit();
 
Index: trunk/src/kernel32/makefile
===================================================================
--- trunk/src/kernel32/makefile	(revision 4473)
+++ trunk/src/kernel32/makefile	(revision 4474)
@@ -1,3 +1,3 @@
-# $Id: makefile,v 1.102 2000-10-02 13:38:56 sandervl Exp $
+# $Id: makefile,v 1.103 2000-10-10 17:14:04 sandervl Exp $
 
 #
@@ -107,5 +107,4 @@
 $(OBJDIR)\cvtbitmap.obj \
 $(OBJDIR)\hmmmap.obj \
-$(OBJDIR)\winfakepeldr.obj \
 $(OBJDIR)\cvtaccel.obj \
 $(OBJDIR)\cvticon.obj \
Index: trunk/src/kernel32/oslibdos.cpp
===================================================================
--- trunk/src/kernel32/oslibdos.cpp	(revision 4473)
+++ trunk/src/kernel32/oslibdos.cpp	(revision 4474)
@@ -1,3 +1,3 @@
-/* $Id: oslibdos.cpp,v 1.48 2000-10-09 22:51:18 sandervl Exp $ */
+/* $Id: oslibdos.cpp,v 1.49 2000-10-10 17:14:04 sandervl Exp $ */
 /*
  * Wrappers for OS/2 Dos* API
@@ -1744,7 +1744,8 @@
         DosFindClose(hDir);
         SetLastError(error2WinError(rc));
-  return INVALID_HANDLE_VALUE_W;
+        return INVALID_HANDLE_VALUE_W;
   }
   translateFindResults(&result,lpFindFileData);
+  SetLastError(ERROR_SUCCESS_W);
   return hDir;
 }
@@ -1783,4 +1784,5 @@
   *count = searchCount;
 
+  SetLastError(ERROR_SUCCESS_W);
   return hDir;
 }
@@ -1801,5 +1803,5 @@
 
   translateFindResults(&result,lpFindFileData);
-
+  SetLastError(ERROR_SUCCESS_W);
   return TRUE;
 }
@@ -1831,4 +1833,5 @@
   *count = searchCount;
 
+  SetLastError(ERROR_SUCCESS_W);
   return TRUE;
 }
@@ -1841,8 +1844,8 @@
   {
     SetLastError(error2WinError(rc));
-
     return FALSE;
   }
 
+  SetLastError(ERROR_SUCCESS_W);
   return TRUE;
 }
@@ -1859,6 +1862,6 @@
 
    if(lpFileSystemNameBuffer == NULL) {
-  DebugInt3();
-  return ERROR_INVALID_PARAMETER_W;
+        DebugInt3();
+        return ERROR_INVALID_PARAMETER_W;
    }
    drv[0] = (char)('A' + drive - 1);
@@ -1870,11 +1873,11 @@
    switch(rc) {
    case ERROR_INVALID_DRIVE:
-  return ERROR_INVALID_DRIVE_W;
+        return ERROR_INVALID_DRIVE_W;
    case ERROR_NO_VOLUME_LABEL:
-  return ERROR_NO_VOLUME_LABEL_W;
+        return ERROR_NO_VOLUME_LABEL_W;
    case NO_ERROR:
-  break;
+        break;
    default:
-  return ERROR_NOT_ENOUGH_MEMORY; //whatever
+        return ERROR_NOT_ENOUGH_MEMORY; //whatever
    }
 
@@ -1889,5 +1892,5 @@
   /*
    if(strlen(fsname) < nFileSystemNameSize) {
-  strcpy(lpFileSystemNameBuffer, fsname);
+        strcpy(lpFileSystemNameBuffer, fsname);
    }
    else return ERROR_BUFFER_OVERFLOW_W;
@@ -2000,4 +2003,5 @@
     return -1; // INVALID_HANDLE_VALUE
   }
+  SetLastError(ERROR_SUCCESS_W);
   return NO_ERROR;
 }
@@ -2075,4 +2079,6 @@
    }
    else len += 3;   // + 3 since DosQueryCurDir doesn't include drive
+
+   SetLastError(ERROR_SUCCESS_W);
    return len;
 }
Index: trunk/src/kernel32/windllbase.cpp
===================================================================
--- trunk/src/kernel32/windllbase.cpp	(revision 4473)
+++ trunk/src/kernel32/windllbase.cpp	(revision 4474)
@@ -1,3 +1,3 @@
-/* $Id: windllbase.cpp,v 1.17 2000-10-02 18:39:36 sandervl Exp $ */
+/* $Id: windllbase.cpp,v 1.18 2000-10-10 17:14:06 sandervl Exp $ */
 
 /*
@@ -53,5 +53,5 @@
   	           referenced(0), fSkipThreadEntryCalls(FALSE), next(NULL), fInserted(FALSE),
                    fAttachedToProcess(FALSE), fUnloaded(FALSE), 
-                   nrDynamicLibRef(0), fDisableUnload(FALSE)
+                   nrDynamicLibRef(0), fDisableUnload(FALSE), fSkipEntryCalls(FALSE)
 {
   dllEntryPoint = DllEntryPoint;
@@ -395,5 +395,5 @@
  BOOL rc, fSetExceptionHandler;
 
-  if(fAttachedToProcess)
+  if(fAttachedToProcess || fSkipEntryCalls)
 	return TRUE;
 
@@ -460,4 +460,9 @@
  USHORT sel;
  BOOL rc;
+
+  if(fSkipEntryCalls) {
+	fUnloaded = TRUE;
+	return TRUE;
+  }
 
   if(dllEntryPoint == NULL) {
Index: trunk/src/kernel32/windllbase.h
===================================================================
--- trunk/src/kernel32/windllbase.h	(revision 4473)
+++ trunk/src/kernel32/windllbase.h	(revision 4474)
@@ -1,3 +1,3 @@
-/* $Id: windllbase.h,v 1.5 2000-08-11 10:56:18 sandervl Exp $ */
+/* $Id: windllbase.h,v 1.6 2000-10-10 17:14:06 sandervl Exp $ */
 
 /*
@@ -53,4 +53,5 @@
         //do not call the ATTACH_THREAD, DETACH_THREAD functions
 	void      disableThreadLibraryCalls()  { fSkipThreadEntryCalls = TRUE; };
+	void      disableLibraryCalls()        { fSkipEntryCalls = fSkipThreadEntryCalls = TRUE; };
 
 	Win32DllBase *getNext()  { return next; };
@@ -114,5 +115,5 @@
 #endif
 
-	BOOL          fSkipThreadEntryCalls, fUnloaded, fAttachedToProcess;
+	BOOL          fSkipThreadEntryCalls, fUnloaded, fAttachedToProcess, fSkipEntryCalls;
 
 	WIN32DLLENTRY dllEntryPoint;
Index: trunk/src/kernel32/winfakepeldr.cpp
===================================================================
--- trunk/src/kernel32/winfakepeldr.cpp	(revision 4473)
+++ 	(revision )
@@ -1,67 +1,0 @@
-/* $Id: winfakepeldr.cpp,v 1.4 2000-02-16 14:22:12 sandervl Exp $ */
-
-/*
- * Win32 PE loader fake image class (RSRC_LOAD)
- *
- * Copyright 1999 Sander van Leeuwen (sandervl@xs4all.nl)
- *
- *
- * Project Odin Software License can be found in LICENSE.TXT
- *
- * NOTE: RSRC_LOAD is a special flag to only load the resource directory
- *       of a PE image. Processing imports, sections etc is not done.
- *       Nor is it put into the linked list of dlls (if it's a dll).
- *       This is useful for GetVersionSize/Resource in case it wants to
- *       get version info of an image that is not loaded.
- *       So an instance of this type can't be used for anything but resource lookup!
- */
-#define INCL_DOSFILEMGR          /* File Manager values      */
-#define INCL_DOSMODULEMGR
-#define INCL_DOSERRORS           /* DOS Error values         */
-#define INCL_DOSPROCESS          /* DOS Process values       */
-#define INCL_DOSMISC             /* DOS Miscellanous values  */
-#define INCL_WIN
-#define INCL_BASE
-#include <os2wrap.h>             //Odin32 OS/2 api wrappers
-
-#include <misc.h>
-#include <win32type.h>
-#include <winfakepeldr.h>
-
-#define DBG_LOCALLOG	DBG_winfakepeldr
-#include "dbglocal.h"
-
-//******************************************************************************
-//******************************************************************************
-Win32PeLdrRsrcImg::Win32PeLdrRsrcImg(char *szFileName) 
-                        : Win32ImageBase(-1), 
-                          Win32PeLdrImage(szFileName, FALSE, RSRC_LOAD)
-{
-}
-//******************************************************************************
-//******************************************************************************
-Win32PeLdrRsrcImg::~Win32PeLdrRsrcImg()
-{
-}
-//******************************************************************************
-//******************************************************************************
-BOOL Win32PeLdrRsrcImg::isDll()
-{
-   return FALSE;
-}
-//******************************************************************************
-//******************************************************************************
-ULONG Win32PeLdrRsrcImg::getApi(char *name)
-{
-   DebugInt3();
-   return 0;
-}
-//******************************************************************************
-//******************************************************************************
-ULONG Win32PeLdrRsrcImg::getApi(int ordinal)
-{
-   DebugInt3();
-   return 0;
-}
-//******************************************************************************
-//******************************************************************************
Index: trunk/src/kernel32/winfakepeldr.h
===================================================================
--- trunk/src/kernel32/winfakepeldr.h	(revision 4473)
+++ 	(revision )
@@ -1,33 +1,0 @@
-/* $Id: winfakepeldr.h,v 1.1 2000-03-10 16:12:02 sandervl Exp $ */
-
-/*
- * Win32 PE loader fake image class (RSRC_LOAD)
- *
- * Copyright 1999 Sander van Leeuwen (sandervl@xs4all.nl)
- *
- *
- * Project Odin Software License can be found in LICENSE.TXT
- *
- */
-#ifndef __WINFAKEPELDR_H__
-#define __WINFAKEPELDR_H__
-
-#include <winimagepeldr.h>
-
-//Class for images that are loaded for only retrieving their resources
-class Win32PeLdrRsrcImg : public Win32PeLdrImage
-{
-public:
-	Win32PeLdrRsrcImg(char *szFileName);
-virtual ~Win32PeLdrRsrcImg();
-
-virtual	ULONG     getApi(char *name);
-virtual ULONG     getApi(int ordinal);
-
-virtual BOOL  isDll();
-
-protected:
-private:
-};
-
-#endif //__WINFAKEPELDR_H__
Index: trunk/src/kernel32/winimagebase.cpp
===================================================================
--- trunk/src/kernel32/winimagebase.cpp	(revision 4473)
+++ trunk/src/kernel32/winimagebase.cpp	(revision 4474)
@@ -1,3 +1,3 @@
-/* $Id: winimagebase.cpp,v 1.28 2000-10-06 11:04:02 sandervl Exp $ */
+/* $Id: winimagebase.cpp,v 1.29 2000-10-10 17:14:07 sandervl Exp $ */
 
 /*
@@ -202,7 +202,8 @@
 
 //******************************************************************************
-//returns ERROR_SUCCESS or error code
-//******************************************************************************
-ULONG Win32ImageBase::isPEImage(char *szFileName)
+//returns ERROR_SUCCESS or error code (Characteristics will contain
+//the Characteristics member of the file header structure)
+//******************************************************************************
+ULONG Win32ImageBase::isPEImage(char *szFileName, DWORD *Characteristics)
 {
  char   filename[CCHMAXPATH];
@@ -291,4 +292,7 @@
   if(fh.Characteristics & IMAGE_FILE_SYSTEM) {
         goto failure;
+  }
+  if(Characteristics) {
+	*Characteristics = fh.Characteristics;
   }
   DosClose(win32handle);
Index: trunk/src/kernel32/winimagebase.h
===================================================================
--- trunk/src/kernel32/winimagebase.h	(revision 4473)
+++ trunk/src/kernel32/winimagebase.h	(revision 4474)
@@ -1,3 +1,3 @@
-/* $Id: winimagebase.h,v 1.16 2000-09-12 22:45:19 bird Exp $ */
+/* $Id: winimagebase.h,v 1.17 2000-10-10 17:14:07 sandervl Exp $ */
 
 /*
@@ -95,6 +95,7 @@
     ULONG getResourceSize(HRSRC hResource);
 
-    //returns ERROR_SUCCESS or error code
-static  ULONG isPEImage(char *szFileName);
+//returns ERROR_SUCCESS or error code (Characteristics will contain
+//the Characteristics member of the file header structure)
+static  ULONG isPEImage(char *szFileName, DWORD *Characteristics = NULL);
 static  BOOL  findDll(const char *pszFileName, char *pszFullName,
                       int cchFullName, const char *pszAltPath = NULL);
Index: trunk/src/kernel32/winimagepeldr.cpp
===================================================================
--- trunk/src/kernel32/winimagepeldr.cpp	(revision 4473)
+++ trunk/src/kernel32/winimagepeldr.cpp	(revision 4474)
@@ -1,3 +1,3 @@
-/* $Id: winimagepeldr.cpp,v 1.59 2000-10-09 18:35:26 sandervl Exp $ */
+/* $Id: winimagepeldr.cpp,v 1.60 2000-10-10 17:14:08 sandervl Exp $ */
 
 /*
@@ -14,7 +14,6 @@
  *       (circular dependencies; have to check what NT does)
  *
- * NOTE: RSRC_LOAD is a special flag to only load the resource directory
+ * NOTE: FLAG_PELDR_LOADASDATAFILE is a special flag to only load the resource directory
  *       of a PE image. Processing imports, sections etc is not done.
- *       Nor is it put into the linked list of dlls (if it's a dll).
  *       This is useful for GetVersionSize/Resource in case it wants to
  *       get version info of an image that is not loaded.
@@ -103,7 +102,7 @@
 //******************************************************************************
 //******************************************************************************
-Win32PeLdrImage::Win32PeLdrImage(char *pszFileName, BOOL isExe, int loadtype) :
+Win32PeLdrImage::Win32PeLdrImage(char *pszFileName, BOOL isExe) :
     Win32ImageBase(-1),
-    nrsections(0), imageSize(0),
+    nrsections(0), imageSize(0), dwFlags(0),
     imageVirtBase(-1), realBaseAddress(0), imageVirtEnd(0),
     nrNameExports(0), nrOrdExports(0), nameexports(NULL), ordexports(NULL),
@@ -111,6 +110,4 @@
 {
  HFILE  dllfile;
-
-  loadType = loadtype;
 
   strcpy(szFileName, pszFileName);
@@ -282,5 +279,5 @@
   nSections = NR_SECTIONS(win32file);
 
-  if(loadType == REAL_LOAD)
+  if(!(dwFlags & FLAG_PELDR_LOADASDATAFILE))
   {
    imageSize = 0;
@@ -307,9 +304,13 @@
 	if(IsSectionType(win32file, &psh[i], IMAGE_DIRECTORY_ENTRY_EXPORT)) 
         {
-            dprintf((LOG, ".edata" ));
-            addSection(SECTION_EXPORT, psh[i].PointerToRawData,
-                   psh[i].SizeOfRawData, psh[i].VirtualAddress + oh.ImageBase,
-                   psh[i].Misc.VirtualSize, psh[i].Characteristics);
-            continue;
+            //SvL: Angus.exe has empty export section that's really an
+            //     uninitialized data section
+            if(psh[i].SizeOfRawData) {
+                 dprintf((LOG, ".edata" ));
+                 addSection(SECTION_EXPORT, psh[i].PointerToRawData,
+                      psh[i].SizeOfRawData, psh[i].VirtualAddress + oh.ImageBase,
+                      psh[i].Misc.VirtualSize, psh[i].Characteristics);
+                 continue;
+            }
         }
 	if(IsSectionType(win32file, &psh[i], IMAGE_DIRECTORY_ENTRY_RESOURCE)) 
@@ -439,5 +440,5 @@
   }
 
-  if(loadType == REAL_LOAD)
+  if(!(dwFlags & FLAG_PELDR_LOADASDATAFILE))
   {
    if(tlsDir = (IMAGE_TLS_DIRECTORY *)ImageDirectoryOffset(win32file, IMAGE_DIRECTORY_ENTRY_TLS)) 
@@ -554,13 +555,13 @@
   }
 
-  if (loadType == REAL_LOAD)
+  if(!(dwFlags & (FLAG_PELDR_LOADASDATAFILE | FLAG_PELDR_SKIPIMPORTS)))
   {
-   if(processImports((char *)win32file) == FALSE) {
-    	dprintf((LOG, "Failed to process imports!" ));
-     	goto failure;
-   }
-  }
-
+        if(processImports((char *)win32file) == FALSE) {
+             dprintf((LOG, "Failed to process imports!" ));
+             goto failure;
+        }
+  }
   return(TRUE);
+
 failure:
   if(memmap) {
@@ -730,5 +731,5 @@
 
   //SvL: We don't care where the image is loaded for resource lookup
-  if(fh.Characteristics & IMAGE_FILE_RELOCS_STRIPPED && loadType == REAL_LOAD) {
+  if(fh.Characteristics & IMAGE_FILE_RELOCS_STRIPPED && !(dwFlags & FLAG_PELDR_LOADASDATAFILE)) {
     	return allocFixedMem(reservedMem);
   }
@@ -898,8 +899,15 @@
 
         case SECTION_READONLYDATA:
+        case SECTION_EXPORT:
         default:
             	section[i].pageflags = PAG_READ;
             	break;
     	}
+	if(section[i].flags & (IMAGE_SCN_CNT_INITIALIZED_DATA|IMAGE_SCN_CNT_UNINITIALIZED_DATA)) {
+		//SvL: sometimes i.e. import/export sections also contain data
+                //     must make them read/write
+            	section[i].pageflags = PAG_WRITE;
+        }
+
   }
   return(TRUE);
@@ -1486,5 +1494,7 @@
   {
     dprintf((LOG, "Module %s", pszCurModule ));
-    dprintf((LOG, "ForwarderChain: %x", pID[i].ForwarderChain));
+    if(pID[i].ForwarderChain) {
+        dprintf((LOG, "ForwarderChain: %x", pID[i].ForwarderChain));
+    }
     //  a) check that OriginalFirstThunk not is 0 and look for Borland-styled PE
     if (i == 0)
Index: trunk/src/kernel32/winimagepeldr.h
===================================================================
--- trunk/src/kernel32/winimagepeldr.h	(revision 4473)
+++ trunk/src/kernel32/winimagepeldr.h	(revision 4474)
@@ -1,3 +1,3 @@
-/* $Id: winimagepeldr.h,v 1.5 2000-10-04 19:36:25 sandervl Exp $ */
+/* $Id: winimagepeldr.h,v 1.6 2000-10-10 17:14:09 sandervl Exp $ */
 
 /*
@@ -22,6 +22,6 @@
 
 //SvL: To load a dll/exe for i.e. getting a single resource (GetVersionSize/Resource)
-#define REAL_LOAD		0
-#define RSRC_LOAD		1
+#define FLAG_PELDR_LOADASDATAFILE	1  //also implies FLAG_PELDR_SKIPIMPORTS
+#define FLAG_PELDR_SKIPIMPORTS		2
 
 //SvL: Amount of memory the peldr dll reserves for win32 exes without fixups
@@ -75,5 +75,5 @@
 {
 public:
-         Win32PeLdrImage(char *szFileName, BOOL isExe, int loadtype = REAL_LOAD);
+         Win32PeLdrImage(char *szFileName, BOOL isExe);
 virtual ~Win32PeLdrImage();
 
@@ -93,4 +93,8 @@
     //Returns required OS version for this image
     virtual ULONG getVersion();
+
+        //tell loader to only process resources and ignore the rest
+        void  setLoadAsDataFile()     { dwFlags |= FLAG_PELDR_LOADASDATAFILE; };
+        void  disableImportHandling() { dwFlags |= FLAG_PELDR_SKIPIMPORTS; };
 
         //commits image page(s) when an access violation exception is dispatched
@@ -137,5 +141,6 @@
         Section               section[MAX_SECTION];
 
-	ULONG                 loadType;
+        //internal flags (see FLAGS_PELDR_*)
+	DWORD                 dwFlags;
 
 	HFILE                 hFile;
Index: trunk/src/kernel32/wprocess.cpp
===================================================================
--- trunk/src/kernel32/wprocess.cpp	(revision 4473)
+++ trunk/src/kernel32/wprocess.cpp	(revision 4474)
@@ -1,3 +1,3 @@
-/* $Id: wprocess.cpp,v 1.102 2000-10-06 15:16:07 sandervl Exp $ */
+/* $Id: wprocess.cpp,v 1.103 2000-10-10 17:14:09 sandervl Exp $ */
 
 /*
@@ -9,4 +9,7 @@
  * NOTE: Even though Odin32 OS/2 apps don't switch FS selectors,
  *       we still allocate a TEB to store misc information.
+ *
+ * TODO: What happens when a dll is first loaded as LOAD_LIBRARY_AS_DATAFILE
+ *       and then for real? (first one not freed of course)
  *
  * Project Odin Software License can be found in LICENSE.TXT
@@ -25,5 +28,4 @@
 #include "windllpeldr.h"
 #include "winexepeldr.h"
-#include "winfakepeldr.h"
 #include "windlllx.h"
 #include <vmutex.h>
@@ -443,4 +445,5 @@
  BOOL rc;
 
+    SetLastError(ERROR_SUCCESS);
     //SvL: Ignore FreeLibary for executable
     if(WinExe && hinstance == WinExe->getInstanceHandle()) {
@@ -633,5 +636,4 @@
  *                      by the module).
  *
- *                  partially implemented yet - imports are resolved it seems.
  *
  *                  LOAD_LIBRARY_AS_DATAFILE
@@ -648,5 +650,4 @@
  *                      LoadCursor, LoadIcon, LoadImage, LoadMenu.)
  *
- *                  not implemented yet.
  *
  *                  LOAD_WITH_ALTERED_SEARCH_PATH
@@ -677,4 +678,5 @@
                                         /* lpszLibFile contains a path. */
     ULONG           fPE;                /* isPEImage return value. */
+    DWORD           Characteristics;    //file header's Characteristics
 
     /** @sketch
@@ -720,4 +722,5 @@
     if (WinExe != NULL && WinExe->matchModName(lpszLibFile))
         return WinExe->getInstanceHandle();
+
     pModule = Win32DllBase::findModule((LPSTR)lpszLibFile);
     if (pModule)
@@ -760,5 +763,5 @@
 
     //test if dll is in PE or LX format
-    fPE = Win32ImageBase::isPEImage(szModname);
+    fPE = Win32ImageBase::isPEImage(szModname, &Characteristics);
 
     /** @sketch
@@ -785,5 +788,4 @@
             if(pModule)
             {
-
                 if(pModule->isLxDll())
                 {
@@ -829,15 +831,11 @@
     if(fPE == ERROR_SUCCESS)
     {
-        Win32PeLdrDll * peldrDll;
-        /* TODO!
-         * We might use the fake loader class to do the LOAD_LIBRARY_AS_DATAFILE and
-         * executable image loading. These are both loaded for accessing resource.
-         * But this requires that they behaves like Dlls...
-        if (dwFlags & LOAD_LIBRARY_AS_DATAFILE || fPE == 2)
-        {
-            peldrDll = new Win32PeLdrRsrcImg(szModname);
-        }
-        else
-        */
+        Win32PeLdrDll *peldrDll;
+
+        //SvL: If executable -> load as data file (only resources)
+        if(!(Characteristics & IMAGE_FILE_DLL))
+        {
+            dwFlags |= (LOAD_LIBRARY_AS_DATAFILE | DONT_RESOLVE_DLL_REFERENCES);
+        }
 
         peldrDll = new Win32PeLdrDll(szModname);
@@ -853,8 +851,17 @@
          * Process dwFlags
          */
-        if (dwFlags & (DONT_RESOLVE_DLL_REFERENCES | LOAD_LIBRARY_AS_DATAFILE))
-        {
-            peldrDll->disableThreadLibraryCalls();
-            //peldrDll->setDontProcessImports(); not implemented?
+        if (dwFlags & LOAD_LIBRARY_AS_DATAFILE) 
+        {
+            dprintf(("KERNEL32: LoadLibraryExA(%s, 0x%x, 0x%x): LOAD_LIBRARY_AS_DATAFILE",
+                      lpszLibFile, hFile, dwFlags));
+            peldrDll->setLoadAsDataFile();
+       	    peldrDll->disableLibraryCalls();
+        }
+        if (dwFlags & DONT_RESOLVE_DLL_REFERENCES)
+        {
+            dprintf(("KERNEL32: LoadLibraryExA(%s, 0x%x, 0x%x): DONT_RESOLVE_DLL_REFERENCES",
+                      lpszLibFile, hFile, dwFlags));
+       	    peldrDll->disableLibraryCalls();
+            peldrDll->disableImportHandling();
         }
         if (dwFlags & LOAD_WITH_ALTERED_SEARCH_PATH)
@@ -863,10 +870,4 @@
                       lpszLibFile, hFile, dwFlags));
             //peldrDll->setLoadWithAlteredSearchPath();
-        }
-        if (dwFlags & LOAD_LIBRARY_AS_DATAFILE)
-        {
-            dprintf(("KERNEL32: LoadLibraryExA(%s, 0x%x, 0x%x): Warning dwFlags LOAD_LIBRARY_AS_DATAFILE is not implemented.",
-                     lpszLibFile, hFile, dwFlags));
-            //peldrDll->setLoadAsDatafile();
         }
 
@@ -918,5 +919,5 @@
             SetLastError(ERROR_INVALID_EXE_SIGNATURE);
             delete peldrDll;
-		return NULL;
+	    return NULL;
         }
     }
@@ -1812,7 +1813,68 @@
 {
  Win32ImageBase *winimage;
- Win32PeLdrRsrcImg *rsrcimg;
-
-  dprintf(("GetVersionStruct of module %s", lpszModName));
+ HINSTANCE hDll;
+
+  dprintf(("GetVersionStruct of module %s %x %d", lpszModName, verstruct, bufLength));
+  if(verstruct == NULL) {
+	SetLastError(ERROR_INVALID_PARAMETER);
+	return FALSE;
+  }
+  if(WinExe && !stricmp(WinExe->getFullPath(), lpszModName)) 
+  {
+        winimage = (Win32ImageBase *)WinExe;
+  }
+  else 
+  {
+        winimage = (Win32ImageBase *)Win32DllBase::findModule(lpszModName);
+        if(winimage == NULL)
+        {
+          char modname[CCHMAXPATH];
+
+          strcpy(modname, lpszModName);
+          //rename dll if necessary (i.e. OLE32 -> OLE32OS2)
+          Win32DllBase::renameDll(modname);
+
+          if(Win32ImageBase::isPEImage(modname) != ERROR_SUCCESS)
+          {
+            HINSTANCE hInstance;
+
+              //must be an LX dll, just load it (app will probably load it anyway)
+              hInstance = LoadLibraryA(modname);
+              if(hInstance == 0)
+                  return 0;
+
+              winimage = (Win32ImageBase *)Win32DllBase::findModule(hInstance);
+              if(winimage) {
+                   return winimage->getVersionStruct(verstruct, bufLength);
+              }
+   	      dprintf(("GetVersionStruct; just loaded dll %s, but can't find it now!", modname));
+              return 0;
+          }
+          BOOL rc = FALSE;
+
+          hDll = LoadLibraryExA(lpszModName, 0, LOAD_LIBRARY_AS_DATAFILE);
+          if(hDll == 0)
+              return 0;
+
+          winimage = (Win32ImageBase *)Win32DllBase::findModule(lpszModName);
+          if(winimage != NULL) {
+	        rc = winimage->getVersionStruct(verstruct, bufLength);
+	  }
+          else	dprintf(("GetVersionSize; just loaded dll %s, but can't find it now!", lpszModName));
+	  FreeLibrary(hDll);
+          return rc;
+        }
+  }
+  return winimage->getVersionStruct(verstruct, bufLength);
+}
+//******************************************************************************
+//******************************************************************************
+ULONG SYSTEM GetVersionSize(char *lpszModName)
+{
+ Win32ImageBase *winimage;
+ HINSTANCE hDll;
+
+  dprintf(("GetVersionSize of %s\n", lpszModName));
+
   if(WinExe && !stricmp(WinExe->getFullPath(), lpszModName)) {
         winimage = (Win32ImageBase *)WinExe;
@@ -1822,13 +1884,13 @@
         if(winimage == NULL)
         {
-        char modname[CCHMAXPATH];
-
-        strcpy(modname, lpszModName);
-        //rename dll if necessary (i.e. OLE32 -> OLE32OS2)
-        Win32DllBase::renameDll(modname);
-
-        if(Win32ImageBase::isPEImage(modname) != ERROR_SUCCESS)
-        {
-         HINSTANCE hInstance;
+          char modname[CCHMAXPATH];
+
+          strcpy(modname, lpszModName);
+          //rename dll if necessary (i.e. OLE32 -> OLE32OS2)
+          Win32DllBase::renameDll(modname);
+
+          if(Win32ImageBase::isPEImage(modname) != ERROR_SUCCESS)
+          {
+            HINSTANCE hInstance;
 
             //must be an LX dll, just load it (app will probably load it anyway)
@@ -1836,87 +1898,30 @@
             if(hInstance == 0)
                 return 0;
-                winimage = (Win32ImageBase *)Win32DllBase::findModule(hInstance);
-                if(winimage) {
-                return winimage->getVersionStruct(verstruct, bufLength);
-            }
-            return 0;
-        }
-        //SvL: Try to load it
-        rsrcimg = new Win32PeLdrRsrcImg(modname);
-        if(rsrcimg == NULL)
-            return 0;
-
-            rsrcimg->init(0);
-        if(rsrcimg->getError() != NO_ERROR)
-        {
-                dprintf(("GetVersionStruct can't load %s\n", modname));
-            delete rsrcimg;
-                return(FALSE);
-        }
-        BOOL rc = rsrcimg->getVersionStruct(verstruct, bufLength);
-        delete rsrcimg;
-        return rc;
-        }
-  }
-  return winimage->getVersionStruct(verstruct, bufLength);
-}
-//******************************************************************************
-//******************************************************************************
-ULONG SYSTEM GetVersionSize(char *lpszModName)
-{
- Win32ImageBase *winimage;
- Win32PeLdrRsrcImg *rsrcimg;
-
-  dprintf(("GetVersionSize of %s\n", lpszModName));
-
-  if(WinExe && !stricmp(WinExe->getFullPath(), lpszModName)) {
-        winimage = (Win32ImageBase *)WinExe;
-  }
-  else {
-        winimage = (Win32ImageBase *)Win32DllBase::findModule(lpszModName);
-        if(winimage == NULL)
-        {
-     char modname[CCHMAXPATH];
-
-        strcpy(modname, lpszModName);
-        //rename dll if necessary (i.e. OLE32 -> OLE32OS2)
-        Win32DllBase::renameDll(modname);
-
-        if(Win32ImageBase::isPEImage(modname) != ERROR_SUCCESS)
-        {
-         HINSTANCE hInstance;
-
-            //must be an LX dll, just load it (app will probably load it anyway)
-            hInstance = LoadLibraryA(modname);
-            if(hInstance == 0)
-                return 0;
-                winimage = (Win32ImageBase *)Win32DllBase::findModule(hInstance);
-                if(winimage) {
+
+            winimage = (Win32ImageBase *)Win32DllBase::findModule(hInstance);
+            if(winimage) {
                 return winimage->getVersionSize();
             }
+	    dprintf(("GetVersionSize; just loaded dll %s, but can't find it now!", modname));
             return 0;
         }
-
-        //SvL: Try to load it
-        rsrcimg = new Win32PeLdrRsrcImg(modname);
-        if(rsrcimg == NULL)
+        int size = 0;
+
+        hDll = LoadLibraryExA(lpszModName, 0, LOAD_LIBRARY_AS_DATAFILE);
+        if(hDll == 0)
             return 0;
 
-            rsrcimg->init(0);
-        if(rsrcimg->getError() != NO_ERROR)
-        {
-                dprintf(("GetVersionSize can't load %s\n", modname));
-            delete rsrcimg;
-                return(FALSE);
-        }
-        int size = rsrcimg->getVersionSize();
-        delete rsrcimg;
+        winimage = (Win32ImageBase *)Win32DllBase::findModule(lpszModName);
+        if(winimage != NULL) {
+	        size = winimage->getVersionSize();
+	}
+        else	dprintf(("GetVersionSize; just loaded dll %s, but can't find it now!", lpszModName));
+	FreeLibrary(hDll);
         return size;
-        }
+      }
   }
   return winimage->getVersionSize();
 }
 //******************************************************************************
-//TODO:What does this do exactly??
 //******************************************************************************
 ODINFUNCTION1(BOOL,DisableThreadLibraryCalls,HMODULE,hModule)
