Small dll separation fixes.

diff --git a/dlls/user/user_main.c b/dlls/user/user_main.c
index 52c094d..684edff 100644
--- a/dlls/user/user_main.c
+++ b/dlls/user/user_main.c
@@ -30,6 +30,8 @@
 
 WINE_LOOK TWEAK_WineLook = WIN31_LOOK;
 
+WORD USER_HeapSel = 0;  /* USER heap selector */
+
 static HMODULE graphics_driver;
 
 #define GET_USER_FUNC(name) \
@@ -43,16 +45,13 @@
     HKEY hkey;
     DWORD type, count;
 
-    if (RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\Wine", 0, NULL,
-                         REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, NULL ))
+    strcpy( buffer, "x11drv" );  /* default value */
+    if (!RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\Wine", &hkey ))
     {
-        MESSAGE("load_driver: Cannot create config registry key\n" );
-        return FALSE;
+        count = sizeof(buffer);
+        RegQueryValueExA( hkey, "GraphicsDriver", 0, &type, buffer, &count );
+        RegCloseKey( hkey );
     }
-    count = sizeof(buffer);
-    if (RegQueryValueExA( hkey, "GraphicsDriver", 0, &type, buffer, &count ))
-        strcpy( buffer, "x11drv" );  /* default value */
-    RegCloseKey( hkey );
 
     if (!(graphics_driver = LoadLibraryA( buffer )))
     {
@@ -163,8 +162,7 @@
     HKEY hkey;
     DWORD type, count = sizeof(buffer);
 
-    if (RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\Tweak.Layout", 0, NULL,
-                         REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, NULL ))
+    if (RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\Tweak.Layout", &hkey ))
         return;
     if (RegQueryValueExA( hkey, "WineLook", 0, &type, buffer, &count ))
         strcpy( buffer, "Win31" );  /* default value */
@@ -197,7 +195,7 @@
 
     /* Create USER heap */
     if ((instance = LoadLibrary16( "USER.EXE" )) < 32) return FALSE;
-    USER_HeapSel = GlobalHandleToSel16( instance );
+    USER_HeapSel = instance | 7;
 
      /* Global atom table initialisation */
     if (!ATOM_Init( USER_HeapSel )) return FALSE;
diff --git a/files/profile.c b/files/profile.c
index aec6153..b198dca 100644
--- a/files/profile.c
+++ b/files/profile.c
@@ -6,6 +6,7 @@
  */
 
 #include <ctype.h>
+#include <errno.h>
 #include <fcntl.h>
 #include <stdlib.h>
 #include <string.h>
@@ -271,7 +272,7 @@
 }
 
 /* convert the .winerc file to the new format */
-static int convert_config( FILE *in, const char *output_name )
+static void convert_config( FILE *in, const char *output_name )
 {
     char buffer[PROFILE_MAX_LINE_LEN];
     char *p, *p2;
@@ -279,7 +280,11 @@
 
     /* create the output file, only if it doesn't exist already */
     int fd = open( output_name, O_WRONLY|O_CREAT|O_EXCL, 0666 );
-    if (fd == -1) return 0;
+    if (fd == -1)
+    {
+        MESSAGE( "Could not create new config file '%s': %s\n", output_name, strerror(errno) );
+        ExitProcess(1);
+    }
 
     out = fdopen( fd, "w" );
     fprintf( out, "WINE REGISTRY Version 2\n" );
@@ -342,71 +347,6 @@
         fprintf( out, "\"\n" );
     }
     fclose( out );
-    return 1;
-}
-
-
-/***********************************************************************
- *           PROFILE_RegistryLoad
- *
- * Load a profile tree from a file into a registry key.
- */
-static DWORD PROFILE_RegistryLoad( HKEY root, FILE *file )
-{
-    HKEY hkey = 0;
-    DWORD err = 0;
-    char buffer[PROFILE_MAX_LINE_LEN];
-    char *p, *p2;
-    int line = 0;
-
-    while (fgets( buffer, PROFILE_MAX_LINE_LEN, file ))
-    {
-        line++;
-        p = buffer;
-        while (*p && PROFILE_isspace(*p)) p++;
-        if (*p == '[')  /* section start */
-        {
-            if (!(p2 = strrchr( p, ']' )))
-            {
-                WARN("Invalid section header at line %d: '%s'\n",
-		     line, p );
-            }
-            else
-            {
-                *p2 = '\0';
-                p++;
-                if (hkey) RegCloseKey( hkey );
-                if ((err = RegCreateKeyExA( root, p, 0, NULL, REG_OPTION_VOLATILE,
-                                            KEY_ALL_ACCESS, NULL, &hkey, NULL ))) return err;
-                TRACE("New section: '%s'\n",p);
-                continue;
-            }
-        }
-
-        p2=p+strlen(p) - 1;
-        while ((p2 > p) && ((*p2 == '\n') || PROFILE_isspace(*p2))) *p2--='\0';
-
-        if ((p2 = strchr( p, '=' )) != NULL)
-        {
-            char *p3 = p2 - 1;
-            while ((p3 > p) && PROFILE_isspace(*p3)) *p3-- = '\0';
-            *p2++ = '\0';
-            while (*p2 && PROFILE_isspace(*p2)) p2++;
-        }
-
-        if (*p && hkey && !IS_ENTRY_COMMENT(p))
-        {
-            if (!p2) p2 = "";
-            if ((err = RegSetValueExA( hkey, p, 0, REG_SZ, p2, strlen(p2)+1 )))
-            {
-                RegCloseKey( hkey );
-                return err;
-            }
-            TRACE("New key: name='%s', value='%s'\n",p,p2);
-        }
-    }
-    if (hkey) RegCloseKey( hkey );
-    return 0;
 }
 
 
@@ -1067,25 +1007,39 @@
  */
 int PROFILE_LoadWineIni(void)
 {
+    OBJECT_ATTRIBUTES attr;
+    UNICODE_STRING nameW;
     char buffer[MAX_PATHNAME_LEN];
     const char *p;
     FILE *f;
     HKEY hKeySW;
     DWORD disp;
 
+    attr.Length = sizeof(attr);
+    attr.RootDirectory = 0;
+    attr.ObjectName = &nameW;
+    attr.Attributes = 0;
+    attr.SecurityDescriptor = NULL;
+    attr.SecurityQualityOfService = NULL;
+
     /* make sure HKLM\\Software\\Wine\\Wine exists as non-volatile key */
-    if (RegCreateKeyA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine", &hKeySW ))
+    if (!RtlCreateUnicodeStringFromAsciiz( &nameW, "Machine\\Software\\Wine\\Wine" ) ||
+        NtCreateKey( &hKeySW, KEY_ALL_ACCESS, &attr, 0, NULL, 0, &disp ))
     {
         ERR("Cannot create config registry key\n" );
-        return 0;
+        ExitProcess( 1 );
     }
-    RegCloseKey( hKeySW );
-    if (RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config", 0, NULL,
-                         REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &wine_profile_key, &disp ))
+    RtlFreeUnicodeString( &nameW );
+    NtClose( hKeySW );
+
+    if (!RtlCreateUnicodeStringFromAsciiz( &nameW, "Machine\\Software\\Wine\\Wine\\Config" ) ||
+        NtCreateKey( &wine_profile_key, KEY_ALL_ACCESS, &attr, 0,
+                     NULL, REG_OPTION_VOLATILE, &disp ))
     {
         ERR("Cannot create config registry key\n" );
-        return 0;
+        ExitProcess( 1 );
     }
+    RtlFreeUnicodeString( &nameW );
 
     if (!CLIENT_IsBootThread()) return 1;  /* already loaded */
 
@@ -1118,18 +1072,14 @@
 
     /* convert to the new format */
     sprintf( buffer, "%s/config", get_config_dir() );
-    if (convert_config( f, buffer ))
-    {
-        MESSAGE( "The '%s' configuration file has been converted\n"
-                 "to the new format and saved as '%s'.\n", PROFILE_WineIniUsed, buffer );
-        MESSAGE( "You should verify that the contents of the new file are correct,\n"
-                 "and then remove the old one and restart Wine.\n" );
-        ExitProcess(0);
-    }
-
-    PROFILE_RegistryLoad( wine_profile_key, f );
+    convert_config( f, buffer );
     fclose( f );
-    return 1;
+
+    MESSAGE( "The '%s' configuration file has been converted\n"
+             "to the new format and saved as '%s'.\n", PROFILE_WineIniUsed, buffer );
+    MESSAGE( "You should verify that the contents of the new file are correct,\n"
+             "and then remove the old one and restart Wine.\n" );
+    ExitProcess(0);
 }
 
 
diff --git a/memory/local.c b/memory/local.c
index b9f025d..b43ff4e 100644
--- a/memory/local.c
+++ b/memory/local.c
@@ -116,8 +116,6 @@
 
 #define LOCAL_HEAP_MAGIC  0x484c  /* 'LH' */
 
-WORD USER_HeapSel = 0;  /* USER heap selector */
-
   /* All local heap allocations are aligned on 4-byte boundaries */
 #define LALIGN(word)          (((word) + 3) & ~3)
 
diff --git a/objects/gdiobj.c b/objects/gdiobj.c
index 73730af..cdd7f39 100644
--- a/objects/gdiobj.c
+++ b/objects/gdiobj.c
@@ -320,7 +320,7 @@
 
     /* create GDI heap */
     if ((instance = LoadLibrary16( "GDI.EXE" )) < 32) return FALSE;
-    GDI_HeapSel = GlobalHandleToSel16( instance );
+    GDI_HeapSel = instance | 7;
 
     /* TWEAK: Initialize font hints */
     ReadFontInformation("OEMFixed", &OEMFixedFont, 0, 0, 0, 0, 0);
diff --git a/objects/metafile.c b/objects/metafile.c
index 330cd86..2e1c2ca 100644
--- a/objects/metafile.c
+++ b/objects/metafile.c
@@ -599,7 +599,7 @@
 		     sizeof(HANDLETABLE16) * mh->mtNoObjects);
     spht = K32WOWGlobalLock16(hHT);
    
-    seg = GlobalHandleToSel16(hmf);
+    seg = hmf | 7;
     offset = mh->mtHeaderSize * 2;
     
     /* loop through metafile records */
diff --git a/windows/user.c b/windows/user.c
index beeb644..053eb16 100644
--- a/windows/user.c
+++ b/windows/user.c
@@ -44,7 +44,7 @@
     int userPercent, gdiPercent;
 
     if ((gdi_inst = LoadLibrary16( "GDI" )) < 32) return 0;
-    gdi_heap = GlobalHandleToSel16( gdi_inst );
+    gdi_heap = gdi_inst | 7;
 
     switch(resType)
     {