Index: trunk/src/kernel32/oslibdos.cpp
===================================================================
--- trunk/src/kernel32/oslibdos.cpp	(revision 1841)
+++ trunk/src/kernel32/oslibdos.cpp	(revision 1844)
@@ -1,3 +1,3 @@
-/* $Id: oslibdos.cpp,v 1.9 1999-11-22 20:35:50 sandervl Exp $ */
+/* $Id: oslibdos.cpp,v 1.10 1999-11-26 00:05:18 sandervl Exp $ */
 
 /*
@@ -47,5 +47,6 @@
   if(size != cb) {
 	dprintf(("ERROR: OSLibDosAliasMem: size != cb (%x!=%x)!!!!!!!!", size, cb));
-	return 5;
+	//ignore this and continue return 5;
+	attr = fl; //just use original protection flags (NOT CORRECT)
   }
   attr &= (PAG_READ|PAG_WRITE|PAG_EXECUTE|PAG_GUARD|PAG_DEFAULT);
Index: trunk/src/kernel32/windlllx.cpp
===================================================================
--- trunk/src/kernel32/windlllx.cpp	(revision 1841)
+++ trunk/src/kernel32/windlllx.cpp	(revision 1844)
@@ -1,3 +1,3 @@
-/* $Id: windlllx.cpp,v 1.4 1999-10-23 23:02:17 sandervl Exp $ */
+/* $Id: windlllx.cpp,v 1.5 1999-11-26 00:05:19 sandervl Exp $ */
 
 /*
@@ -114,47 +114,4 @@
 //******************************************************************************
 //******************************************************************************
-ULONG Win32LxDll::getApi(char *name)
-{
-  APIRET      rc;
-  ULONG       apiaddr;
-
-  rc = DosQueryProcAddr(hinstance, 0, name, (PFN *)&apiaddr);
-  if(rc)  
-  {
-	if(rc == ERROR_INVALID_HANDLE) 
-        {//handle invalid for some silly reason, so load module again (initterm entrypoint not called twice)
-		char szErrName[CCHMAXPATH];
-
-		rc = DosLoadModule(szErrName, sizeof(szErrName), szFileName, &hinstance);
-		if(!rc)
-			rc = DosQueryProcAddr(hinstance, 0, name, (PFN *)&apiaddr);
-	}
-	if(rc) 	return(0);
-  }
-  return(apiaddr);
-}
-//******************************************************************************
-//******************************************************************************
-ULONG Win32LxDll::getApi(int ordinal)
-{
- APIRET      rc;
- ULONG       apiaddr;
-
-  rc = DosQueryProcAddr(hinstance, ordinal, NULL, (PFN *)&apiaddr);
-  if(rc) {
-	if(rc == ERROR_INVALID_HANDLE) 
-        {//handle invalid for some silly reason, so load module again (initterm entrypoint not called twice)
-		char szErrName[CCHMAXPATH];
-
-		rc = DosLoadModule(szErrName, sizeof(szErrName), szFileName, &hinstance);
-		if(!rc)
-			rc = DosQueryProcAddr(hinstance, ordinal, NULL, (PFN *)&apiaddr);
-	}
-	if(rc) 	return(0);
-  }
-  return(apiaddr);
-}
-//******************************************************************************
-//******************************************************************************
 BOOL Win32LxDll::isLxDll()
 {
Index: trunk/src/kernel32/windllpe2lx.cpp
===================================================================
--- trunk/src/kernel32/windllpe2lx.cpp	(revision 1841)
+++ trunk/src/kernel32/windllpe2lx.cpp	(revision 1844)
@@ -1,3 +1,3 @@
-/* $Id: windllpe2lx.cpp,v 1.3 1999-10-17 01:49:08 bird Exp $ */
+/* $Id: windllpe2lx.cpp,v 1.4 1999-11-26 00:05:19 sandervl Exp $ */
 
 /*
@@ -168,44 +168,4 @@
 
 /**
- * Gets pointer to an exported procedure by procedure name.
- * @returns   Address of exported procedure. 0UL if not found.
- * @param     name  Exported procedure name.
- * @status    completely implemented.
- * @author    Sander van Leeuwen
- * @remark
- */
-ULONG Win32Pe2LxDll::getApi(char *name)
-{
-    APIRET      rc;
-    ULONG       ulApiAddr;
-
-    rc = DosQueryProcAddr(hinstance, 0, name, (PFN *)&ulApiAddr);
-    return rc == NO_ERROR ? ulApiAddr : 0;
-}
-
-
-/**
- * Gets pointer to an exported procedure by ordinal.
- * @returns   Pointer to an exported procedure. 0UL if not found.
- * @param     ordinal  Export ordinal number.
- * @status    completely implemented.
- * @author    Sander van Leeuwen
- * @remark    FIXME:
- *            This function should be implemented for both Exe and Dll images!
- *            It could be done similar in both peldr image and pe2lx images by
- *            accessing PE structures.
- */
-ULONG Win32Pe2LxDll::getApi(int ordinal)
-{
-    APIRET      rc;
-    ULONG       ulApiAddr;
-
-    rc = DosQueryProcAddr(hinstance, ordinal, NULL, (PFN *)&ulApiAddr);
-
-    return rc == NO_ERROR ? ulApiAddr : 0;
-}
-
-
-/**
  * Simple question: -Native LX dll?
  *                  -No!
Index: trunk/src/kernel32/windllpeldr.cpp
===================================================================
--- trunk/src/kernel32/windllpeldr.cpp	(revision 1841)
+++ trunk/src/kernel32/windllpeldr.cpp	(revision 1844)
@@ -1,3 +1,3 @@
-/* $Id: windllpeldr.cpp,v 1.3 1999-11-24 19:31:23 sandervl Exp $ */
+/* $Id: windllpeldr.cpp,v 1.4 1999-11-26 00:05:19 sandervl Exp $ */
 
 /*
@@ -81,60 +81,4 @@
 //******************************************************************************
 //******************************************************************************
-ULONG Win32PeLdrDll::getApi(char *name)
-{
-  ULONG       apiaddr, i, apilen;
-  char       *apiname;
-  char        tmp[4];
-  NameExport *curexport;
-  ULONG       ulAPIOrdinal;                      /* api requested by ordinal */
-  
-  apilen = strlen(name) + 1;
-  if(apilen < 4) 
-  {
-	*(ULONG *)tmp = 0;
-	strcpy(tmp, name);
-	apiname = tmp;
-  }
-  else	apiname = name;
-
-  curexport = nameexports;
-  for(i=0; i<nrNameExports; i++) 
-  {
-    if(apilen == curexport->nlength && 
-       *(ULONG *)curexport->name == *(ULONG *)name) 
-    {
-      	if(strcmp(curexport->name, name) == 0) 
-        	return(curexport->virtaddr);
-    }
-    curexport = (NameExport *)((ULONG)curexport->name + curexport->nlength);
-  }
-  return(0);
-}
-//******************************************************************************
-//******************************************************************************
-ULONG Win32PeLdrDll::getApi(int ordinal)
-{
- ULONG       apiaddr, i;
- OrdExport  *curexport;
- NameExport *nexport;
-
-  curexport = ordexports;
-  for(i=0;i<nrOrdExports;i++) {
-	if(curexport->ordinal == ordinal)
-		return(curexport->virtaddr);
-	curexport++;
-  }
-  //Name exports also contain an ordinal, so check this 
-  nexport = nameexports;
-  for(i=0;i<nrNameExports;i++) {
-	if(nexport->ordinal == ordinal)
-		return(nexport->virtaddr);
-
-	nexport = (NameExport *)((ULONG)nexport->name + nexport->nlength);
-  }
-  return(0);
-}
-//******************************************************************************
-//******************************************************************************
 BOOL Win32PeLdrDll::isLxDll()
 {
Index: trunk/src/kernel32/winfakepeldr.cpp
===================================================================
--- trunk/src/kernel32/winfakepeldr.cpp	(revision 1841)
+++ trunk/src/kernel32/winfakepeldr.cpp	(revision 1844)
@@ -1,3 +1,3 @@
-/* $Id: winfakepeldr.cpp,v 1.2 1999-11-24 19:31:23 sandervl Exp $ */
+/* $Id: winfakepeldr.cpp,v 1.3 1999-11-26 00:05:19 sandervl Exp $ */
 
 /*
@@ -49,2 +49,16 @@
 //******************************************************************************
 //******************************************************************************
+ULONG Win32PeLdrRsrcImg::getApi(char *name)
+{
+   DebugInt3();
+   return 0;
+}
+//******************************************************************************
+//******************************************************************************
+ULONG Win32PeLdrRsrcImg::getApi(int ordinal)
+{
+   DebugInt3();
+   return 0;
+}
+//******************************************************************************
+//******************************************************************************
Index: trunk/src/kernel32/winimagelx.cpp
===================================================================
--- trunk/src/kernel32/winimagelx.cpp	(revision 1841)
+++ trunk/src/kernel32/winimagelx.cpp	(revision 1844)
@@ -1,3 +1,3 @@
-/* $Id: winimagelx.cpp,v 1.3 1999-10-04 20:52:33 sandervl Exp $ */
+/* $Id: winimagelx.cpp,v 1.4 1999-11-26 00:05:19 sandervl Exp $ */
 
 /*
@@ -68,3 +68,46 @@
 //******************************************************************************
 //******************************************************************************
+ULONG Win32LxImage::getApi(char *name)
+{
+  APIRET      rc;
+  ULONG       apiaddr;
 
+  rc = DosQueryProcAddr(hinstance, 0, name, (PFN *)&apiaddr);
+  if(rc)  
+  {
+	if(rc == ERROR_INVALID_HANDLE) 
+        {//handle invalid for some silly reason, so load module again (initterm entrypoint not called twice)
+		char szErrName[CCHMAXPATH];
+
+		rc = DosLoadModule(szErrName, sizeof(szErrName), szFileName, &hinstance);
+		if(!rc)
+			rc = DosQueryProcAddr(hinstance, 0, name, (PFN *)&apiaddr);
+	}
+	if(rc) 	return(0);
+  }
+  return(apiaddr);
+}
+//******************************************************************************
+//******************************************************************************
+ULONG Win32LxImage::getApi(int ordinal)
+{
+ APIRET      rc;
+ ULONG       apiaddr;
+
+  rc = DosQueryProcAddr(hinstance, ordinal, NULL, (PFN *)&apiaddr);
+  if(rc) {
+	if(rc == ERROR_INVALID_HANDLE) 
+        {//handle invalid for some silly reason, so load module again (initterm entrypoint not called twice)
+		char szErrName[CCHMAXPATH];
+
+		rc = DosLoadModule(szErrName, sizeof(szErrName), szFileName, &hinstance);
+		if(!rc)
+			rc = DosQueryProcAddr(hinstance, ordinal, NULL, (PFN *)&apiaddr);
+	}
+	if(rc) 	return(0);
+  }
+  return(apiaddr);
+}
+//******************************************************************************
+//******************************************************************************
+
Index: trunk/src/kernel32/winimagepe2lx.cpp
===================================================================
--- trunk/src/kernel32/winimagepe2lx.cpp	(revision 1841)
+++ trunk/src/kernel32/winimagepe2lx.cpp	(revision 1844)
@@ -1,3 +1,3 @@
-/* $Id: winimagepe2lx.cpp,v 1.5 1999-11-18 08:55:06 bird Exp $ */
+/* $Id: winimagepe2lx.cpp,v 1.6 1999-11-26 00:05:19 sandervl Exp $ */
 
 /*
@@ -16,4 +16,5 @@
 #define INCL_DOSERRORS          /* DOS Error values */
 #define INCL_DOSPROFILE         /* DosQuerySysState (Toolkit 4.5) */
+#define INCL_DOSMODULEMGR   /* DOS Module management */
 
 #define ALIGN(a, alignment) (((a) + (alignment - 1UL)) & ~(alignment - 1UL))
@@ -524,2 +525,40 @@
 }
 
+/**
+ * Gets pointer to an exported procedure by procedure name.
+ * @returns   Address of exported procedure. 0UL if not found.
+ * @param     name  Exported procedure name.
+ * @status    completely implemented.
+ * @author    Sander van Leeuwen
+ * @remark
+ */
+ULONG Win32Pe2LxImage::getApi(char *name)
+{
+    APIRET      rc;
+    ULONG       ulApiAddr;
+
+    rc = DosQueryProcAddr(hinstance, 0, name, (PFN *)&ulApiAddr);
+    return rc == NO_ERROR ? ulApiAddr : 0;
+}
+
+
+/**
+ * Gets pointer to an exported procedure by ordinal.
+ * @returns   Pointer to an exported procedure. 0UL if not found.
+ * @param     ordinal  Export ordinal number.
+ * @status    completely implemented.
+ * @author    Sander van Leeuwen
+ * @remark    FIXME:
+ *            This function should be implemented for both Exe and Dll images!
+ *            It could be done similar in both peldr image and pe2lx images by
+ *            accessing PE structures.
+ */
+ULONG Win32Pe2LxImage::getApi(int ordinal)
+{
+    APIRET      rc;
+    ULONG       ulApiAddr;
+
+    rc = DosQueryProcAddr(hinstance, ordinal, NULL, (PFN *)&ulApiAddr);
+
+    return rc == NO_ERROR ? ulApiAddr : 0;
+}
Index: trunk/src/kernel32/winimagepeldr.cpp
===================================================================
--- trunk/src/kernel32/winimagepeldr.cpp	(revision 1841)
+++ trunk/src/kernel32/winimagepeldr.cpp	(revision 1844)
@@ -1,3 +1,3 @@
-/* $Id: winimagepeldr.cpp,v 1.16 1999-11-24 19:52:34 sandervl Exp $ */
+/* $Id: winimagepeldr.cpp,v 1.17 1999-11-26 00:05:19 sandervl Exp $ */
 
 /*
@@ -315,9 +315,4 @@
 		tlsDir = (IMAGE_TLS_DIRECTORY *)ImageDirectoryOffset(win32file, IMAGE_DIRECTORY_ENTRY_TLS);
 		if(tlsDir) {
-			fout << "TLS Directory" << endl;
-			fout << "TLS Address of Index     " << hex((ULONG)tlsDir->AddressOfIndex) << endl;
-			fout << "TLS Address of Callbacks " << hex((ULONG)tlsDir->AddressOfCallBacks) << endl;
-			fout << "TLS SizeOfZeroFill       " << hex(tlsDir->SizeOfZeroFill) << endl;
-			fout << "TLS Characteristics      " << hex(tlsDir->Characteristics) << endl;
 		        addSection(SECTION_TLS, psh[i].PointerToRawData,
                 		   psh[i].SizeOfRawData, psh[i].VirtualAddress + oh.ImageBase,
@@ -440,4 +435,9 @@
 	    	goto failure;
 	}
+	fout << "TLS Directory" << endl;
+	fout << "TLS Address of Index     " << hex((ULONG)tlsDir->AddressOfIndex) << endl;
+	fout << "TLS Address of Callbacks " << hex((ULONG)tlsDir->AddressOfCallBacks) << endl;
+	fout << "TLS SizeOfZeroFill       " << hex(tlsDir->SizeOfZeroFill) << endl;
+	fout << "TLS Characteristics      " << hex(tlsDir->Characteristics) << endl;
   	setTLSAddress((char *)sect->realvirtaddr);
   	setTLSInitSize(tlsDir->EndAddressOfRawData - tlsDir->StartAddressOfRawData);
@@ -463,10 +463,10 @@
 	commitPage((ULONG)pFixups, FALSE);
    }
-   if(fh.Characteristics & IMAGE_FILE_DLL) {
+//   if(fh.Characteristics & IMAGE_FILE_DLL) {
     	if(processExports((char *)win32file) == FALSE) {
         	fout << "Failed to process exported apis" << endl;
 	    	goto failure;
     	}
-   }
+//   }
   }
 
@@ -1432,4 +1432,60 @@
 //******************************************************************************
 //******************************************************************************
+ULONG Win32PeLdrImage::getApi(char *name)
+{
+  ULONG       apiaddr, i, apilen;
+  char       *apiname;
+  char        tmp[4];
+  NameExport *curexport;
+  ULONG       ulAPIOrdinal;                      /* api requested by ordinal */
+  
+  apilen = strlen(name) + 1;
+  if(apilen < 4) 
+  {
+	*(ULONG *)tmp = 0;
+	strcpy(tmp, name);
+	apiname = tmp;
+  }
+  else	apiname = name;
+
+  curexport = nameexports;
+  for(i=0; i<nrNameExports; i++) 
+  {
+    if(apilen == curexport->nlength && 
+       *(ULONG *)curexport->name == *(ULONG *)name) 
+    {
+      	if(strcmp(curexport->name, name) == 0) 
+        	return(curexport->virtaddr);
+    }
+    curexport = (NameExport *)((ULONG)curexport->name + curexport->nlength);
+  }
+  return(0);
+}
+//******************************************************************************
+//******************************************************************************
+ULONG Win32PeLdrImage::getApi(int ordinal)
+{
+ ULONG       apiaddr, i;
+ OrdExport  *curexport;
+ NameExport *nexport;
+
+  curexport = ordexports;
+  for(i=0;i<nrOrdExports;i++) {
+	if(curexport->ordinal == ordinal)
+		return(curexport->virtaddr);
+	curexport++;
+  }
+  //Name exports also contain an ordinal, so check this 
+  nexport = nameexports;
+  for(i=0;i<nrNameExports;i++) {
+	if(nexport->ordinal == ordinal)
+		return(nexport->virtaddr);
+
+	nexport = (NameExport *)((ULONG)nexport->name + nexport->nlength);
+  }
+  return(0);
+}
+//******************************************************************************
+//******************************************************************************
 ULONG MissingApi()
 {
Index: trunk/src/kernel32/wprocess.cpp
===================================================================
--- trunk/src/kernel32/wprocess.cpp	(revision 1841)
+++ trunk/src/kernel32/wprocess.cpp	(revision 1844)
@@ -1,3 +1,3 @@
-/* $Id: wprocess.cpp,v 1.50 1999-11-22 20:35:52 sandervl Exp $ */
+/* $Id: wprocess.cpp,v 1.51 1999-11-26 00:05:20 sandervl Exp $ */
 
 /*
@@ -684,9 +684,13 @@
 FARPROC WIN32API GetProcAddress(HMODULE hModule, LPCSTR lpszProc)
 {
- Win32DllBase *winmod;
+ Win32ImageBase *winmod;
  FARPROC   proc;
  ULONG     ulAPIOrdinal;
 
-  winmod = Win32DllBase::findModule((HINSTANCE)hModule);
+  if(hModule == 0 || hModule == -1 || (WinExe && hModule == WinExe->getInstanceHandle())) {
+	winmod = WinExe;
+  }
+  else  winmod = (Win32ImageBase *)Win32DllBase::findModule((HINSTANCE)hModule);
+
   if(winmod) {
     	ulAPIOrdinal = (ULONG)lpszProc;
