Index: trunk/src/gdi32/initgdi32.cpp
===================================================================
--- trunk/src/gdi32/initgdi32.cpp	(revision 6395)
+++ trunk/src/gdi32/initgdi32.cpp	(revision 6397)
@@ -86,4 +86,5 @@
          ParseLogStatusGDI32();
 
+         InitializeKernel32();
 	 if(InitRegionSpace() == FALSE) {
 		return 0UL;
Index: trunk/src/kernel32/KERNEL32.CPP
===================================================================
--- trunk/src/kernel32/KERNEL32.CPP	(revision 6395)
+++ trunk/src/kernel32/KERNEL32.CPP	(revision 6397)
@@ -1,3 +1,3 @@
-/* $Id: KERNEL32.CPP,v 1.68 2001-06-03 08:49:29 sandervl Exp $ */
+/* $Id: KERNEL32.CPP,v 1.69 2001-07-28 18:03:36 sandervl Exp $ */
 
 /*
@@ -129,8 +129,8 @@
 //******************************************************************************
 //******************************************************************************
-BOOL WIN32API IsBadCodePtr( FARPROC arg1)
-{
-    dprintf(("KERNEL32:  IsBadCodePtr\n"));
-    return O32_IsBadCodePtr(arg1);
+BOOL WIN32API IsBadCodePtr(FARPROC pCode)
+{
+    dprintf(("KERNEL32: IsBadCodePtr %x", pCode));
+    return O32_IsBadCodePtr(pCode);
 }
 //******************************************************************************
@@ -226,34 +226,51 @@
     dprintf(("dwAvailVirtual  %X\n", arg1->dwAvailVirtual));
 }
+//******************************************************************************
+//******************************************************************************
 BOOL WIN32API Beep( DWORD arg1, DWORD  arg2)
 {
-    dprintf(("KERNEL32:  OS2Beep\n"));
-    return O32_Beep(arg1, arg2);
-}
-//******************************************************************************
-//******************************************************************************
-VOID WIN32API FatalAppExitA( UINT arg1, LPCSTR  arg2)
-{
-    dprintf(("KERNEL32:  OS2FatalAppExitA\n"));
-    O32_FatalAppExit(arg1, arg2);
-}
-//******************************************************************************
-//******************************************************************************
-VOID WIN32API FatalAppExitW(UINT arg1, LPCWSTR arg2)
-{
- char *astring;
-
-    dprintf(("KERNEL32: OS2FatalAppExitW %x", arg1));
-    astring = UnicodeToAsciiString((LPWSTR)arg2);
-    O32_FatalAppExit(arg1, astring);
-    //probably won't return, but who cares..
-    FreeAsciiString(astring);
-}
-//******************************************************************************
-//******************************************************************************
-VOID WIN32API FatalExit( UINT arg1)
-{
-    dprintf(("KERNEL32: FatalExit %x", arg1));
-    O32_FatalExit(arg1);
+    dprintf(("KERNEL32: Beep %d %d", arg1, arg2));
+    return OSLibDosBeep(arg1, arg2);
+}
+//******************************************************************************
+//******************************************************************************
+
+typedef INT (WINAPI *MessageBoxA_funcptr)(HWND,LPCSTR,LPCSTR,UINT);
+typedef INT (WINAPI *MessageBoxW_funcptr)(HWND,LPCWSTR,LPCWSTR,UINT);
+
+//******************************************************************************
+//******************************************************************************
+VOID WIN32API FatalAppExitA( UINT exitCode, LPCSTR  str)
+{
+    HMODULE mod = GetModuleHandleA( "user32.dll" );
+    MessageBoxA_funcptr pMessageBoxA = NULL;
+
+    dprintf(("KERNEL32: FatalAppExitA %d %s", exitCode, str));
+
+    if (mod) pMessageBoxA = (MessageBoxA_funcptr)GetProcAddress( mod, "MessageBoxA" );
+    if(pMessageBoxA) pMessageBoxA( 0, str, NULL, MB_SYSTEMMODAL | MB_OK );
+
+    ExitProcess(exitCode);
+}
+//******************************************************************************
+//******************************************************************************
+VOID WIN32API FatalAppExitW(UINT exitCode, LPCWSTR str)
+{
+    HMODULE mod = GetModuleHandleA( "user32.dll" );
+    MessageBoxW_funcptr pMessageBoxW = NULL;
+
+    dprintf(("KERNEL32: FatalAppExitW %d %ls", exitCode, str));
+
+    if (mod) pMessageBoxW = (MessageBoxW_funcptr)GetProcAddress( mod, "MessageBoxW" );
+    if(pMessageBoxW) pMessageBoxW( 0, str, NULL, MB_SYSTEMMODAL | MB_OK );
+
+    ExitProcess(exitCode);
+}
+//******************************************************************************
+//******************************************************************************
+VOID WIN32API FatalExit( UINT exitCode)
+{
+    dprintf(("KERNEL32: FatalExit %x", exitCode));
+    ExitProcess(exitCode);
 }
 //******************************************************************************
@@ -261,6 +278,5 @@
 BOOL WIN32API IsBadHugeReadPtr( const void * arg1, UINT  arg2)
 {
-    dprintf(("KERNEL32:  OS2IsBadHugeReadPtr\n"));
-    return O32_IsBadHugeReadPtr(arg1, arg2);
+    return IsBadReadPtr(arg1, arg2);
 }
 //******************************************************************************
@@ -268,6 +284,5 @@
 BOOL WIN32API IsBadHugeWritePtr( PVOID arg1, UINT  arg2)
 {
-    dprintf(("KERNEL32: IsBadHugeWritePtr\n"));
-    return O32_IsBadHugeWritePtr(arg1, arg2);
+    return IsBadWritePtr(arg1, arg2);
 }
 //******************************************************************************
Index: trunk/src/kernel32/KERNEL32.DEF
===================================================================
--- trunk/src/kernel32/KERNEL32.DEF	(revision 6395)
+++ trunk/src/kernel32/KERNEL32.DEF	(revision 6397)
@@ -1,3 +1,3 @@
-; $Id: KERNEL32.DEF,v 1.116 2001-07-22 18:13:08 sandervl Exp $
+; $Id: KERNEL32.DEF,v 1.117 2001-07-28 18:03:36 sandervl Exp $
 
 ;Basis is Windows95 KERNEL32
@@ -1164,4 +1164,9 @@
     _Odin32GetBuildNumber@0                                       @1293 NONAME
 
+    _AttachThreadInput@12                                         @1300 NONAME
+    _WaitForInputIdle@8                                           @1301 NONAME
+
+    InitializeKernel32                                            @1302 NONAME
+
     IsExeStarted__Fv                                              @2001 NONAME
     CheckCurFS                                                    @2002 NONAME
Index: trunk/src/kernel32/heap.cpp
===================================================================
--- trunk/src/kernel32/heap.cpp	(revision 6395)
+++ trunk/src/kernel32/heap.cpp	(revision 6397)
@@ -1,3 +1,3 @@
-/* $Id: heap.cpp,v 1.32 2001-07-17 12:10:21 sandervl Exp $ */
+/* $Id: heap.cpp,v 1.33 2001-07-28 18:03:37 sandervl Exp $ */
 
 /*
@@ -82,13 +82,9 @@
   //Create Open32 heap for it's handle
   dprintf2(("HeapCreate dwInitialSize %X", dwInitialSize));
-  HANDLE hHeap = O32_HeapCreate(flOptions, 0, 4096);
-  if(hHeap == NULL)
-    return(NULL);
-
-  curheap = new OS2Heap(hHeap, flOptions, dwInitialSize, dwMaximumSize);
+
+  curheap = new OS2Heap(flOptions, dwInitialSize, dwMaximumSize);
 
   if(curheap == NULL)
   {
-      	O32_HeapDestroy(hHeap);
         return(NULL);
   }
@@ -96,5 +92,4 @@
   if(curheap->getHeapHandle() == NULL)
   {
-    O32_HeapDestroy(hHeap);
     delete(curheap);
     return(NULL);
@@ -112,5 +107,4 @@
         return(FALSE);
 
-  O32_HeapDestroy(curheap->getHeapHandle());
   delete(curheap);
   return(TRUE);
@@ -178,14 +172,10 @@
     //SvL: Only one process heap per process
     if(processheap == NULL) {
-      //TODO: I haven't thought real hard about this.  I added it just to make "hdr.exe" happy.
-      hHeap = O32_HeapCreate(HEAP_GENERATE_EXCEPTIONS, 1, 0x4000);
-
-      OS2ProcessHeap = new OS2Heap(hHeap, HEAP_GENERATE_EXCEPTIONS, 0x4000, 0);
+      OS2ProcessHeap = new OS2Heap(HEAP_GENERATE_EXCEPTIONS, 0x4000, 0);
 
       if(OS2ProcessHeap == NULL) {
-         	O32_HeapDestroy(hHeap);
                	return(NULL);
       }
-      processheap = hHeap;
+      processheap = OS2ProcessHeap->getHeapHandle();
     }
     return(processheap);
Index: trunk/src/kernel32/initkernel32.cpp
===================================================================
--- trunk/src/kernel32/initkernel32.cpp	(revision 6395)
+++ trunk/src/kernel32/initkernel32.cpp	(revision 6397)
@@ -89,4 +89,5 @@
     APIRET rc;
     ULONG  ulSysinfo, version[2];
+    static BOOL fInit = FALSE;
     
     /*-------------------------------------------------------------------------*/
@@ -96,4 +97,8 @@
     /*-------------------------------------------------------------------------*/
 
+    if(fInit == TRUE && ulFlag == 0) {
+        return 1; //already initialized
+    }
+    fInit = TRUE;
     switch (ulFlag)
     {
@@ -229,2 +234,16 @@
     return ;
 }
+//******************************************************************************
+ULONG APIENTRY O32__DLL_InitTerm(ULONG handle, ULONG flag);
+//******************************************************************************
+ULONG APIENTRY InitializeKernel32()
+{
+    HMODULE hModule;
+
+    DosQueryModuleHandle("WGSS50", &hModule);
+    O32__DLL_InitTerm(hModule, 0);
+    DosQueryModuleHandle("KERNEL32", &hModule);
+    return inittermKernel32(hModule, 0);
+}
+//******************************************************************************
+//******************************************************************************
Index: trunk/src/kernel32/os2heap.cpp
===================================================================
--- trunk/src/kernel32/os2heap.cpp	(revision 6395)
+++ trunk/src/kernel32/os2heap.cpp	(revision 6397)
@@ -1,3 +1,3 @@
-/* $Id: os2heap.cpp,v 1.21 2001-07-19 20:00:56 sandervl Exp $ */
+/* $Id: os2heap.cpp,v 1.22 2001-07-28 18:03:38 sandervl Exp $ */
 
 /*
@@ -47,9 +47,8 @@
 //******************************************************************************
 //******************************************************************************
-OS2Heap::OS2Heap(HANDLE hHeap, DWORD flOptions, DWORD dwInitialSize, DWORD dwMaximumSize)
+OS2Heap::OS2Heap(DWORD flOptions, DWORD dwInitialSize, DWORD dwMaximumSize)
 {
  OS2Heap *curheap = OS2Heap::heap;
 
-  hPrimaryHeap = hHeap;
   totalAlloc   = 0;
   fInitialized = 0;
@@ -99,4 +98,5 @@
         DebugInt3();
   }
+  hPrimaryHeap = (HANDLE)uheap;
 }
 //******************************************************************************
Index: trunk/src/kernel32/os2heap.h
===================================================================
--- trunk/src/kernel32/os2heap.h	(revision 6395)
+++ trunk/src/kernel32/os2heap.h	(revision 6397)
@@ -1,3 +1,3 @@
-/* $Id: os2heap.h,v 1.6 2001-07-17 12:10:22 sandervl Exp $ */
+/* $Id: os2heap.h,v 1.7 2001-07-28 18:03:38 sandervl Exp $ */
 
 /*
@@ -37,5 +37,5 @@
 {
 public:
-    OS2Heap(HANDLE hHeap, DWORD flOptions, DWORD dwInitialSize, DWORD dwMaximumSize);
+    OS2Heap(DWORD flOptions, DWORD dwInitialSize, DWORD dwMaximumSize);
     ~OS2Heap();
 
Index: trunk/src/kernel32/oslibdos.cpp
===================================================================
--- trunk/src/kernel32/oslibdos.cpp	(revision 6395)
+++ trunk/src/kernel32/oslibdos.cpp	(revision 6397)
@@ -1,3 +1,3 @@
-/* $Id: oslibdos.cpp,v 1.71 2001-06-24 16:40:44 sandervl Exp $ */
+/* $Id: oslibdos.cpp,v 1.72 2001-07-28 18:03:38 sandervl Exp $ */
 /*
  * Wrappers for OS/2 Dos* API
@@ -2603,2 +2603,61 @@
 //******************************************************************************
 //******************************************************************************
+BOOL OSLibDosBeep(DWORD ulFreq, DWORD ulDuration)
+{
+   APIRET   rc;
+
+   if (ulDuration == -1)
+   {
+      SetLastError(ERROR_NOT_SUPPORTED_W);
+      return FALSE;
+   }
+   rc = DosBeep(ulFreq, ulDuration);
+   SetLastError(error2WinError(rc,ERROR_INVALID_HANDLE));
+
+   return (rc == 0);
+}
+//******************************************************************************
+//******************************************************************************
+ULONG OSLibDosGetModuleFileName(HMODULE hModule, LPTSTR lpszPath, DWORD cchPath)
+{
+   PTIB pTIB;
+   PPIB pPIB;
+   APIRET rc;
+
+   if(hModule == -1 || hModule == 0)
+   {
+      DosGetInfoBlocks(&pTIB, &pPIB);
+      hModule = pPIB->pib_hmte;
+   }
+   *lpszPath = 0;
+   rc = DosQueryModuleName(hModule, cchPath, lpszPath);
+
+   DWORD len = strlen(lpszPath);
+   SetLastError(error2WinError(rc,ERROR_INVALID_HANDLE));
+   return len;
+}
+//******************************************************************************
+//******************************************************************************
+ULONG OSLibDosGetProcAddress(HMODULE hModule, LPCSTR lpszProc)
+{
+   APIRET  rc;
+   PFN     pfn = NULL;
+   ULONG   ordinal = (((ULONG)lpszProc) <= 0xFFFF) ? (ULONG)lpszProc : 0;
+   HMODULE hmod = (HMODULE)hModule;
+
+   rc = DosQueryProcAddr( hmod, ordinal, (PSZ)lpszProc, &pfn );
+   if(rc == ERROR_INVALID_HANDLE && pfn == NULL) {
+      CHAR pszError[32], pszModule[CCHMAXPATH];
+
+      if(DosQueryModuleName( hmod, CCHMAXPATH, pszModule ) == 0 && 
+         DosLoadModule( pszError, 32, pszModule, &hmod ) == 0) 
+      {
+          rc = DosQueryProcAddr(hmod, ordinal, (PSZ)lpszProc, &pfn);
+      }
+   }
+   SetLastError(error2WinError(rc,ERROR_INVALID_HANDLE));
+
+   return (ULONG)pfn;
+}
+//******************************************************************************
+//******************************************************************************
Index: trunk/src/kernel32/oslibdos.h
===================================================================
--- trunk/src/kernel32/oslibdos.h	(revision 6395)
+++ trunk/src/kernel32/oslibdos.h	(revision 6397)
@@ -1,3 +1,3 @@
-/* $Id: oslibdos.h,v 1.34 2001-06-24 16:40:45 sandervl Exp $ */
+/* $Id: oslibdos.h,v 1.35 2001-07-28 18:03:38 sandervl Exp $ */
 
 /*
@@ -311,2 +311,6 @@
 HINSTANCE OSLibDosLoadModule(LPSTR szModName);
 void      OSLibDosFreeModule(HINSTANCE hinst);
+
+ULONG OSLibDosGetModuleFileName(HMODULE hModule, LPTSTR lpszPath, DWORD cchPath);
+BOOL  OSLibDosBeep(DWORD ulFreq, DWORD ulDuration);
+ULONG OSLibDosGetProcAddress(HMODULE hModule, LPCSTR lpszProc);
Index: trunk/src/kernel32/wprocess.cpp
===================================================================
--- trunk/src/kernel32/wprocess.cpp	(revision 6395)
+++ trunk/src/kernel32/wprocess.cpp	(revision 6397)
@@ -1,3 +1,3 @@
-/* $Id: wprocess.cpp,v 1.130 2001-07-15 15:18:58 sandervl Exp $ */
+/* $Id: wprocess.cpp,v 1.131 2001-07-28 18:03:38 sandervl Exp $ */
 
 /*
@@ -1419,5 +1419,5 @@
         //only needed for call inside kernel32's initterm (profile init)
         //(console init only it seems...)
-        cch = O32_GetModuleFileName(hModule, lpszPath, cchPath);
+        cch = OSLibDosGetModuleFileName(hModule, lpszPath, cchPath);
         if (cch > 0)    cch++;          /* Open32 doesn't count the terminator. */
     }
@@ -1874,12 +1874,38 @@
     }
     else {
-        rc = O32_WaitForInputIdle(procinfo.hProcess, 15000);
+        dprintf(("Calling WaitForInputIdle %x %d", procinfo.hProcess, 15000));
+        rc = WaitForInputIdle(procinfo.hProcess, 15000);
+#ifdef DEBUG
         if(rc != 0) {
             dprintf(("WinExec: WaitForInputIdle %x returned %x", procinfo.hProcess, rc));
         }
+        else dprintf(("WinExec: WaitForInputIdle successfull"));
+#endif
     }
     CloseHandle(procinfo.hThread);
     CloseHandle(procinfo.hProcess);
     return 33;
+}
+//******************************************************************************
+//DWORD idAttach;   /* thread to attach */
+//DWORD idAttachTo; /* thread to attach to  */
+//BOOL fAttach; /* attach or detach */
+//******************************************************************************
+BOOL WIN32API AttachThreadInput(DWORD idAttach, DWORD idAttachTo, BOOL fAttach)
+{
+  dprintf(("USER32: AttachThreadInput, not implemented\n"));
+  return(TRUE);
+}
+//******************************************************************************
+//******************************************************************************
+DWORD WIN32API WaitForInputIdle(HANDLE hProcess, DWORD dwTimeOut)
+{
+  dprintf(("USER32: WaitForInputIdle %x %d\n", hProcess, dwTimeOut));
+
+  if(fVersionWarp3) {
+        Sleep(1000);
+        return 0;        
+  }
+  else  return O32_WaitForInputIdle(hProcess, dwTimeOut);
 }
 //******************************************************************************
@@ -1951,5 +1977,5 @@
     {
         /* Give 15 seconds to the app to come up */
-        if ( O32_WaitForInputIdle ( info.hProcess, 15000 ) ==  0xFFFFFFFF )
+        if ( WaitForInputIdle ( info.hProcess, 15000 ) ==  0xFFFFFFFF )
             dprintf(("ERROR: WaitForInputIdle failed: Error %ld\n", GetLastError() ));
         hInstance = 33;
@@ -2000,5 +2026,5 @@
         return proc;
   }
-  proc = O32_GetProcAddress(hModule, lpszProc);
+  proc = (FARPROC)OSLibDosGetProcAddress(hModule, lpszProc);
   if(HIWORD(lpszProc))
         dprintf(("KERNEL32:  GetProcAddress %s from %X returned %X\n", lpszProc, hModule, proc));
Index: trunk/src/user32/inituser32.cpp
===================================================================
--- trunk/src/user32/inituser32.cpp	(revision 6395)
+++ trunk/src/user32/inituser32.cpp	(revision 6397)
@@ -87,4 +87,6 @@
          ParseLogStatusUSER32();
 
+         InitializeKernel32();
+
          hInstanceUser32 = RegisterLxDll(hModule, 0, (PVOID)&_Resource_PEResTab,
                                          USER32_MAJORIMAGE_VERSION, USER32_MINORIMAGE_VERSION,
Index: trunk/src/user32/user32.cpp
===================================================================
--- trunk/src/user32/user32.cpp	(revision 6395)
+++ trunk/src/user32/user32.cpp	(revision 6397)
@@ -1,3 +1,3 @@
-/* $Id: user32.cpp,v 1.109 2001-07-15 14:58:07 sandervl Exp $ */
+/* $Id: user32.cpp,v 1.110 2001-07-28 18:02:50 sandervl Exp $ */
 
 /*
@@ -973,29 +973,4 @@
 }
 
-/* Process and Thread Functions */
-
-//******************************************************************************
-//DWORD idAttach;   /* thread to attach */
-//DWORD idAttachTo; /* thread to attach to  */
-//BOOL fAttach; /* attach or detach */
-//******************************************************************************
-BOOL WIN32API AttachThreadInput(DWORD idAttach, DWORD idAttachTo, BOOL fAttach)
-{
-  dprintf(("USER32:  AttachThreadInput, not implemented\n"));
-  return(TRUE);
-}
-//******************************************************************************
-//******************************************************************************
-DWORD WIN32API WaitForInputIdle(HANDLE hProcess, DWORD dwTimeOut)
-{
-  dprintf(("USER32: WaitForInputIdle %x %d\n", hProcess, dwTimeOut));
-
-  if(fVersionWarp3) {
-        Sleep(1000);
-        return 0;        
-  }
-  else  return O32_WaitForInputIdle(hProcess, dwTimeOut);
-}
-
 /* Help Functions */
 
Index: trunk/src/user32/window.cpp
===================================================================
--- trunk/src/user32/window.cpp	(revision 6395)
+++ trunk/src/user32/window.cpp	(revision 6397)
@@ -1,3 +1,3 @@
-/* $Id: window.cpp,v 1.102 2001-07-28 13:43:54 sandervl Exp $ */
+/* $Id: window.cpp,v 1.103 2001-07-28 18:02:50 sandervl Exp $ */
 /*
  * Win32 window apis for OS/2
@@ -1872,8 +1872,8 @@
 
     hwnd = Win32ToOS2Handle(hWnd);
-    hwnd = OS2ToWin32Handle(O32_GetLastActivePopup(hwnd));
+////    hwnd = OS2ToWin32Handle(O32_GetLastActivePopup(hwnd));
 
     dprintf(("GetLastActivePopup %x returned %x NOT CORRECTLY IMPLEMENTED", hWnd, hwnd));
-    return hwnd;
+    return 0;
 }
 //******************************************************************************
