Index: trunk/src/kernel32/cpu.cpp
===================================================================
--- trunk/src/kernel32/cpu.cpp	(revision 1837)
+++ trunk/src/kernel32/cpu.cpp	(revision 1838)
@@ -1,3 +1,3 @@
-/* $Id: cpu.cpp,v 1.2 1999-11-23 20:01:17 sandervl Exp $ */
+/* $Id: cpu.cpp,v 1.3 1999-11-25 19:19:57 sandervl Exp $ */
 /*
  * Odin win32 CPU apis
@@ -26,4 +26,10 @@
 static BYTE PF[64] = {0,};
 static nrCPUs = 1;
+static HINSTANCE hInstance = 0;
+
+LONG (WINAPI *ADVAPI32_RegCloseKey)(HKEY) = 0;
+LONG (WINAPI *ADVAPI32_RegCreateKeyA)(HKEY,LPCSTR,LPHKEY) = 0;
+LONG (WINAPI *ADVAPI32_RegSetValueExA)(HKEY,LPSTR,DWORD,DWORD,LPBYTE,DWORD) = 0;
+
 //******************************************************************************
 //******************************************************************************
@@ -31,4 +37,11 @@
 {
   SYSTEM_INFO si;
+
+   hInstance = LoadLibraryA("ADVAPI32.DLL");
+   if(hInstance) {
+    	*(VOID **)&ADVAPI32_RegCloseKey=(void*)GetProcAddress(hInstance, (LPCSTR)"RegCloseKey");
+        *(VOID **)&ADVAPI32_RegCreateKeyA=(void*)GetProcAddress(hInstance, (LPCSTR)"RegCreateKeyA");
+        *(VOID **)&ADVAPI32_RegSetValueExA=(void*)GetProcAddress(hInstance, (LPCSTR)"RegSetValueExA");
+   }
 
    nrCPUs = nrcpus;
@@ -97,5 +110,5 @@
 
         /* Create this registry key for all systems */
-	if (RegCreateKeyA(HKEY_LOCAL_MACHINE,"HARDWARE\\DESCRIPTION\\System\\CentralProcessor",&hkey)!=ERROR_SUCCESS) {
+	if (ADVAPI32_RegCreateKeyA(HKEY_LOCAL_MACHINE,"HARDWARE\\DESCRIPTION\\System\\CentralProcessor",&hkey)!=ERROR_SUCCESS) {
             dprintf(("Unable to register CPU information\n"));
         }
@@ -108,6 +121,6 @@
 		sprintf(buf,"%d",i);
 		if (xhkey)
-			RegCloseKey(xhkey);
-		RegCreateKeyA(hkey,buf,&xhkey);
+			ADVAPI32_RegCloseKey(xhkey);
+		ADVAPI32_RegCreateKeyA(hkey,buf,&xhkey);
 
 	 	signature = GetCPUSignature();
@@ -132,8 +145,8 @@
 		sprintf(buf,"CPU %ld",cachedsi.dwProcessorType);
 		if (xhkey) {
-			RegSetValueExA(xhkey,"Identifier",0,REG_SZ,(LPBYTE)buf,strlen(buf));
+			ADVAPI32_RegSetValueExA(xhkey,"Identifier",0,REG_SZ,(LPBYTE)buf,strlen(buf));
 			memset(buf, 0, sizeof(buf));
 			GetCPUVendorString(buf);
-			RegSetValueExA(xhkey,"VendorIdentifier",0,REG_SZ,(LPBYTE)buf,strlen(buf));
+			ADVAPI32_RegSetValueExA(xhkey,"VendorIdentifier",0,REG_SZ,(LPBYTE)buf,strlen(buf));
 		}
 		cachedsi.wProcessorRevision = signature & 0xf;
@@ -157,5 +170,5 @@
 		if (features & CPUID_FPU_PRESENT) {
 			if (i == 0) {
-				if(RegCreateKeyA(HKEY_LOCAL_MACHINE,"HARDWARE\\DESCRIPTION\\System\\FloatingPointProcessor",&fpukey)!=ERROR_SUCCESS) 
+				if(ADVAPI32_RegCreateKeyA(HKEY_LOCAL_MACHINE,"HARDWARE\\DESCRIPTION\\System\\FloatingPointProcessor",&fpukey)!=ERROR_SUCCESS) 
             				dprintf(("Unable to register FPU information\n"));
         		}
@@ -163,5 +176,5 @@
 			if(fpukey) {
 				sprintf(buf,"%d",i);
-				RegCreateKeyA(fpukey,buf,&xhfpukey);
+				ADVAPI32_RegCreateKeyA(fpukey,buf,&xhfpukey);
 			}
 		}
@@ -172,11 +185,11 @@
 
 	if (xhkey)
-		RegCloseKey(xhkey);
+		ADVAPI32_RegCloseKey(xhkey);
 	if (hkey)
-		RegCloseKey(hkey);
+		ADVAPI32_RegCloseKey(hkey);
 	if (xhfpukey)
-		RegCloseKey(xhfpukey);
+		ADVAPI32_RegCloseKey(xhfpukey);
 	if (fpukey)
-		RegCloseKey(fpukey);
+		ADVAPI32_RegCloseKey(fpukey);
 
 }
Index: trunk/src/kernel32/makefile
===================================================================
--- trunk/src/kernel32/makefile	(revision 1837)
+++ trunk/src/kernel32/makefile	(revision 1838)
@@ -1,3 +1,3 @@
-# $Id: makefile,v 1.61 1999-11-24 19:31:23 sandervl Exp $
+# $Id: makefile,v 1.62 1999-11-25 19:19:57 sandervl Exp $
 
 #
@@ -74,5 +74,4 @@
 $(PDWIN32_LIB)\LIBCONV.LIB
 $(PDWIN32_LIB)\odincrt.lib
-$(PDWIN32_LIB)\advapi32.lib
 OS2386.LIB
 $(RTLLIB_O)
Index: trunk/src/kernel32/unicode.cpp
===================================================================
--- trunk/src/kernel32/unicode.cpp	(revision 1837)
+++ trunk/src/kernel32/unicode.cpp	(revision 1838)
@@ -1,3 +1,3 @@
-/* $Id: unicode.cpp,v 1.14 1999-09-13 09:06:05 sandervl Exp $ */
+/* $Id: unicode.cpp,v 1.15 1999-11-25 19:19:57 sandervl Exp $ */
 
 /*
@@ -41,62 +41,151 @@
 }
 
-//******************************************************************************
-//Not identical, but close enough
-//******************************************************************************
-int WIN32API MultiByteToWideChar(UINT uCodePage, DWORD dwFlags, LPCSTR lpMultiByteStr,
-                                   int  cchMultiByte, LPWSTR lpWideCharStr, int cchWideChar)
-{
- int i, len;
-
-//  dprintf(("MultiByteToWideChar %s\n", lpMultiByteStr));
-
-  if((int)lpMultiByteStr == (int)lpWideCharStr) {//not allowed
-        SetLastError(ERROR_INVALID_PARAMETER);
-        return(FALSE);
-  }
-  if(cchWideChar == 0) {//return space required for conversion
-        if(cchMultiByte == -1)
-            cchMultiByte = strlen(lpMultiByteStr) + 1;
-        return(cchMultiByte);   //return length in wide chars
-  }
-  if(cchMultiByte == -1)
-        cchMultiByte = strlen(lpMultiByteStr) + 1;
-
-  len = min(cchWideChar, cchMultiByte);
-  for(i=0;i<=len;i++) { //including 0 terminator
-        lpWideCharStr[i] = lpMultiByteStr[i];
-  }
-  return(len);
-}
-//******************************************************************************
-//******************************************************************************
-//Not identical, close enough
-//Forget about characters that can't be mapped; just do it
-//******************************************************************************
-int WIN32API WideCharToMultiByte(UINT uCodePage, DWORD dwFlags, LPCWSTR lpWideCharStr,
-                                   int cchWideChar, LPSTR lpMultiByteStr,
-                                   int cchMultiByte, LPCSTR lpDefaultChar,
-                                   LPBOOL lpfUsedDefaultChar)
-{
- int i, len;
-
-//  dprintf(("WideCharToMultiByte\n"));
-
-  if((int)lpMultiByteStr == (int)lpWideCharStr) {//not allowed
-        SetLastError(ERROR_INVALID_PARAMETER);
-        return(FALSE);
-  }
-  if(cchMultiByte == 0) {//return space required for conversion
-        if(cchWideChar == -1)   cchWideChar = UniStrlen((UniChar *)lpWideCharStr);
-        return(cchWideChar);
-  }
-  if(cchWideChar == -1)
-        cchWideChar = UniStrlen((UniChar*)lpWideCharStr);
-
-  len = min(cchWideChar, cchMultiByte);
-  for(i=0;i<=len;i++) { //including 0 terminator
-        lpMultiByteStr[i] = (UCHAR)lpWideCharStr[i];
-  }
-  return(len);
+/***********************************************************************
+ *              MultiByteToWideChar                (KERNEL32.534)
+ *
+ * PARAMS
+ *   page [in]   Codepage character set to convert from
+ *   flags [in]  Character mapping flags
+ *   src [in]     Source string buffer
+ *   srclen [in]  Length of source string buffer
+ *   dst [in]     Destination buffer
+ *   dstlen [in]  Length of destination buffer
+ *
+ * NOTES
+ *   The returned length includes the null terminator character.
+ *
+ * RETURNS
+ *   Success: If dstlen > 0, number of characters written to destination
+ *            buffer.  If dstlen == 0, number of characters needed to do
+ *            conversion.
+ *   Failure: 0. Occurs if not enough space is available.
+ *
+ * ERRORS
+ *   ERROR_INSUFFICIENT_BUFFER
+ *   ERROR_INVALID_FLAGS (not yet implemented)
+ *   ERROR_INVALID_PARAMETER (not yet implemented)
+ *
+ * BUGS
+ *   Does not properly handle codepage conversions.
+ *   Does not properly handle flags.
+ *
+ */
+INT WINAPI MultiByteToWideChar(UINT page, DWORD flags,
+			         LPCSTR src, INT srclen,
+                                 LPWSTR dst, INT dstlen)
+{
+    int ret;
+
+    if (srclen == -1)
+	srclen = lstrlenA(src)+1;
+    if (!dstlen || !dst)
+	return srclen;
+
+    ret = srclen;
+    while (srclen && dstlen) {
+	*dst = (WCHAR)(unsigned char)*src;
+	dst++;    src++;
+	dstlen--; srclen--;
+    }
+    if (!dstlen && srclen) {
+	SetLastError(ERROR_INSUFFICIENT_BUFFER);
+	return 0;
+    }
+    return ret;
+}
+
+/***********************************************************************
+ *              WideCharToMultiByte                (KERNEL32.727)
+ *
+ * PARAMS
+ *   page [in]    Codepage character set to convert to
+ *   flags [in]   Character mapping flags
+ *   src [in]     Source string buffer
+ *   srclen [in]  Length of source string buffer
+ *   dst [in]     Destination buffer
+ *   dstlen [in]  Length of destination buffer
+ *   defchar [in] Default character to use for conversion if no exact
+ *		    conversion can be made
+ *   used [out]   Set if default character was used in the conversion
+ *
+ * NOTES
+ *   The returned length includes the null terminator character.
+ *
+ * RETURNS
+ *   Success: If dstlen > 0, number of characters written to destination
+ *            buffer.  If dstlen == 0, number of characters needed to do
+ *            conversion.
+ *   Failure: 0. Occurs if not enough space is available.
+ *
+ * ERRORS
+ *   ERROR_INSUFFICIENT_BUFFER
+ *   ERROR_INVALID_FLAGS (not yet implemented)
+ *
+ * BUGS
+ *   Does not properly handle codepage conversions.
+ *   Does not properly handle flags.
+ *
+ */
+INT WIN32API WideCharToMultiByte(UINT page, DWORD flags, LPCWSTR src,
+				 INT srclen,LPSTR dst, INT dstlen,
+				 LPCSTR defchar, BOOL *used)
+{
+    int count = 0;
+    int eos = 0;
+    int care_for_eos=0;
+    int dont_copy= (dstlen==0);
+
+    if ((!src) || ((!dst) && (!dont_copy)) )
+    {	SetLastError(ERROR_INVALID_PARAMETER);
+	return 0;
+    }
+    
+    if (page!=GetACP() && page!=CP_OEMCP && page!=CP_ACP)
+	dprintf(("WideCharToMultiByte, Conversion in CP %d not supported\n",page));
+#if 0
+    if (flags)
+	dprintf(("WideCharToMultiByte, flags %lx not supported\n",flags));
+#endif
+    if(used)
+	*used=0;
+    if (srclen == -1)
+      {
+	srclen = lstrlenW(src)+1;
+	 care_for_eos=1;
+      }
+    while(srclen && (dont_copy || dstlen))
+    {
+	if(!dont_copy){
+	    if(*src<256)
+		*dst = *src;
+	    else
+	    {
+		/* ??? The WC_DEFAULTCHAR flag only gets used in
+		 * combination with the WC_COMPOSITECHECK flag or at
+		 * least this is what it seems from using the function
+		 * on NT4.0 in combination with reading the documentation.
+		 */
+		*dst = defchar ? *defchar : '?';
+		if(used)*used=1;
+	    }
+	    dstlen--;
+	    dst++;
+	}
+	count++;
+	srclen--;
+	if((!*src) && care_for_eos) {
+	    eos = 1;
+	    break;
+	}
+	src++;
+    }
+    if (dont_copy)
+	return count;
+
+    if (!eos && srclen > 0) {
+	SetLastError(ERROR_INSUFFICIENT_BUFFER);
+	return 0;
+    }
+    return count;
 }
 //******************************************************************************
