Index: trunk/src/kernel32/conbuffer.cpp
===================================================================
--- trunk/src/kernel32/conbuffer.cpp	(revision 10469)
+++ trunk/src/kernel32/conbuffer.cpp	(revision 10471)
@@ -1,3 +1,3 @@
-/* $Id: conbuffer.cpp,v 1.19 2003-04-11 12:08:35 sandervl Exp $ */
+/* $Id: conbuffer.cpp,v 1.20 2004-02-19 13:03:05 sandervl Exp $ */
 
 /*
@@ -2498,5 +2498,4 @@
 }
 
-
 /*****************************************************************************
  * Name      : DWORD HMDeviceConsoleBufferClass::WriteConsoleW
@@ -2524,4 +2523,5 @@
   DWORD          rc;
   LPSTR          pszAscii;
+  int            alen;
 
 #ifdef DEBUG_LOCAL2
@@ -2534,18 +2534,21 @@
 #endif
 
+  alen = WideCharToMultiByte( GetConsoleCP(), 0, (LPCWSTR)lpvBuffer, cchToWrite, 0, 0, 0, 0 );
   /* Ascii -> unicode translation */
-  pszAscii = (LPSTR)HEAP_malloc(cchToWrite+1);
+  pszAscii = (LPSTR)HEAP_malloc(( alen + 1 ) * sizeof( WCHAR ));
   if (pszAscii == NULL)
      return ERROR_NOT_ENOUGH_MEMORY;
 
-  lstrcpynWtoA(pszAscii, (LPWSTR)lpvBuffer, cchToWrite+1);
+  WideCharToMultiByte( GetConsoleCP(), 0, (LPWSTR)lpvBuffer, cchToWrite, pszAscii, alen, 0, 0 );
+  pszAscii[ alen ] = 0;
 
   /* simply forward the request to that routine */
   rc = HMDeviceConsoleBufferClass::WriteFile(pHMHandleData,
                                              pszAscii,
-                                             cchToWrite,
+                                             alen,
                                              lpcchWritten,
                                              NULL, NULL);
 
+  *lpcchWritten = MultiByteToWideChar( GetConsoleCP(), 0, pszAscii, *lpcchWritten, 0, 0 );
   // free memory again
   HEAP_free(pszAscii);
Index: trunk/src/kernel32/conin.cpp
===================================================================
--- trunk/src/kernel32/conin.cpp	(revision 10469)
+++ trunk/src/kernel32/conin.cpp	(revision 10471)
@@ -1,3 +1,3 @@
-/* $Id: conin.cpp,v 1.17 2001-12-05 18:05:59 sandervl Exp $ */
+/* $Id: conin.cpp,v 1.18 2004-02-19 13:03:05 sandervl Exp $ */
 
 /*
@@ -755,12 +755,13 @@
 
   // create ascii buffer
-  lpstrAscii = (LPSTR)HEAP_malloc(cchToRead);
+  lpstrAscii = (LPSTR)HEAP_malloc(cchToRead * sizeof( WCHAR ));
   if (lpstrAscii == NULL)
      return ERROR_NOT_ENOUGH_MEMORY;
 
                                /* simply forward the request to that routine */
+  // FIXME : if results of ReadFile() have MBCS string, some data might be lost on next call.
   dwResult = HMDeviceConsoleInClass::ReadFile(pHMHandleData,
                                               lpstrAscii,
-                                              cchToRead,
+                                              cchToRead * sizeof( WCHAR ),
                                               lpcchRead,
                                               NULL, NULL);
@@ -768,5 +769,5 @@
   /* Ascii -> unicode translation */
   if (dwResult == TRUE)
-    lstrcpynAtoW((LPWSTR)lpvBuffer, lpstrAscii, min(cchToRead, *lpcchRead+1));
+    *lpcchRead = MultiByteToWideChar( GetConsoleCP(), 0, lpstrAscii, *lpcchRead, ( LPWSTR )lpvBuffer, cchToRead );
 
   HEAP_free(lpstrAscii);
Index: trunk/src/kernel32/console.cpp
===================================================================
--- trunk/src/kernel32/console.cpp	(revision 10469)
+++ trunk/src/kernel32/console.cpp	(revision 10471)
@@ -1,3 +1,3 @@
-/* $Id: console.cpp,v 1.32 2002-12-27 13:42:08 sandervl Exp $ */
+/* $Id: console.cpp,v 1.33 2004-02-19 13:03:06 sandervl Exp $ */
 
 /*
@@ -61,6 +61,8 @@
 #define  INCL_DOSSEMAPHORES
 #define  INCL_DOSERRORS
+#define  INCL_DOSEXCEPTIONS
 #define  INCL_DOSPROCESS
 #define  INCL_DOSMODULEMGR
+#define  INCL_DOSDEVICES
 #define  INCL_VIO
 #define  INCL_KBD
@@ -177,4 +179,9 @@
   if (ConsoleGlobals.hevConsole != NULLHANDLE) /* we're already initialized ?*/
     return (NO_ERROR);                             /* then abort immediately */
+
+  rc = DosSetSignalExceptionFocus(SIG_SETFOCUS, &ulPostCount);
+  if(rc) {
+      dprintf(("DosSetSignalExceptionFocus failed with %d", rc));
+  }
 
   if(flVioConsole == TRUE)
@@ -2695,19 +2702,16 @@
  *****************************************************************************/
 
+
 DWORD WIN32API GetConsoleTitleW(LPWSTR lpConsoleTitle,
                                 DWORD  nSize)
 {
-  ULONG ulLength;                                          /* length of text */
-
   if (ConsoleGlobals.pszWindowTitle == NULL)    /* is there a window title ? */
     return 0;                                           /* abort immediately */
 
-  ulLength = strlen(ConsoleGlobals.pszWindowTitle);        /* length of text */
-
-  lstrcpynAtoW(lpConsoleTitle,
-               ConsoleGlobals.pszWindowTitle,
-               nSize);
-
-  return (nSize < ulLength) ? nSize : ulLength;
+  MultiByteToWideChar( GetConsoleCP(), 0, ConsoleGlobals.pszWindowTitle, -1,
+        lpConsoleTitle, nSize );
+  lpConsoleTitle[ nSize - 1 ] = 0;
+
+  return lstrlenW( lpConsoleTitle );
 }
 
@@ -3443,4 +3447,6 @@
 BOOL WIN32API SetConsoleTitleW(LPWSTR lpszTitle)
 {
+  int alen;
+
   if (lpszTitle == NULL)                                 /* check parameters */
     return FALSE;
@@ -3449,12 +3455,9 @@
     free (ConsoleGlobals.pszWindowTitle);                     /* then free it */
 
+  alen = WideCharToMultiByte( GetConsoleCP(), 0, lpszTitle, -1, 0, 0, 0, 0 );
   /* create an ascii copy of the lpszTitle */
-  int iLength = lstrlenW(lpszTitle);
-
-  ConsoleGlobals.pszWindowTitle = (PSZ)malloc(iLength+1);
-  ConsoleGlobals.pszWindowTitle[iLength] = 0;
-  lstrcpynWtoA(ConsoleGlobals.pszWindowTitle,
-               lpszTitle,
-               iLength+1); //must add one (lstrcpynWtoA terminates string)
+  ConsoleGlobals.pszWindowTitle = (PSZ)malloc( alen );
+  WideCharToMultiByte( GetConsoleCP(), 0, lpszTitle, -1,
+        ConsoleGlobals.pszWindowTitle, alen, 0, 0 );
 
   WinSetWindowText(ConsoleGlobals.hwndFrame,           /* set new title text */
Index: trunk/src/kernel32/winimgres.cpp
===================================================================
--- trunk/src/kernel32/winimgres.cpp	(revision 10469)
+++ trunk/src/kernel32/winimgres.cpp	(revision 10471)
@@ -1,3 +1,3 @@
-/* $Id: winimgres.cpp,v 1.53 2001-08-03 17:45:27 sandervl Exp $ */
+/* $Id: winimgres.cpp,v 1.54 2004-02-19 13:03:07 sandervl Exp $ */
 
 /*
@@ -11,5 +11,5 @@
  * Copyright 1995 Thomas Sandford
  * Copyright 1996 Martin von Loewis
- * 
+ *
  *
  * Project Odin Software License can be found in LICENSE.TXT
@@ -32,5 +32,5 @@
 #include "oslibmisc.h"
 
-#define DBG_LOCALLOG	DBG_winimgres
+#define DBG_LOCALLOG    DBG_winimgres
 #include "dbglocal.h"
 
@@ -42,6 +42,6 @@
 
 STD_RESTYPE ResType[MAX_RES] =
-      { {NULL,          0}, 
-        {"CURSOR",      6}, 
+      { {NULL,          0},
+        {"CURSOR",      6},
         {"BITMAP",      6},
         {"ICON",        4},
@@ -69,5 +69,5 @@
 {
  PIMAGE_RESOURCE_DATA_ENTRY pData = NULL;
-   
+
     pData = (PIMAGE_RESOURCE_DATA_ENTRY)findResourceA(lpszName, lpszType, lang);
     if(pData == NULL) {
@@ -82,5 +82,5 @@
 {
  PIMAGE_RESOURCE_DATA_ENTRY pData = NULL;
-   
+
     pData = (PIMAGE_RESOURCE_DATA_ENTRY)findResourceW(lpszName, lpszType, lang);
     if(pData == NULL) {
@@ -98,6 +98,6 @@
 
   if(pData == NULL) {
-	DebugInt3();
-	return NULL;
+    DebugInt3();
+    return NULL;
   }
   //ulRVAResourceSection contains the relative virtual address (relative to the start of the image)
@@ -113,6 +113,6 @@
 
   if(pData == NULL) {
-	DebugInt3();
-	return NULL;
+    DebugInt3();
+    return NULL;
   }
   return pData->Size;
@@ -127,10 +127,10 @@
  HRSRC                     hRes;
 
-    if(HIWORD(lpszType) != 0) 
-    {
-	typelen = strlen(lpszType);
+    if(HIWORD(lpszType) != 0)
+    {
+    typelen = strlen(lpszType);
 
         for(int i=0;i<MAX_RES;i++) {
-            if(ResType[i].namelen && 
+            if(ResType[i].namelen &&
                ResType[i].namelen == typelen &&
                stricmp(lpszType, ResType[i].typename) == 0)
@@ -144,12 +144,12 @@
     if(!pResDirRet) {
         dprintf2(("FindResourceA %s: resource %x (type %x, lang %x) TYPE NOT FOUND", szModule, lpszName, lpszType, lang));
-	SetLastError(ERROR_RESOURCE_TYPE_NOT_FOUND);
-	return NULL;
+    SetLastError(ERROR_RESOURCE_TYPE_NOT_FOUND);
+    return NULL;
     }
     pResDirRet = getResSubDirA(pResDirRet, lpszName);
     if(!pResDirRet) {
         dprintf2(("FindResourceA %s: resource %x (type %x, lang %x) NAME NOT FOUND", szModule, lpszName, lpszType, lang));
-	SetLastError(ERROR_RESOURCE_NAME_NOT_FOUND);
-	return NULL;
+    SetLastError(ERROR_RESOURCE_NAME_NOT_FOUND);
+    return NULL;
     }
 
@@ -160,5 +160,5 @@
        lang == MAKELANGID(LANG_NEUTRAL, 3)) /* FIXME: real name? */
     {
-      	 hRes = getResourceLang(pResDirRet);
+         hRes = getResourceLang(pResDirRet);
     }
     else hRes = getResourceLangEx(pResDirRet, lang);
@@ -181,11 +181,11 @@
  HRSRC                     hRes;
 
-    if(HIWORD(lpszType) != 0 && lpszType[0] != (WCHAR)'#') 
+    if(HIWORD(lpszType) != 0 && lpszType[0] != (WCHAR)'#')
     {
         astring1 = UnicodeToAsciiString(lpszType);
-	typelen = strlen(astring1);
+    typelen = strlen(astring1);
 
         for(int i=0;i<MAX_RES;i++) {
-            if(ResType[i].namelen && 
+            if(ResType[i].namelen &&
                ResType[i].namelen == typelen &&
                stricmp(astring1, ResType[i].typename) == 0)
@@ -195,17 +195,17 @@
              lpszType = (LPWSTR)i;
         }
-	FreeAsciiString(astring1);
+    FreeAsciiString(astring1);
     }
     pResDirRet = getResSubDirW(pResRootDir, lpszType);
     if(!pResDirRet) {
         dprintf2(("FindResourceW %s: resource %x (type %x, lang %x) TYPE NOT FOUND", szModule, lpszName, lpszType, lang));
-	SetLastError(ERROR_RESOURCE_TYPE_NOT_FOUND);
-	return NULL;
+    SetLastError(ERROR_RESOURCE_TYPE_NOT_FOUND);
+    return NULL;
     }
     pResDirRet = getResSubDirW(pResDirRet, lpszName);
     if(!pResDirRet) {
         dprintf2(("FindResourceW %s: resource %x (type %x, lang %x) NAME NOT FOUND", szModule, lpszName, lpszType, lang));
-	SetLastError(ERROR_RESOURCE_NAME_NOT_FOUND);
-	return NULL;
+    SetLastError(ERROR_RESOURCE_NAME_NOT_FOUND);
+    return NULL;
     }
 
@@ -216,5 +216,5 @@
        lang == MAKELANGID(LANG_NEUTRAL, 3)) /* FIXME: real name? */
     {
-      	 hRes = getResourceLang(pResDirRet);
+         hRes = getResourceLang(pResDirRet);
     }
     else hRes = getResourceLangEx(pResDirRet, lang);
@@ -248,25 +248,25 @@
     hRes = (HRSRC)getResDataLang(pResDirToSearch, lang);
     if(!hRes) {
-	/* 2. Neutral language with default sublanguage */
-	lang = MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT);
+    /* 2. Neutral language with default sublanguage */
+    lang = MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT);
         hRes = (HRSRC)getResDataLang(pResDirToSearch, lang);
     }
     if(!hRes) {
-	/* 3. Current locale lang id */
-	lang = LANGIDFROMLCID(GetUserDefaultLCID());
+    /* 3. Current locale lang id */
+    lang = LANGIDFROMLCID(GetUserDefaultLCID());
         hRes = (HRSRC)getResDataLang(pResDirToSearch, lang);
     }
     if(!hRes) {
-	/* 4. Current locale lang id with neutral sublanguage */
-	lang = MAKELANGID(PRIMARYLANGID(lang), SUBLANG_NEUTRAL);
+    /* 4. Current locale lang id with neutral sublanguage */
+    lang = MAKELANGID(PRIMARYLANGID(lang), SUBLANG_NEUTRAL);
         hRes = (HRSRC)getResDataLang(pResDirToSearch, lang);
     }
     if(!hRes) {
-	/* 5. (!) LANG_ENGLISH, SUBLANG_DEFAULT */
-	lang = MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT);
+    /* 5. (!) LANG_ENGLISH, SUBLANG_DEFAULT */
+    lang = MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT);
         hRes = (HRSRC)getResDataLang(pResDirToSearch, lang);
     }
     if(!hRes) {
-	/* 6. Return first in the list */
+    /* 6. Return first in the list */
         hRes = (HRSRC)getResDataLang(pResDirToSearch, lang, TRUE);
     }
@@ -290,16 +290,16 @@
     hRes = (HRSRC)getResDataLang(pResDirToSearch, lang);
     if(!hRes) {
-	/* 2. Language with neutral sublanguage */
+    /* 2. Language with neutral sublanguage */
         lang = MAKELANGID(PRIMARYLANGID(lang), SUBLANG_NEUTRAL);
         hRes = (HRSRC)getResDataLang(pResDirToSearch, lang);
     }
     if(!hRes) {
-	/* 3. Neutral language with neutral sublanguage */
+    /* 3. Neutral language with neutral sublanguage */
         lang = MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL);
         hRes = (HRSRC)getResDataLang(pResDirToSearch, lang);
     }
     if(!hRes) {
-	/* 4. Current locale lang id with neutral sublanguage */
-	lang = MAKELANGID(PRIMARYLANGID(lang), SUBLANG_NEUTRAL);
+    /* 4. Current locale lang id with neutral sublanguage */
+    lang = MAKELANGID(PRIMARYLANGID(lang), SUBLANG_NEUTRAL);
         hRes = (HRSRC)getResDataLang(pResDirToSearch, lang);
     }
@@ -324,5 +324,5 @@
     hRes = findResourceW((LPWSTR)ID_GETFIRST, (LPWSTR)NTRT_VERSION, MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL));
     if(hRes == NULL) {
-	//last error already set by findResourceW
+    //last error already set by findResourceW
         dprintf(("Win32PeLdrImage::getVersionStruct: couldn't find version resource!"));
         return 0;
@@ -397,5 +397,5 @@
  * @author    knut st. osmundsen
  */
-PIMAGE_RESOURCE_DIRECTORY Win32ImageBase::getResSubDirW(PIMAGE_RESOURCE_DIRECTORY pResDirToSearch, 
+PIMAGE_RESOURCE_DIRECTORY Win32ImageBase::getResSubDirW(PIMAGE_RESOURCE_DIRECTORY pResDirToSearch,
                                                         LPCWSTR lpszName)
 {
@@ -405,9 +405,9 @@
 
     if(pResDirToSearch == NULL) {
-	return NULL;
+    return NULL;
     }
 
     if((ULONG)lpszName == -1) {//check for nonsense values
-	return NULL;
+    return NULL;
     }
 
@@ -460,5 +460,5 @@
                 (PIMAGE_RESOURCE_DIR_STRING_U)(paResDirEntries[i].u1.s.NameOffset + (ULONG)pResRootDir /*?*/);
 
-	    //SvL: Must do case insensitive string compare here
+        //SvL: Must do case insensitive string compare here
             if (pResDirStr->Length == cusName
                 && lstrncmpiW(pResDirStr->NameString, lpszName, cusName) == 0)
@@ -485,5 +485,5 @@
  * @author    knut st. osmundsen
  */
-PIMAGE_RESOURCE_DIRECTORY Win32ImageBase::getResSubDirA(PIMAGE_RESOURCE_DIRECTORY pResDirToSearch, 
+PIMAGE_RESOURCE_DIRECTORY Win32ImageBase::getResSubDirA(PIMAGE_RESOURCE_DIRECTORY pResDirToSearch,
                                                         LPCTSTR lpszName)
 {
@@ -492,9 +492,9 @@
 
     if(pResDirToSearch == NULL) {
-	return NULL;
+    return NULL;
     }
 
     if((ULONG)lpszName == -1) {//check for nonsense values
-	return NULL;
+    return NULL;
     }
 
@@ -528,5 +528,5 @@
  */
 //******************************************************************************
-PIMAGE_RESOURCE_DATA_ENTRY 
+PIMAGE_RESOURCE_DATA_ENTRY
      Win32ImageBase::getResDataLang(PIMAGE_RESOURCE_DIRECTORY pResDirToSearch,
                                     ULONG language, BOOL fGetDefault)
@@ -536,5 +536,5 @@
 
     if(pResDirToSearch == NULL) {
-	return NULL;
+    return NULL;
     }
 
@@ -542,13 +542,13 @@
 
     if(pResDirToSearch->NumberOfNamedEntries) {
-	DebugInt3();
+    DebugInt3();
     }
     paResDirEntries += pResDirToSearch->NumberOfNamedEntries;
 
     for (i = 0; i < pResDirToSearch->NumberOfIdEntries; i++) {
-    	if (paResDirEntries[i].u1.Id == language) 
+        if (paResDirEntries[i].u1.Id == language)
         {
-               	return (PIMAGE_RESOURCE_DATA_ENTRY) (paResDirEntries[i].u2.s.OffsetToDirectory + (ULONG)pResRootDir);
-	}
+                return (PIMAGE_RESOURCE_DATA_ENTRY) (paResDirEntries[i].u2.s.OffsetToDirectory + (ULONG)pResRootDir);
+    }
     }
 
@@ -556,11 +556,11 @@
     if(fGetDefault)
     {
-    	return (PIMAGE_RESOURCE_DATA_ENTRY) (paResDirEntries[0].u2.s.OffsetToDirectory + (ULONG)pResRootDir);
-    }
-    return NULL;
-}
-//******************************************************************************
-//******************************************************************************
-BOOL Win32ImageBase::enumResourceTypesA(HMODULE hmod, ENUMRESTYPEPROCA lpEnumFunc, 
+        return (PIMAGE_RESOURCE_DATA_ENTRY) (paResDirEntries[0].u2.s.OffsetToDirectory + (ULONG)pResRootDir);
+    }
+    return NULL;
+}
+//******************************************************************************
+//******************************************************************************
+BOOL Win32ImageBase::enumResourceTypesA(HMODULE hmod, ENUMRESTYPEPROCA lpEnumFunc,
                                         LONG lParam)
 {
@@ -591,25 +591,26 @@
     prde = (PIMAGE_RESOURCE_DIRECTORY_ENTRY)((ULONG)pResRootDir + sizeof(IMAGE_RESOURCE_DIRECTORY));
 
-    for (i=0; i<pResRootDir->NumberOfNamedEntries+pResRootDir->NumberOfIdEntries && fRet; i++) 
-    {
-      	/* locate directory or each resource type */
-    	prdType = (PIMAGE_RESOURCE_DIRECTORY)((int)pResRootDir + (int)prde->u2.OffsetToData);
+    for (i=0; i<pResRootDir->NumberOfNamedEntries+pResRootDir->NumberOfIdEntries && fRet; i++)
+    {
+        /* locate directory or each resource type */
+        prdType = (PIMAGE_RESOURCE_DIRECTORY)((int)pResRootDir + (int)prde->u2.OffsetToData);
 
         if (prde->u1.s.NameIsString)
-    	{//name or id entry?
-	        //SvL: 30-10-'97, high bit is set, so clear to get real offset
-	        nameOffset = prde->u1.Name & ~0x80000000;
-	
-	        pstring = (PIMAGE_RESOURCE_DIR_STRING_U)((ULONG)pResRootDir + nameOffset);
-	        char *typename = (char *)malloc(pstring->Length+1);
-	        lstrcpynWtoA(typename, pstring->NameString, pstring->Length+1);
-	        typename[pstring->Length] = 0;
-
-		fRet = lpEnumFunc(hmod, typename, lParam);
-        	free(typename);
-    	}
-    	else {
-		fRet = lpEnumFunc(hmod, (LPSTR)prde->u1.Id, lParam);
-	}
+        {//name or id entry?
+            //SvL: 30-10-'97, high bit is set, so clear to get real offset
+            nameOffset = prde->u1.Name & ~0x80000000;
+
+            pstring = (PIMAGE_RESOURCE_DIR_STRING_U)((ULONG)pResRootDir + nameOffset);
+            int len = lstrlenWtoA( pstring->NameString, pstring->Length );
+            char *typename = (char *)malloc( len + 1 );
+            lstrcpynWtoA(typename, pstring->NameString, len + 1 );
+            typename[len] = 0;
+
+        fRet = lpEnumFunc(hmod, typename, lParam);
+            free(typename);
+        }
+        else {
+        fRet = lpEnumFunc(hmod, (LPSTR)prde->u1.Id, lParam);
+    }
 
         /* increment to next entry */
@@ -620,5 +621,5 @@
 //******************************************************************************
 //******************************************************************************
-BOOL Win32ImageBase::enumResourceTypesW(HMODULE hmod, ENUMRESTYPEPROCW lpEnumFunc, 
+BOOL Win32ImageBase::enumResourceTypesW(HMODULE hmod, ENUMRESTYPEPROCW lpEnumFunc,
                                         LONG lParam)
 {
@@ -650,25 +651,25 @@
     prde = (PIMAGE_RESOURCE_DIRECTORY_ENTRY)((ULONG)pResRootDir + sizeof(IMAGE_RESOURCE_DIRECTORY));
 
-    for (i=0; i<pResRootDir->NumberOfNamedEntries+pResRootDir->NumberOfIdEntries && fRet; i++) 
-    {
-      	/* locate directory or each resource type */
-    	prdType = (PIMAGE_RESOURCE_DIRECTORY)((int)pResRootDir + (int)prde->u2.OffsetToData);
+    for (i=0; i<pResRootDir->NumberOfNamedEntries+pResRootDir->NumberOfIdEntries && fRet; i++)
+    {
+        /* locate directory or each resource type */
+        prdType = (PIMAGE_RESOURCE_DIRECTORY)((int)pResRootDir + (int)prde->u2.OffsetToData);
 
         if (prde->u1.s.NameIsString)
-    	{//name or id entry?
-	        //SvL: 30-10-'97, high bit is set, so clear to get real offset
-	        nameOffset = prde->u1.Name & ~0x80000000;
-	
-	        pstring = (PIMAGE_RESOURCE_DIR_STRING_U)((ULONG)pResRootDir + nameOffset);
-
-		lpszType = (LPWSTR)malloc((pstring->Length+1) * sizeof(WCHAR));
+        {//name or id entry?
+            //SvL: 30-10-'97, high bit is set, so clear to get real offset
+            nameOffset = prde->u1.Name & ~0x80000000;
+
+            pstring = (PIMAGE_RESOURCE_DIR_STRING_U)((ULONG)pResRootDir + nameOffset);
+
+        lpszType = (LPWSTR)malloc((pstring->Length+1) * sizeof(WCHAR));
                 memcpy(lpszType, pstring->NameString, pstring->Length * sizeof(WCHAR));
                 lpszType[pstring->Length] = 0;
 
-		fRet = lpEnumFunc(hmod, pstring->NameString, lParam);
-
-		free(lpszType);
-    	}
-    	else 	fRet = lpEnumFunc(hmod, (LPWSTR)prde->u1.Id, lParam);
+        fRet = lpEnumFunc(hmod, pstring->NameString, lParam);
+
+        free(lpszType);
+        }
+        else    fRet = lpEnumFunc(hmod, (LPWSTR)prde->u1.Id, lParam);
 
         /* increment to next entry */
@@ -776,6 +777,8 @@
                     pszASCII = (char*)pszTmp;
                 }
-		lstrcpynWtoA(pszASCII, pResDirString->NameString, pResDirString->Length+1);
-		pszASCII[pResDirString->Length] = 0;
+
+                int len = lstrlenWtoA( pResDirString->NameString, pResDirString->Length );
+                lstrcpynWtoA(pszASCII, pResDirString->NameString, len + 1);
+                pszASCII[len] = 0;
                 lpszName = pszASCII;
             }
@@ -879,15 +882,15 @@
             LPWSTR lpszName, lpszResName;
 
-            if(paResDirEntries[i].u1.s.NameIsString) 
+            if(paResDirEntries[i].u1.s.NameIsString)
             {
                 lpszName = (LPWSTR)(paResDirEntries[i].u1.s.NameOffset + (ULONG)pResRootDir + 2);
                 length   = (int)*(LPWSTR)(paResDirEntries[i].u1.s.NameOffset + (ULONG)pResRootDir);
 
-       		lpszResName = (LPWSTR)malloc((length+1) * sizeof(WCHAR));
+            lpszResName = (LPWSTR)malloc((length+1) * sizeof(WCHAR));
                 memcpy(lpszResName, lpszName, length * sizeof(WCHAR));
                 lpszResName[length] = 0;
 
                 fRet = lpEnumFunc(hmod, lpszType, lpszResName, lParam);
-		free(lpszResName);
+        free(lpszResName);
             }
             else {
@@ -907,7 +910,7 @@
 //******************************************************************************
 //******************************************************************************
-BOOL Win32ImageBase::enumResourceLanguagesA(HMODULE hmod, LPCSTR lpszType, 
-                                            LPCSTR lpszName, 
-                                            ENUMRESLANGPROCA lpEnumFunc, 
+BOOL Win32ImageBase::enumResourceLanguagesA(HMODULE hmod, LPCSTR lpszType,
+                                            LPCSTR lpszName,
+                                            ENUMRESLANGPROCA lpEnumFunc,
                                             LONG lParam)
 {
@@ -930,24 +933,24 @@
     pResDirRet = getResSubDirA(pResRootDir, lpszType);
     if(!pResDirRet) {
-	SetLastError(ERROR_RESOURCE_TYPE_NOT_FOUND);
-	return FALSE;
+    SetLastError(ERROR_RESOURCE_TYPE_NOT_FOUND);
+    return FALSE;
     }
     pResDirRet = getResSubDirA(pResDirRet, lpszName);
     if(!pResDirRet) {
-	SetLastError(ERROR_RESOURCE_NAME_NOT_FOUND);
-	return FALSE;
+    SetLastError(ERROR_RESOURCE_NAME_NOT_FOUND);
+    return FALSE;
     }
 
     paResDirEntries = (PIMAGE_RESOURCE_DIRECTORY_ENTRY)((ULONG)pResDirRet + sizeof(*pResDirRet));
     if(pResDirRet->NumberOfNamedEntries) {
-	DebugInt3();
+    DebugInt3();
     }
     paResDirEntries += pResDirRet->NumberOfNamedEntries;
 
-    for(int i = 0;i < pResDirRet->NumberOfIdEntries;i++) 
-    {
-	fRet = lpEnumFunc(hmod, lpszType, lpszName, paResDirEntries[i].u1.Id, lParam);
-	if(!fRet)
-		break;
+    for(int i = 0;i < pResDirRet->NumberOfIdEntries;i++)
+    {
+    fRet = lpEnumFunc(hmod, lpszType, lpszName, paResDirEntries[i].u1.Id, lParam);
+    if(!fRet)
+        break;
     }
     return fRet;
@@ -955,7 +958,7 @@
 //******************************************************************************
 //******************************************************************************
-BOOL Win32ImageBase::enumResourceLanguagesW(HMODULE hmod, LPCWSTR lpszType, 
-                                            LPCWSTR lpszName, 
-                                            ENUMRESLANGPROCW lpEnumFunc, 
+BOOL Win32ImageBase::enumResourceLanguagesW(HMODULE hmod, LPCWSTR lpszType,
+                                            LPCWSTR lpszName,
+                                            ENUMRESLANGPROCW lpEnumFunc,
                                             LONG lParam)
 {
@@ -978,24 +981,24 @@
     pResDirRet = getResSubDirW(pResRootDir, lpszType);
     if(!pResDirRet) {
-	SetLastError(ERROR_RESOURCE_TYPE_NOT_FOUND);
-	return FALSE;
+    SetLastError(ERROR_RESOURCE_TYPE_NOT_FOUND);
+    return FALSE;
     }
     pResDirRet = getResSubDirW(pResDirRet, lpszName);
     if(!pResDirRet) {
-	SetLastError(ERROR_RESOURCE_NAME_NOT_FOUND);
-	return FALSE;
+    SetLastError(ERROR_RESOURCE_NAME_NOT_FOUND);
+    return FALSE;
     }
 
     paResDirEntries = (PIMAGE_RESOURCE_DIRECTORY_ENTRY)((ULONG)pResDirRet + sizeof(*pResDirRet));
     if(pResDirRet->NumberOfNamedEntries) {
-	DebugInt3();
+    DebugInt3();
     }
     paResDirEntries += pResDirRet->NumberOfNamedEntries;
 
-    for(int i = 0;i < pResDirRet->NumberOfIdEntries;i++) 
-    {
-	fRet = lpEnumFunc(hmod, lpszType, lpszName, paResDirEntries[i].u1.Id, lParam);
-	if(!fRet)
-		break;
+    for(int i = 0;i < pResDirRet->NumberOfIdEntries;i++)
+    {
+    fRet = lpEnumFunc(hmod, lpszType, lpszName, paResDirEntries[i].u1.Id, lParam);
+    if(!fRet)
+        break;
     }
     return fRet;
