Moved SystemHeap allocations to the process heap.

diff --git a/dlls/advapi32/security.c b/dlls/advapi32/security.c
index d98fe65..8a5d11f 100644
--- a/dlls/advapi32/security.c
+++ b/dlls/advapi32/security.c
@@ -733,7 +733,7 @@
 	{
 	  case PolicyAuditEventsInformation: /* 2 */
 	    {
-	      PPOLICY_AUDIT_EVENTS_INFO p = HeapAlloc(SystemHeap, HEAP_ZERO_MEMORY, sizeof(POLICY_AUDIT_EVENTS_INFO));
+	      PPOLICY_AUDIT_EVENTS_INFO p = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(POLICY_AUDIT_EVENTS_INFO));
 	      p->AuditingMode = FALSE; /* no auditing */
 	      *Buffer = p;
 	    }
@@ -747,7 +747,7 @@
 	      };
 	      SID_IDENTIFIER_AUTHORITY localSidAuthority = {SECURITY_NT_AUTHORITY};
 		
-	      struct di * xdi = HeapAlloc(SystemHeap, HEAP_ZERO_MEMORY, sizeof(xdi));
+	      struct di * xdi = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(xdi));
 	      RtlInitUnicodeString(&(xdi->ppdi.Name), HEAP_strdupAtoW(GetProcessHeap(),0,"DOMAIN"));
 	      xdi->ppdi.Sid = &(xdi->sid);
 	      xdi->sid.Revision = SID_REVISION;
@@ -816,7 +816,7 @@
 LsaFreeMemory(IN PVOID Buffer)
 {
 	TRACE("(%p)\n",Buffer);
-	return HeapFree(SystemHeap, 0, Buffer);
+	return HeapFree(GetProcessHeap(), 0, Buffer);
 }
 /******************************************************************************
  * LsaClose [ADVAPI32.243]
diff --git a/dlls/lzexpand/lzexpand_main.c b/dlls/lzexpand/lzexpand_main.c
index 143a459..06fb1ea 100644
--- a/dlls/lzexpand/lzexpand_main.c
+++ b/dlls/lzexpand/lzexpand_main.c
@@ -177,7 +177,7 @@
 	}
         for (i = 0; i < MAX_LZSTATES; i++) if (!lzstates[i]) break;
         if (i == MAX_LZSTATES) return LZERROR_GLOBALLOC;
-	lzstates[i] = lzs = HeapAlloc( SystemHeap, 0, sizeof(struct lzstate) );
+	lzstates[i] = lzs = HeapAlloc( GetProcessHeap(), 0, sizeof(struct lzstate) );
 
 	memset(lzs,'\0',sizeof(*lzs));
 	lzs->realfd	= hfSrc;
@@ -637,7 +637,7 @@
             if (lzs->get) HeapFree( GetProcessHeap(), 0, lzs->get );
             CloseHandle(lzs->realfd);
             lzstates[fd - 0x400] = NULL;
-            HeapFree( SystemHeap, 0, lzs );
+            HeapFree( GetProcessHeap(), 0, lzs );
         }
 }
 
diff --git a/dlls/mpr/mpr_main.c b/dlls/mpr/mpr_main.c
index 6d136df..eb306a7 100644
--- a/dlls/mpr/mpr_main.c
+++ b/dlls/mpr/mpr_main.c
@@ -18,7 +18,7 @@
  */
 LPVOID WINAPI MPR_Alloc( DWORD dwSize )
 {
-    return HeapAlloc( SystemHeap, HEAP_ZERO_MEMORY, dwSize );
+    return HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, dwSize );
 }
 
 /*****************************************************************
@@ -27,9 +27,9 @@
 LPVOID WINAPI MPR_ReAlloc( LPVOID lpSrc, DWORD dwSize )
 {
     if ( lpSrc )
-        return HeapReAlloc( SystemHeap, HEAP_ZERO_MEMORY, lpSrc, dwSize );
+        return HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, lpSrc, dwSize );
     else
-        return HeapAlloc( SystemHeap, HEAP_ZERO_MEMORY, dwSize );
+        return HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, dwSize );
 }
 
 /*****************************************************************
@@ -38,7 +38,7 @@
 BOOL WINAPI MPR_Free( LPVOID lpMem )
 {
     if ( lpMem )
-        return HeapFree( SystemHeap, 0, lpMem );
+        return HeapFree( GetProcessHeap(), 0, lpMem );
     else
         return FALSE;
 }
diff --git a/dlls/winaspi/winaspi16.c b/dlls/winaspi/winaspi16.c
index 9800b35..48f1d43 100644
--- a/dlls/winaspi/winaspi16.c
+++ b/dlls/winaspi/winaspi16.c
@@ -80,7 +80,7 @@
     }
 
     /* device is now open */
-    curr = HeapAlloc( SystemHeap, 0, sizeof(ASPI_DEVICE_INFO) );
+    curr = HeapAlloc( GetProcessHeap(), 0, sizeof(ASPI_DEVICE_INFO) );
     curr->fd = fd;
     curr->hostId = prb->SRB_HaId;
     curr->target = prb->SRB_Target;
diff --git a/dlls/winmm/lolvldrv.c b/dlls/winmm/lolvldrv.c
index c5edc24..bf87a50 100644
--- a/dlls/winmm/lolvldrv.c
+++ b/dlls/winmm/lolvldrv.c
@@ -2211,7 +2211,7 @@
 	  lpDrv->name, llTypes[type].name);
     /* realloc translation table */
     llTypes[type].lpMlds = (LPWINE_MLD)
-	HeapReAlloc(SystemHeap, 0, (llTypes[type].lpMlds) ? llTypes[type].lpMlds - 1 : NULL,
+	HeapReAlloc(GetProcessHeap(), 0, (llTypes[type].lpMlds) ? llTypes[type].lpMlds - 1 : NULL,
 		    sizeof(WINE_MLD) * (llTypes[type].wMaxId + 1)) + 1;
     /* re-build the translation table */
     if (llTypes[type].nMapper != -1) {
diff --git a/dlls/winmm/mci.c b/dlls/winmm/mci.c
index fcd0aec..737652e 100644
--- a/dlls/winmm/mci.c
+++ b/dlls/winmm/mci.c
@@ -341,7 +341,7 @@
 		    count++;
 	    } while (eid != MCI_END_COMMAND_LIST);
 
-	    S_MciCmdTable[uTbl].aVerbs = HeapAlloc(SystemHeap, 0, count * sizeof(LPCSTR));
+	    S_MciCmdTable[uTbl].aVerbs = HeapAlloc(GetProcessHeap(), 0, count * sizeof(LPCSTR));
 	    S_MciCmdTable[uTbl].nVerbs = count;
 
 	    lmem = S_MciCmdTable[uTbl].lpTable;
@@ -373,7 +373,7 @@
     FreeResource16(S_MciCmdTable[uTbl].hMem);
     S_MciCmdTable[uTbl].hMem = 0;
     if (S_MciCmdTable[uTbl].aVerbs) {
-	HeapFree(SystemHeap, 0, S_MciCmdTable[uTbl].aVerbs);
+	HeapFree(GetProcessHeap(), 0, S_MciCmdTable[uTbl].aVerbs);
 	S_MciCmdTable[uTbl].aVerbs = 0;
     }
     return TRUE;
@@ -1121,7 +1121,7 @@
 	break;
     case MCI_BREAK:
 	{
-            LPMCI_BREAK_PARMS		mbp32 = HeapAlloc(SystemHeap, 0, sizeof(MCI_BREAK_PARMS));
+            LPMCI_BREAK_PARMS		mbp32 = HeapAlloc(GetProcessHeap(), 0, sizeof(MCI_BREAK_PARMS));
 	    LPMCI_BREAK_PARMS16		mbp16 = PTR_SEG_TO_LIN(*lParam);
 
 	    if (mbp32) {
@@ -1136,7 +1136,7 @@
 	return MCI_MAP_OKMEM;
     case MCI_ESCAPE:
 	{
-            LPMCI_VD_ESCAPE_PARMSA	mvep32a = HeapAlloc(SystemHeap, 0, sizeof(MCI_VD_ESCAPE_PARMSA));
+            LPMCI_VD_ESCAPE_PARMSA	mvep32a = HeapAlloc(GetProcessHeap(), 0, sizeof(MCI_VD_ESCAPE_PARMSA));
 	    LPMCI_VD_ESCAPE_PARMS16	mvep16  = PTR_SEG_TO_LIN(*lParam);
 
 	    if (mvep32a) {
@@ -1150,7 +1150,7 @@
 	return MCI_MAP_OKMEM;
     case MCI_INFO:
 	{
-            LPMCI_INFO_PARMSA	mip32a = HeapAlloc(SystemHeap, 0, sizeof(MCI_INFO_PARMSA));
+            LPMCI_INFO_PARMSA	mip32a = HeapAlloc(GetProcessHeap(), 0, sizeof(MCI_INFO_PARMSA));
 	    LPMCI_INFO_PARMS16	mip16  = PTR_SEG_TO_LIN(*lParam);
 
 	    /* FIXME this is wrong if device is of type 
@@ -1169,7 +1169,7 @@
     case MCI_OPEN:
     case MCI_OPEN_DRIVER:	
 	{
-            LPMCI_OPEN_PARMSA	mop32a = HeapAlloc(SystemHeap, 0, sizeof(LPMCI_OPEN_PARMS16) + sizeof(MCI_OPEN_PARMSA) + 2 * sizeof(DWORD));
+            LPMCI_OPEN_PARMSA	mop32a = HeapAlloc(GetProcessHeap(), 0, sizeof(LPMCI_OPEN_PARMS16) + sizeof(MCI_OPEN_PARMSA) + 2 * sizeof(DWORD));
 	    LPMCI_OPEN_PARMS16	mop16  = PTR_SEG_TO_LIN(*lParam);
 
 	    if (mop32a) {
@@ -1197,7 +1197,7 @@
 	return MCI_MAP_OKMEM;
     case MCI_SYSINFO:
 	{
-            LPMCI_SYSINFO_PARMSA	msip32a = HeapAlloc(SystemHeap, 0, sizeof(MCI_SYSINFO_PARMSA));
+            LPMCI_SYSINFO_PARMSA	msip32a = HeapAlloc(GetProcessHeap(), 0, sizeof(MCI_SYSINFO_PARMSA));
 	    LPMCI_SYSINFO_PARMS16	msip16  = PTR_SEG_TO_LIN(*lParam);
 
 	    if (msip32a) {
@@ -1282,7 +1282,7 @@
     case MCI_ESCAPE:
     case MCI_INFO:
     case MCI_SYSINFO:
-	HeapFree(SystemHeap, 0, (LPVOID)lParam);
+	HeapFree(GetProcessHeap(), 0, (LPVOID)lParam);
 	return MCI_MAP_OK;
     case MCI_OPEN:
     case MCI_OPEN_DRIVER:	
@@ -1291,7 +1291,7 @@
 	    LPMCI_OPEN_PARMS16	mop16  = *(LPMCI_OPEN_PARMS16*)((char*)mop32a - sizeof(LPMCI_OPEN_PARMS16));
 	    
 	    mop16->wDeviceID = mop32a->wDeviceID;
-	    if (!HeapFree(SystemHeap, 0, (LPVOID)(lParam - sizeof(LPMCI_OPEN_PARMS16))))
+	    if (!HeapFree(GetProcessHeap(), 0, (LPVOID)(lParam - sizeof(LPMCI_OPEN_PARMS16))))
 		FIXME("bad free line=%d\n", __LINE__);
 	}
 	return MCI_MAP_OK;
@@ -2476,7 +2476,7 @@
     LPSTR	ptr1, ptr2;
 
     MCI_InstalledCount = 0;
-    ptr1 = MCI_lpInstallNames = HeapAlloc(SystemHeap, 0, 2048);
+    ptr1 = MCI_lpInstallNames = HeapAlloc(GetProcessHeap(), 0, 2048);
 
     if (!MCI_lpInstallNames)
 	return FALSE;
diff --git a/dlls/winmm/wineoss/midi.c b/dlls/winmm/wineoss/midi.c
index 555eb31..6402a84 100644
--- a/dlls/winmm/wineoss/midi.c
+++ b/dlls/winmm/wineoss/midi.c
@@ -179,7 +179,7 @@
 	    return TRUE;
 	}
 	
-	tmplpCaps = HeapAlloc(SystemHeap, 0, sizeof(MIDIOUTCAPSA));
+	tmplpCaps = HeapAlloc(GetProcessHeap(), 0, sizeof(MIDIOUTCAPSA));
 	if (!tmplpCaps)
 	    break;
 	/* We also have the information sinfo.synth_subtype, not used here
@@ -258,7 +258,7 @@
 	    return TRUE;
 	}
 	
-	tmplpOutCaps = HeapAlloc(SystemHeap, 0, sizeof(MIDIOUTCAPSA));
+	tmplpOutCaps = HeapAlloc(GetProcessHeap(), 0, sizeof(MIDIOUTCAPSA));
 	if (!tmplpOutCaps)
 	    break;
 	/* This whole part is somewhat obscure to me. I'll keep trying to dig
@@ -284,7 +284,7 @@
 	
 	midiOutDevices[numsynthdevs + i] = tmplpOutCaps;
 	
-	tmplpInCaps = HeapAlloc(SystemHeap, 0, sizeof(MIDIOUTCAPSA));
+	tmplpInCaps = HeapAlloc(GetProcessHeap(), 0, sizeof(MIDIOUTCAPSA));
 	if (!tmplpInCaps)
 	    break;
 	/* This whole part is somewhat obscure to me. I'll keep trying to dig
diff --git a/dlls/wnaspi32/winaspi32.c b/dlls/wnaspi32/winaspi32.c
index ab47826..ec226df 100644
--- a/dlls/wnaspi32/winaspi32.c
+++ b/dlls/wnaspi32/winaspi32.c
@@ -117,7 +117,7 @@
     }
 
     /* device is now open */
-    curr = HeapAlloc( SystemHeap, 0, sizeof(ASPI_DEVICE_INFO) );
+    curr = HeapAlloc( GetProcessHeap(), 0, sizeof(ASPI_DEVICE_INFO) );
     curr->fd = fd;
     curr->hostId = prb->SRB_HaId;
     curr->target = prb->SRB_Target;
diff --git a/files/dos_fs.c b/files/dos_fs.c
index 2395e57..313db95 100644
--- a/files/dos_fs.c
+++ b/files/dos_fs.c
@@ -321,7 +321,7 @@
  */
 static DOS_DIR *DOSFS_OpenDir( LPCSTR path )
 {
-    DOS_DIR *dir = HeapAlloc( SystemHeap, 0, sizeof(*dir) );
+    DOS_DIR *dir = HeapAlloc( GetProcessHeap(), 0, sizeof(*dir) );
     if (!dir)
     {
         SetLastError( ERROR_NOT_ENOUGH_MEMORY );
@@ -357,7 +357,7 @@
 
     if (!(dir->dir = opendir( path )))
     {
-        HeapFree( SystemHeap, 0, dir );
+        HeapFree( GetProcessHeap(), 0, dir );
         return NULL;
     }
     return dir;
@@ -373,7 +373,7 @@
     if (dir->fd != -1) close( dir->fd );
 #endif  /* VFAT_IOCTL_READDIR_BOTH */
     if (dir->dir) closedir( dir->dir );
-    HeapFree( SystemHeap, 0, dir );
+    HeapFree( GetProcessHeap(), 0, dir );
 }
 
 
@@ -1384,7 +1384,7 @@
     if (!(handle = GlobalAlloc16( GMEM_MOVEABLE, sizeof(FIND_FIRST_INFO) )))
         return INVALID_HANDLE_VALUE16;
     info = (FIND_FIRST_INFO *)GlobalLock16( handle );
-    info->path = HEAP_strdupA( SystemHeap, 0, full_name.long_name );
+    info->path = HEAP_strdupA( GetProcessHeap(), 0, full_name.long_name );
     info->long_mask = strrchr( info->path, '/' );
     *(info->long_mask++) = '\0';
     info->short_mask = NULL;
@@ -1462,7 +1462,7 @@
     if (!DOSFS_FindNextEx( info, data ))
     {
         DOSFS_CloseDir( info->dir ); info->dir = NULL;
-        HeapFree( SystemHeap, 0, info->path );
+        HeapFree( GetProcessHeap(), 0, info->path );
         info->path = info->long_mask = NULL;
         SetLastError( ERROR_NO_MORE_FILES );
         return FALSE;
@@ -1513,7 +1513,7 @@
         return FALSE;
     }
     if (info->dir) DOSFS_CloseDir( info->dir );
-    if (info->path) HeapFree( SystemHeap, 0, info->path );
+    if (info->path) HeapFree( GetProcessHeap(), 0, info->path );
     GlobalUnlock16( handle );
     GlobalFree16( handle );
     return TRUE;
diff --git a/files/drive.c b/files/drive.c
index 8ff68a1..dfe2b87 100644
--- a/files/drive.c
+++ b/files/drive.c
@@ -174,9 +174,9 @@
                 continue;
             }
 
-            drive->root = HEAP_strdupA( SystemHeap, 0, path );
-            drive->dos_cwd  = HEAP_strdupA( SystemHeap, 0, "" );
-            drive->unix_cwd = HEAP_strdupA( SystemHeap, 0, "" );
+            drive->root = HEAP_strdupA( GetProcessHeap(), 0, path );
+            drive->dos_cwd  = HEAP_strdupA( GetProcessHeap(), 0, "" );
+            drive->unix_cwd = HEAP_strdupA( GetProcessHeap(), 0, "" );
             drive->type     = DRIVE_GetDriveType( name );
             drive->device   = NULL;
             drive->flags    = 0;
@@ -207,7 +207,7 @@
                                       buffer, sizeof(buffer) );
             if (buffer[0])
 	    {
-                drive->device = HEAP_strdupA( SystemHeap, 0, buffer );
+                drive->device = HEAP_strdupA( GetProcessHeap(), 0, buffer );
 		drive->read_volinfo =
 		(BOOL)PROFILE_GetWineIniInt( name, "ReadVolInfo", 1);
 	    }
@@ -232,9 +232,9 @@
     {
         MESSAGE("Warning: no valid DOS drive found, check your configuration file.\n" );
         /* Create a C drive pointing to Unix root dir */
-        DOSDrives[2].root     = HEAP_strdupA( SystemHeap, 0, "/" );
-        DOSDrives[2].dos_cwd  = HEAP_strdupA( SystemHeap, 0, "" );
-        DOSDrives[2].unix_cwd = HEAP_strdupA( SystemHeap, 0, "" );
+        DOSDrives[2].root     = HEAP_strdupA( GetProcessHeap(), 0, "/" );
+        DOSDrives[2].dos_cwd  = HEAP_strdupA( GetProcessHeap(), 0, "" );
+        DOSDrives[2].unix_cwd = HEAP_strdupA( GetProcessHeap(), 0, "" );
         strcpy( DOSDrives[2].label_conf, "Drive C    " );
         DOSDrives[2].serial_conf   = 12345678;
         DOSDrives[2].type     = TYPE_HD;
@@ -641,11 +641,11 @@
     TRACE("(%c:): unix_cwd=%s dos_cwd=%s\n",
                    'A' + drive, unix_cwd, full_name.short_name + 3 );
 
-    HeapFree( SystemHeap, 0, DOSDrives[drive].dos_cwd );
-    HeapFree( SystemHeap, 0, DOSDrives[drive].unix_cwd );
-    DOSDrives[drive].dos_cwd  = HEAP_strdupA( SystemHeap, 0,
+    HeapFree( GetProcessHeap(), 0, DOSDrives[drive].dos_cwd );
+    HeapFree( GetProcessHeap(), 0, DOSDrives[drive].unix_cwd );
+    DOSDrives[drive].dos_cwd  = HEAP_strdupA( GetProcessHeap(), 0,
                                               full_name.short_name + 3 );
-    DOSDrives[drive].unix_cwd = HEAP_strdupA( SystemHeap, 0, unix_cwd );
+    DOSDrives[drive].unix_cwd = HEAP_strdupA( GetProcessHeap(), 0, unix_cwd );
 
     if (pTask && (pTask->curdrive & 0x80) && 
         ((pTask->curdrive & ~0x80) == drive))
@@ -719,9 +719,9 @@
 	return 0;
     }
 
-    new->root = HEAP_strdupA( SystemHeap, 0, old->root );
-    new->dos_cwd = HEAP_strdupA( SystemHeap, 0, old->dos_cwd );
-    new->unix_cwd = HEAP_strdupA( SystemHeap, 0, old->unix_cwd );
+    new->root = HEAP_strdupA( GetProcessHeap(), 0, old->root );
+    new->dos_cwd = HEAP_strdupA( GetProcessHeap(), 0, old->dos_cwd );
+    new->unix_cwd = HEAP_strdupA( GetProcessHeap(), 0, old->unix_cwd );
     memcpy ( new->label_conf, old->label_conf, 12 );
     new->serial_conf = old->serial_conf;
     new->type = old->type;
diff --git a/files/file.c b/files/file.c
index 2999730..170e261 100644
--- a/files/file.c
+++ b/files/file.c
@@ -983,7 +983,7 @@
 BOOL FILE_InitProcessDosHandles( void ) {
 	HANDLE *ptr;
 
-        if (!(ptr = HeapAlloc( SystemHeap, HEAP_ZERO_MEMORY,
+        if (!(ptr = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
                                sizeof(*ptr) * DOS_TABLE_SIZE )))
             return FALSE;
         PROCESS_Current()->dos_handles = ptr;
@@ -2082,11 +2082,11 @@
   }
 #endif
 
-  curr = HeapAlloc( SystemHeap, 0, sizeof(DOS_FILE_LOCK) );
+  curr = HeapAlloc( GetProcessHeap(), 0, sizeof(DOS_FILE_LOCK) );
   curr->processId = GetCurrentProcessId();
   curr->base = f->l_start;
   curr->len = f->l_len;
-/*  curr->unix_name = HEAP_strdupA( SystemHeap, 0, file->unix_name);*/
+/*  curr->unix_name = HEAP_strdupA( GetProcessHeap(), 0, file->unix_name);*/
   curr->next = locks;
   curr->dos_file = file;
   locks = curr;
@@ -2105,8 +2105,8 @@
     if ((*curr)->dos_file == file) {
       rem = *curr;
       *curr = (*curr)->next;
-/*      HeapFree( SystemHeap, 0, rem->unix_name );*/
-      HeapFree( SystemHeap, 0, rem );
+/*      HeapFree( GetProcessHeap(), 0, rem->unix_name );*/
+      HeapFree( GetProcessHeap(), 0, rem );
     }
     else
       curr = &(*curr)->next;
@@ -2128,8 +2128,8 @@
       /* this is the same lock */
       rem = *curr;
       *curr = (*curr)->next;
-/*      HeapFree( SystemHeap, 0, rem->unix_name );*/
-      HeapFree( SystemHeap, 0, rem );
+/*      HeapFree( GetProcessHeap(), 0, rem->unix_name );*/
+      HeapFree( GetProcessHeap(), 0, rem );
       return TRUE;
     }
   }
diff --git a/files/profile.c b/files/profile.c
index 4d16416..5575b91 100644
--- a/files/profile.c
+++ b/files/profile.c
@@ -196,16 +196,16 @@
 
     for ( ; section; section = next_section)
     {
-        if (section->name) HeapFree( SystemHeap, 0, section->name );
+        if (section->name) HeapFree( GetProcessHeap(), 0, section->name );
         for (key = section->key; key; key = next_key)
         {
             next_key = key->next;
-            if (key->name) HeapFree( SystemHeap, 0, key->name );
-            if (key->value) HeapFree( SystemHeap, 0, key->value );
-            HeapFree( SystemHeap, 0, key );
+            if (key->name) HeapFree( GetProcessHeap(), 0, key->name );
+            if (key->value) HeapFree( GetProcessHeap(), 0, key->value );
+            HeapFree( GetProcessHeap(), 0, key );
         }
         next_section = section->next;
-        HeapFree( SystemHeap, 0, section );
+        HeapFree( GetProcessHeap(), 0, section );
     }
 }
 
@@ -232,7 +232,7 @@
     PROFILESECTION **next_section;
     PROFILEKEY *key, *prev_key, **next_key;
 
-    first_section = HEAP_xalloc( SystemHeap, 0, sizeof(*section) );
+    first_section = HEAP_xalloc( GetProcessHeap(), 0, sizeof(*section) );
     first_section->name = NULL;
     first_section->key  = NULL;
     first_section->next = NULL;
@@ -256,8 +256,8 @@
             {
                 *p2 = '\0';
                 p++;
-                section = HEAP_xalloc( SystemHeap, 0, sizeof(*section) );
-                section->name = HEAP_strdupA( SystemHeap, 0, p );
+                section = HEAP_xalloc( GetProcessHeap(), 0, sizeof(*section) );
+                section->name = HEAP_strdupA( GetProcessHeap(), 0, p );
                 section->key  = NULL;
                 section->next = NULL;
                 *next_section = section;
@@ -284,9 +284,9 @@
 
         if(*p || !prev_key || *prev_key->name)
           {
-           key = HEAP_xalloc( SystemHeap, 0, sizeof(*key) );
-           key->name  = HEAP_strdupA( SystemHeap, 0, p );
-           key->value = p2 ? HEAP_strdupA( SystemHeap, 0, p2 ) : NULL;
+           key = HEAP_xalloc( GetProcessHeap(), 0, sizeof(*key) );
+           key->name  = HEAP_strdupA( GetProcessHeap(), 0, p );
+           key->value = p2 ? HEAP_strdupA( GetProcessHeap(), 0, p2 ) : NULL;
            key->next  = NULL;
            *next_key  = key;
            next_key   = &key->next;
@@ -341,9 +341,9 @@
                 {
                     PROFILEKEY *to_del = *key;
                     *key = to_del->next;
-                    if (to_del->name) HeapFree( SystemHeap, 0, to_del->name );
-                    if (to_del->value) HeapFree( SystemHeap, 0, to_del->value);
-                    HeapFree( SystemHeap, 0, to_del );
+                    if (to_del->name) HeapFree( GetProcessHeap(), 0, to_del->name );
+                    if (to_del->value) HeapFree( GetProcessHeap(), 0, to_del->value);
+                    HeapFree( GetProcessHeap(), 0, to_del );
                     return TRUE;
                 }
                 key = &(*key)->next;
@@ -392,8 +392,8 @@
                 key = &(*key)->next;
             }
             if (!create) return NULL;
-            *key = HEAP_xalloc( SystemHeap, 0, sizeof(PROFILEKEY) );
-            (*key)->name  = HEAP_strdupA( SystemHeap, 0, key_name );
+            *key = HEAP_xalloc( GetProcessHeap(), 0, sizeof(PROFILEKEY) );
+            (*key)->name  = HEAP_strdupA( GetProcessHeap(), 0, key_name );
             (*key)->value = NULL;
             (*key)->next  = NULL;
             return *key;
@@ -401,11 +401,11 @@
         section = &(*section)->next;
     }
     if (!create) return NULL;
-    *section = HEAP_xalloc( SystemHeap, 0, sizeof(PROFILESECTION) );
-    (*section)->name = HEAP_strdupA( SystemHeap, 0, section_name );
+    *section = HEAP_xalloc( GetProcessHeap(), 0, sizeof(PROFILESECTION) );
+    (*section)->name = HEAP_strdupA( GetProcessHeap(), 0, section_name );
     (*section)->next = NULL;
-    (*section)->key  = HEAP_xalloc( SystemHeap, 0, sizeof(PROFILEKEY) );
-    (*section)->key->name  = HEAP_strdupA( SystemHeap, 0, key_name );
+    (*section)->key  = HEAP_xalloc( GetProcessHeap(), 0, sizeof(PROFILEKEY) );
+    (*section)->key->name  = HEAP_strdupA( GetProcessHeap(), 0, key_name );
     (*section)->key->value = NULL;
     (*section)->key->next  = NULL;
     return (*section)->key;
@@ -469,9 +469,9 @@
 {
     PROFILE_FlushFile();
     PROFILE_Free( CurProfile->section );
-    if (CurProfile->dos_name) HeapFree( SystemHeap, 0, CurProfile->dos_name );
-    if (CurProfile->unix_name) HeapFree( SystemHeap, 0, CurProfile->unix_name );
-    if (CurProfile->filename) HeapFree( SystemHeap, 0, CurProfile->filename );
+    if (CurProfile->dos_name) HeapFree( GetProcessHeap(), 0, CurProfile->dos_name );
+    if (CurProfile->unix_name) HeapFree( GetProcessHeap(), 0, CurProfile->unix_name );
+    if (CurProfile->filename) HeapFree( GetProcessHeap(), 0, CurProfile->filename );
     CurProfile->changed   = FALSE;
     CurProfile->section   = NULL;
     CurProfile->dos_name  = NULL;
@@ -501,7 +501,7 @@
     if(!CurProfile)
        for(i=0;i<N_CACHED_PROFILES;i++)
          {
-          MRUProfile[i]=HEAP_xalloc( SystemHeap, 0, sizeof(PROFILE) );
+          MRUProfile[i]=HEAP_xalloc( GetProcessHeap(), 0, sizeof(PROFILE) );
           MRUProfile[i]->changed=FALSE;
           MRUProfile[i]->section=NULL;
           MRUProfile[i]->dos_name=NULL;
@@ -562,9 +562,9 @@
     if(CurProfile->filename) PROFILE_ReleaseFile();
 
     /* OK, now that CurProfile is definitely free we assign it our new file */
-    newdos_name = HEAP_strdupA( SystemHeap, 0, full_name.short_name );
+    newdos_name = HEAP_strdupA( GetProcessHeap(), 0, full_name.short_name );
     CurProfile->dos_name  = newdos_name;
-    CurProfile->filename  = HEAP_strdupA( SystemHeap, 0, filename );
+    CurProfile->filename  = HEAP_strdupA( GetProcessHeap(), 0, filename );
 
     /* Try to open the profile file, first in $HOME/.wine */
 
@@ -578,12 +578,12 @@
     {
         TRACE("(%s): found it in %s\n",
               filename, buffer );
-        CurProfile->unix_name = HEAP_strdupA( SystemHeap, 0, buffer );
+        CurProfile->unix_name = HEAP_strdupA( GetProcessHeap(), 0, buffer );
     }
 
     if (!file)
     {
-        CurProfile->unix_name = HEAP_strdupA( SystemHeap, 0,
+        CurProfile->unix_name = HEAP_strdupA( GetProcessHeap(), 0,
                                              full_name.long_name );
         if ((file = fopen( full_name.long_name, "r" )))
             TRACE("(%s): found it in %s\n",
@@ -748,10 +748,10 @@
                 return TRUE;  /* No change needed */
             }
             TRACE("  replacing '%s'\n", key->value );
-            HeapFree( SystemHeap, 0, key->value );
+            HeapFree( GetProcessHeap(), 0, key->value );
         }
         else TRACE("  creating key\n" );
-        key->value = HEAP_strdupA( SystemHeap, 0, value );
+        key->value = HEAP_strdupA( GetProcessHeap(), 0, value );
         CurProfile->changed = TRUE;
     }
     return TRUE;
@@ -1066,7 +1066,7 @@
  */
 UINT WINAPI GetProfileIntW( LPCWSTR section, LPCWSTR entry, INT def_val )
 {
-    if (!wininiW) wininiW = HEAP_strdupAtoW( SystemHeap, 0, "win.ini" );
+    if (!wininiW) wininiW = HEAP_strdupAtoW( GetProcessHeap(), 0, "win.ini" );
     return GetPrivateProfileIntW( section, entry, def_val, wininiW );
 }
 
@@ -1096,7 +1096,7 @@
 INT WINAPI GetProfileStringW( LPCWSTR section, LPCWSTR entry,
 			      LPCWSTR def_val, LPWSTR buffer, UINT len )
 {
-    if (!wininiW) wininiW = HEAP_strdupAtoW( SystemHeap, 0, "win.ini" );
+    if (!wininiW) wininiW = HEAP_strdupAtoW( GetProcessHeap(), 0, "win.ini" );
     return GetPrivateProfileStringW( section, entry, def_val,
 				     buffer, len, wininiW );
 }
@@ -1125,7 +1125,7 @@
 BOOL WINAPI WriteProfileStringW( LPCWSTR section, LPCWSTR entry,
                                      LPCWSTR string )
 {
-    if (!wininiW) wininiW = HEAP_strdupAtoW( SystemHeap, 0, "win.ini" );
+    if (!wininiW) wininiW = HEAP_strdupAtoW( GetProcessHeap(), 0, "win.ini" );
     return WritePrivateProfileStringW( section, entry, string, wininiW );
 }
 
@@ -1306,7 +1306,7 @@
  */
 INT WINAPI GetProfileSectionW( LPCWSTR section, LPWSTR buffer, DWORD len )
 {
-    if (!wininiW) wininiW = HEAP_strdupAtoW( SystemHeap, 0, "win.ini" );
+    if (!wininiW) wininiW = HEAP_strdupAtoW( GetProcessHeap(), 0, "win.ini" );
     return GetPrivateProfileSectionW( section, buffer, len, wininiW );
 }
 
@@ -1442,7 +1442,7 @@
  */
 BOOL WINAPI WriteProfileSectionW( LPCWSTR section, LPCWSTR keys_n_values)
 {
-   if (!wininiW) wininiW = HEAP_strdupAtoW( SystemHeap, 0, "win.ini");
+   if (!wininiW) wininiW = HEAP_strdupAtoW( GetProcessHeap(), 0, "win.ini");
    
    return (WritePrivateProfileSectionW (section,keys_n_values, wininiW));
 }
@@ -1637,7 +1637,7 @@
         return WritePrivateProfileStringA( NULL, NULL, NULL, filename );
 
     /* allocate string buffer for hex chars + checksum hex char + '\0' */
-    outstring = HeapAlloc( SystemHeap, 0, bufsize*2 + 2 + 1);
+    outstring = HeapAlloc( GetProcessHeap(), 0, bufsize*2 + 2 + 1);
     p = outstring;
     for (binbuf = (LPBYTE)buf; binbuf < (LPBYTE)buf+bufsize; binbuf++) {
       *p++ = hex[*binbuf >> 4];
@@ -1656,7 +1656,7 @@
 
     LeaveCriticalSection( &PROFILE_CritSect );
 
-    HeapFree( SystemHeap, 0, outstring );
+    HeapFree( GetProcessHeap(), 0, outstring );
 
     return ret;
 }
diff --git a/graphics/driver.c b/graphics/driver.c
index f2a0732..761fc16 100644
--- a/graphics/driver.c
+++ b/graphics/driver.c
@@ -26,12 +26,12 @@
  */
 BOOL DRIVER_RegisterDriver( LPCSTR name, const DC_FUNCTIONS *funcs )
 {
-    GRAPHICS_DRIVER *driver = HeapAlloc( SystemHeap, 0, sizeof(*driver) );
+    GRAPHICS_DRIVER *driver = HeapAlloc( GetProcessHeap(), 0, sizeof(*driver) );
     if (!driver) return FALSE;
     driver->funcs = funcs;
     if (name)
     {
-        driver->name  = HEAP_strdupA( SystemHeap, 0, name );
+        driver->name  = HEAP_strdupA( GetProcessHeap(), 0, name );
         driver->next  = firstDriver;
         firstDriver = driver;
         return TRUE;
@@ -40,7 +40,7 @@
     if (genericDriver)
     {
         WARN(" already a generic driver\n" );
-        HeapFree( SystemHeap, 0, driver );
+        HeapFree( GetProcessHeap(), 0, driver );
         return FALSE;
     }
     driver->name = NULL;
@@ -80,8 +80,8 @@
             {
                 GRAPHICS_DRIVER *driver = *ppDriver;
                 (*ppDriver) = driver->next;
-                HeapFree( SystemHeap, 0, driver->name );
-                HeapFree( SystemHeap, 0, driver );
+                HeapFree( GetProcessHeap(), 0, driver->name );
+                HeapFree( GetProcessHeap(), 0, driver );
                 return TRUE;
             }
             ppDriver = &(*ppDriver)->next;
@@ -91,7 +91,7 @@
     else
     {
         if (!genericDriver) return FALSE;
-        HeapFree( SystemHeap, 0, genericDriver );
+        HeapFree( GetProcessHeap(), 0, genericDriver );
         genericDriver = NULL;
         return TRUE;
     }
diff --git a/graphics/enhmetafiledrv/graphics.c b/graphics/enhmetafiledrv/graphics.c
index 187027a..e83c7a0 100644
--- a/graphics/enhmetafiledrv/graphics.c
+++ b/graphics/enhmetafiledrv/graphics.c
@@ -310,7 +310,7 @@
 
     size = sizeof(EMRPOLYLINE) + sizeof(POINTL) * (count - 1);
 
-    emr = HeapAlloc( SystemHeap, 0, size );
+    emr = HeapAlloc( GetProcessHeap(), 0, size );
     emr->emr.iType = iType;
     emr->emr.nSize = size;
     
@@ -334,7 +334,7 @@
     ret = EMFDRV_WriteRecord( dc, &emr->emr );
     if(ret)
         EMFDRV_UpdateBBox( dc, &emr->rclBounds );
-    HeapFree( SystemHeap, 0, emr );
+    HeapFree( GetProcessHeap(), 0, emr );
     return ret;
 }
 
@@ -392,7 +392,7 @@
     size = sizeof(EMRPOLYPOLYLINE) + (polys - 1) * sizeof(DWORD) + 
       (cptl - 1) * sizeof(POINTL);
 
-    emr = HeapAlloc( SystemHeap, 0, size );
+    emr = HeapAlloc( GetProcessHeap(), 0, size );
 
     emr->emr.iType = iType;
     emr->emr.nSize = size;
@@ -404,7 +404,7 @@
     ret = EMFDRV_WriteRecord( dc, &emr->emr );
     if(ret)
         EMFDRV_UpdateBBox( dc, &emr->rclBounds );
-    HeapFree( SystemHeap, 0, emr );
+    HeapFree( GetProcessHeap(), 0, emr );
     return ret;
 }
 
@@ -461,7 +461,7 @@
 
     rgnsize = GetRegionData( hrgn, 0, NULL );
     size = rgnsize + sizeof(EMRFILLRGN) - 1;
-    emr = HeapAlloc( SystemHeap, 0, size );
+    emr = HeapAlloc( GetProcessHeap(), 0, size );
 
     GetRegionData( hrgn, rgnsize, (RGNDATA *)&emr->RgnData );
 
@@ -477,7 +477,7 @@
     ret = EMFDRV_WriteRecord( dc, &emr->emr );
     if(ret)
         EMFDRV_UpdateBBox( dc, &emr->rclBounds );
-    HeapFree( SystemHeap, 0, emr );
+    HeapFree( GetProcessHeap(), 0, emr );
     return ret;
 }
 /*********************************************************************
@@ -494,7 +494,7 @@
 
     rgnsize = GetRegionData( hrgn, 0, NULL );
     size = rgnsize + sizeof(EMRFRAMERGN) - 1;
-    emr = HeapAlloc( SystemHeap, 0, size );
+    emr = HeapAlloc( GetProcessHeap(), 0, size );
 
     GetRegionData( hrgn, rgnsize, (RGNDATA *)&emr->RgnData );
 
@@ -512,7 +512,7 @@
     ret = EMFDRV_WriteRecord( dc, &emr->emr );
     if(ret)
         EMFDRV_UpdateBBox( dc, &emr->rclBounds );
-    HeapFree( SystemHeap, 0, emr );
+    HeapFree( GetProcessHeap(), 0, emr );
     return ret;
 }
 
@@ -530,7 +530,7 @@
 
     rgnsize = GetRegionData( hrgn, 0, NULL );
     size = rgnsize + sizeof(EMRINVERTRGN) - 1;
-    emr = HeapAlloc( SystemHeap, 0, size );
+    emr = HeapAlloc( GetProcessHeap(), 0, size );
 
     GetRegionData( hrgn, rgnsize, (RGNDATA *)&emr->RgnData );
 
@@ -545,7 +545,7 @@
     ret = EMFDRV_WriteRecord( dc, &emr->emr );
     if(ret)
         EMFDRV_UpdateBBox( dc, &emr->rclBounds );
-    HeapFree( SystemHeap, 0, emr );
+    HeapFree( GetProcessHeap(), 0, emr );
     return ret;
 }
 
diff --git a/graphics/enhmetafiledrv/init.c b/graphics/enhmetafiledrv/init.c
index 5996764..4fce766 100644
--- a/graphics/enhmetafiledrv/init.c
+++ b/graphics/enhmetafiledrv/init.c
@@ -122,8 +122,8 @@
 {
     EMFDRV_PDEVICE *physDev = (EMFDRV_PDEVICE *)dc->physDev;
     
-    if (physDev->emh) HeapFree( SystemHeap, 0, physDev->emh );
-    HeapFree( SystemHeap, 0, physDev );
+    if (physDev->emh) HeapFree( GetProcessHeap(), 0, physDev->emh );
+    HeapFree( GetProcessHeap(), 0, physDev );
     dc->physDev = NULL;
     GDI_FreeObject(dc->hSelf);
     return TRUE;
@@ -150,7 +150,7 @@
 	    return FALSE;
     } else {
 	len = physDev->emh->nBytes;
-	emh = HeapReAlloc( SystemHeap, 0, physDev->emh, len );
+	emh = HeapReAlloc( GetProcessHeap(), 0, physDev->emh, len );
         if (!emh) return FALSE;
         physDev->emh = emh;
 	memcpy((CHAR *)physDev->emh + physDev->emh->nBytes - emr->nSize, emr,
@@ -252,7 +252,7 @@
     if (!(dc = DC_AllocDC( &EMFDRV_Funcs ))) return 0;
     dc->header.wMagic = ENHMETAFILE_DC_MAGIC;
 
-    physDev = (EMFDRV_PDEVICE *)HeapAlloc(SystemHeap,0,sizeof(*physDev));
+    physDev = (EMFDRV_PDEVICE *)HeapAlloc(GetProcessHeap(),0,sizeof(*physDev));
     if (!physDev) {
         GDI_HEAP_FREE( dc->hSelf );
         return 0;
@@ -267,8 +267,8 @@
     }
     size = sizeof(ENHMETAHEADER) + (length + 3) / 4 * 4;
 
-    if (!(physDev->emh = HeapAlloc( SystemHeap, HEAP_ZERO_MEMORY, size))) {
-        HeapFree( SystemHeap, 0, physDev );
+    if (!(physDev->emh = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, size))) {
+        HeapFree( GetProcessHeap(), 0, physDev );
         GDI_HEAP_FREE( dc->hSelf );
         return 0;
     }
@@ -362,7 +362,7 @@
             EMFDRV_DeleteDC( dc );
             return 0;
         }
-	HeapFree( SystemHeap, 0, physDev->emh );
+	HeapFree( GetProcessHeap(), 0, physDev->emh );
         hMapping = CreateFileMappingA(physDev->hFile, NULL, PAGE_READONLY, 0,
 				      0, NULL);
 	TRACE("hMapping = %08x\n", hMapping );
diff --git a/graphics/enhmetafiledrv/objects.c b/graphics/enhmetafiledrv/objects.c
index ef90372..f373ceb 100644
--- a/graphics/enhmetafiledrv/objects.c
+++ b/graphics/enhmetafiledrv/objects.c
@@ -64,8 +64,8 @@
 					  info->bmiHeader.biBitCount);
 	biSize = DIB_BitmapInfoSize(info, LOWORD(brushObj->logbrush.lbColor)); 
 	size = sizeof(EMRCREATEDIBPATTERNBRUSHPT) + biSize + bmSize;
-	emr = HeapAlloc( SystemHeap, 0, size );
-	if(!emr) break;;
+	emr = HeapAlloc( GetProcessHeap(), 0, size );
+	if(!emr) break;
 	emr->emr.iType = EMR_CREATEDIBPATTERNBRUSHPT;
 	emr->emr.nSize = size;
 	emr->ihBrush = index = EMFDRV_AddHandleDC( dc );
@@ -78,7 +78,7 @@
 
 	if(!EMFDRV_WriteRecord( dc, &emr->emr ))
 	    index = 0;
-	HeapFree( SystemHeap, 0, emr );
+	HeapFree( GetProcessHeap(), 0, emr );
 	GlobalUnlock16(brushObj->logbrush.lbHatch);
       }
       break;
diff --git a/graphics/metafiledrv/bitblt.c b/graphics/metafiledrv/bitblt.c
index a8ee0f6..21f30e9 100644
--- a/graphics/metafiledrv/bitblt.c
+++ b/graphics/metafiledrv/bitblt.c
@@ -39,7 +39,7 @@
 
     GetObject16(dcSrc->w.hBitmap, sizeof(BITMAP16), &BM);
     len = sizeof(METARECORD) + 12 * sizeof(INT16) + BM.bmWidthBytes * BM.bmHeight;
-    if (!(mr = HeapAlloc(SystemHeap, 0, len)))
+    if (!(mr = HeapAlloc(GetProcessHeap(), 0, len)))
 	return FALSE;
     mr->rdFunction = META_BITBLT;
     *(mr->rdParm + 7) = BM.bmWidth;
@@ -63,7 +63,7 @@
     } 
     else
         ret = FALSE;
-    HeapFree( SystemHeap, 0, mr);
+    HeapFree( GetProcessHeap(), 0, mr);
     return ret;
 }
 
@@ -96,7 +96,7 @@
     len = sizeof(METARECORD) + 10 * sizeof(INT16) 
             + sizeof(BITMAPINFOHEADER) + (nBPP != 24 ? 1 << nBPP: 0) * sizeof(RGBQUAD) 
               + ((BM.bmWidth * nBPP + 31) / 32) * 4 * BM.bmHeight;
-    if (!(mr = HeapAlloc( SystemHeap, 0, len)))
+    if (!(mr = HeapAlloc( GetProcessHeap(), 0, len)))
 	return FALSE;
     mr->rdFunction = META_DIBSTRETCHBLT;
     lpBMI=(LPBITMAPINFOHEADER)(mr->rdParm+10);
@@ -120,7 +120,7 @@
                   (LPBITMAPINFO)lpBMI, DIB_RGB_COLORS))
 #else
     len = sizeof(METARECORD) + 15 * sizeof(INT16) + BM.bmWidthBytes * BM.bmHeight;
-    if (!(mr = HeapAlloc( SystemHeap, 0, len )))
+    if (!(mr = HeapAlloc( GetProcessHeap(), 0, len )))
 	return FALSE;
     mr->rdFunction = META_STRETCHBLT;
     *(mr->rdParm +10) = BM.bmWidth;
@@ -148,7 +148,7 @@
     }  
     else
         ret = FALSE;
-    HeapFree( SystemHeap, 0, mr);
+    HeapFree( GetProcessHeap(), 0, mr);
     return ret;
 }
 
@@ -170,7 +170,7 @@
 				      info->bmiHeader.biBitCount );
 
     len = sizeof(METARECORD) + 10 * sizeof(WORD) + infosize + imagesize;
-    mr = (METARECORD *)HeapAlloc( SystemHeap, 0, len );
+    mr = (METARECORD *)HeapAlloc( GetProcessHeap(), 0, len );
     if(!mr) return 0;
 
     mr->rdSize = len / 2;
@@ -189,7 +189,7 @@
     memcpy(mr->rdParm + 11, info, infosize);
     memcpy(mr->rdParm + 11 + infosize / 2, bits, imagesize);
     MFDRV_WriteRecord( dc, mr, mr->rdSize * 2 );
-    HeapFree( SystemHeap, 0, mr );
+    HeapFree( GetProcessHeap(), 0, mr );
     return heightSrc;
 }
 
@@ -212,7 +212,7 @@
 				      info->bmiHeader.biBitCount );
 
     len = sizeof(METARECORD) + 8 * sizeof(WORD) + infosize + imagesize;
-    mr = (METARECORD *)HeapAlloc( SystemHeap, 0, len );
+    mr = (METARECORD *)HeapAlloc( GetProcessHeap(), 0, len );
     if(!mr) return 0;
 
     mr->rdSize = len / 2;
@@ -229,7 +229,7 @@
     memcpy(mr->rdParm + 9, info, infosize);
     memcpy(mr->rdParm + 9 + infosize / 2, bits, imagesize);
     MFDRV_WriteRecord( dc, mr, mr->rdSize * 2 );
-    HeapFree( SystemHeap, 0, mr );
+    HeapFree( GetProcessHeap(), 0, mr );
     return lines;
 }
 
diff --git a/graphics/metafiledrv/graphics.c b/graphics/metafiledrv/graphics.c
index 664a9a0..98e6879 100644
--- a/graphics/metafiledrv/graphics.c
+++ b/graphics/metafiledrv/graphics.c
@@ -120,7 +120,7 @@
     METARECORD *mr;
 
     len = sizeof(METARECORD) + (count * 4); 
-    if (!(mr = HeapAlloc( SystemHeap, HEAP_ZERO_MEMORY, len )))
+    if (!(mr = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, len )))
 	return FALSE;
 
     mr->rdSize = len / 2;
@@ -128,7 +128,7 @@
     *(mr->rdParm) = count;
     memcpy(mr->rdParm + 1, pt, count * 4);
     ret = MFDRV_WriteRecord( dc, mr, mr->rdSize * 2);
-    HeapFree( SystemHeap, 0, mr);
+    HeapFree( GetProcessHeap(), 0, mr);
     return ret;
 }
 
@@ -227,7 +227,7 @@
     BOOL ret;
 
     len = GetRegionData( hrgn, 0, NULL );
-    if( !(rgndata = HeapAlloc( SystemHeap, 0, len )) ) {
+    if( !(rgndata = HeapAlloc( GetProcessHeap(), 0, len )) ) {
         WARN("Can't alloc rgndata buffer\n");
 	return -1;
     }
@@ -237,9 +237,9 @@
      * Assume every rect is a separate band -> 6 WORDs per rect
      */
     len = sizeof(METARECORD) + 20 + (rgndata->rdh.nCount * 12);
-    if( !(mr = HeapAlloc( SystemHeap, HEAP_ZERO_MEMORY, len )) ) {
+    if( !(mr = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, len )) ) {
         WARN("Can't alloc METARECORD buffer\n");
-	HeapFree( SystemHeap, 0, rgndata );
+	HeapFree( GetProcessHeap(), 0, rgndata );
 	return -1;
     }
 
@@ -287,8 +287,8 @@
     mr->rdFunction = META_CREATEREGION;
     mr->rdSize = len / 2;
     ret = MFDRV_WriteRecord( dc, mr, mr->rdSize * 2 );	
-    HeapFree( SystemHeap, 0, mr );
-    HeapFree( SystemHeap, 0, rgndata );
+    HeapFree( GetProcessHeap(), 0, mr );
+    HeapFree( GetProcessHeap(), 0, rgndata );
     if(!ret) 
     {
         WARN("MFDRV_WriteRecord failed\n");
diff --git a/graphics/metafiledrv/init.c b/graphics/metafiledrv/init.c
index 4b518cb..a9ff802 100644
--- a/graphics/metafiledrv/init.c
+++ b/graphics/metafiledrv/init.c
@@ -125,7 +125,7 @@
     if (!(dc = DC_AllocDC( &MFDRV_Funcs ))) return NULL;
     dc->header.wMagic = METAFILE_DC_MAGIC;
 
-    physDev = (METAFILEDRV_PDEVICE *)HeapAlloc(SystemHeap,0,sizeof(*physDev));
+    physDev = (METAFILEDRV_PDEVICE *)HeapAlloc(GetProcessHeap(),0,sizeof(*physDev));
     if (!physDev)
     {
         GDI_HEAP_FREE( dc->hSelf );
@@ -133,9 +133,9 @@
     }
     dc->physDev = physDev;
 
-    if (!(physDev->mh = HeapAlloc( SystemHeap, 0, sizeof(*physDev->mh) )))
+    if (!(physDev->mh = HeapAlloc( GetProcessHeap(), 0, sizeof(*physDev->mh) )))
     {
-        HeapFree( SystemHeap, 0, physDev );
+        HeapFree( GetProcessHeap(), 0, physDev );
         GDI_HEAP_FREE( dc->hSelf );
         return NULL;
     }
@@ -161,8 +161,8 @@
 {
     METAFILEDRV_PDEVICE *physDev = (METAFILEDRV_PDEVICE *)dc->physDev;
     
-    if (physDev->mh) HeapFree( SystemHeap, 0, physDev->mh );
-    HeapFree( SystemHeap, 0, physDev );
+    if (physDev->mh) HeapFree( GetProcessHeap(), 0, physDev->mh );
+    HeapFree( GetProcessHeap(), 0, physDev );
     dc->physDev = NULL;
     GDI_FreeObject(dc->hSelf);
     return TRUE;
@@ -352,7 +352,7 @@
     {
     case METAFILE_MEMORY:
 	len = physDev->mh->mtSize * 2 + rlen;
-	mh = HeapReAlloc( SystemHeap, 0, physDev->mh, len );
+	mh = HeapReAlloc( GetProcessHeap(), 0, physDev->mh, len );
         if (!mh) return FALSE;
         physDev->mh = mh;
 	memcpy((WORD *)physDev->mh + physDev->mh->mtSize, mr, rlen);
diff --git a/graphics/metafiledrv/objects.c b/graphics/metafiledrv/objects.c
index f27ea79..88db9b2 100644
--- a/graphics/metafiledrv/objects.c
+++ b/graphics/metafiledrv/objects.c
@@ -52,7 +52,7 @@
 	    lb16.lbColor = brushObj->logbrush.lbColor;
 	    lb16.lbHatch = brushObj->logbrush.lbHatch;
 	    size = sizeof(METARECORD) + sizeof(LOGBRUSH16) - 2;
-	    mr = HeapAlloc( SystemHeap, 0, size );
+	    mr = HeapAlloc( GetProcessHeap(), 0, size );
 	    mr->rdSize = size / 2;
 	    mr->rdFunction = META_CREATEBRUSHINDIRECT;
 	    memcpy( mr->rdParm, &lb16, sizeof(LOGBRUSH));
@@ -76,7 +76,7 @@
 	    size = sizeof(METARECORD) + sizeof(WORD) + sizeof(BITMAPINFO) + 
 	      sizeof(RGBQUAD) + bmSize;
 
-	    mr = HeapAlloc(SystemHeap, HEAP_ZERO_MEMORY, size);
+	    mr = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
 	    if(!mr) return FALSE;
 	    mr->rdFunction = META_DIBCREATEPATTERNBRUSH;
 	    mr->rdSize = size / 2;
@@ -113,7 +113,7 @@
 	      biSize = DIB_BitmapInfoSize(info,
 					  LOWORD(brushObj->logbrush.lbColor)); 
 	      size = sizeof(METARECORD) + biSize + bmSize + 2;
-	      mr = HeapAlloc(SystemHeap, HEAP_ZERO_MEMORY, size);
+	      mr = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
 	      if(!mr) return FALSE;
 	      mr->rdFunction = META_DIBCREATEPATTERNBRUSH;
 	      mr->rdSize = size / 2;
@@ -129,7 +129,7 @@
     index = MFDRV_AddHandleDC( dc );
     if(!MFDRV_WriteRecord( dc, mr, mr->rdSize * 2))
         index = -1;
-    HeapFree(SystemHeap, 0, mr);
+    HeapFree(GetProcessHeap(), 0, mr);
     GDI_HEAP_UNLOCK( hBrush );
     return index;
 }
diff --git a/graphics/win16drv/init.c b/graphics/win16drv/init.c
index 27ca812..e089035 100644
--- a/graphics/win16drv/init.c
+++ b/graphics/win16drv/init.c
@@ -210,7 +210,7 @@
     TRACE("In creatdc for (%s,%s,%s) initData 0x%p\n",
 	  driver, device, output, initData);
 
-    physDev = (WIN16DRV_PDEVICE *)HeapAlloc( SystemHeap, 0, sizeof(*physDev) );
+    physDev = (WIN16DRV_PDEVICE *)HeapAlloc( GetProcessHeap(), 0, sizeof(*physDev) );
     if (!physDev) return FALSE;
     dc->physDev = physDev;
 
@@ -218,7 +218,7 @@
     if (pLPD == NULL)
     {
 	WARN("Failed to find printer driver\n");
-        HeapFree( SystemHeap, 0, physDev );
+        HeapFree( GetProcessHeap(), 0, physDev );
         return FALSE;
     }
     TRACE("windevCreateDC pLPD 0x%p\n", pLPD);
diff --git a/graphics/win16drv/prtdrv.c b/graphics/win16drv/prtdrv.c
index 47ad848..ac97af5 100644
--- a/graphics/win16drv/prtdrv.c
+++ b/graphics/win16drv/prtdrv.c
@@ -185,7 +185,7 @@
 	memset(pLPD, 0 , sizeof(LOADED_PRINTER_DRIVER));
 	
 	pLPD->hInst	= hInst;
-	pLPD->szDriver	= HEAP_strdupA(SystemHeap,0,pszDriver);
+	pLPD->szDriver	= HEAP_strdupA(GetProcessHeap(),0,pszDriver);
 
 	/* Get DS for the printer module */
 	pLPD->ds_reg	= hInst;
@@ -421,7 +421,7 @@
 	    RGNDATA *clip;
 
 	    size = GetRegionData( hClipRgn, 0, NULL );
-	    clip = HeapAlloc( SystemHeap, 0, size );
+	    clip = HeapAlloc( GetProcessHeap(), 0, size );
 	    if(!clip) 
 	    {
 	        WARN("Can't alloc clip array in PRTDRV_Output\n");
@@ -456,7 +456,7 @@
 		}
 		SEGPTR_FREE(lP8);
 	    }
-	    HeapFree( SystemHeap, 0, clip );
+	    HeapFree( GetProcessHeap(), 0, clip );
 	}
 	else
 	{
diff --git a/graphics/x11drv/xfont.c b/graphics/x11drv/xfont.c
index 6989bb6..b596a14 100644
--- a/graphics/x11drv/xfont.c
+++ b/graphics/x11drv/xfont.c
@@ -328,7 +328,7 @@
     if (*lpch)
 	WARN("Extra ignored in font '%s'\n", lpFont);
     
-    lfd = HeapAlloc( SystemHeap, 0, sizeof(LFD) );
+    lfd = HeapAlloc( GetProcessHeap(), 0, sizeof(LFD) );
     if (lfd)
     {
 	lfd->foundry = lfd_fld[0];
@@ -1341,7 +1341,7 @@
 		XFONT_LoadDefaultLFD(lfd, fonttype);
 	    else
 		WARN("Ini section [%s]%s is malformed\n", INIFontSection, ini);
-	    HeapFree(SystemHeap, 0, lfd);
+	    HeapFree(GetProcessHeap(), 0, lfd);
 	}
     }   
 }
@@ -1376,7 +1376,7 @@
     }
 
     j = lstrlenA(lpTypeFace) + 1;
-    pfa = HeapAlloc( SystemHeap, 0, sizeof(fontAlias) +
+    pfa = HeapAlloc( GetProcessHeap(), 0, sizeof(fontAlias) +
 			       j + lstrlenA(lpAlias) + 1 );
     if (pfa)
     {
@@ -1444,7 +1444,7 @@
 
 		/* Update any references to the substituted font in aliasTable */
 		if(!strcmp(frMatch->lfFaceName, pfa->faTypeFace))
-		    pfa->faTypeFace = HEAP_strdupA( SystemHeap, 0, lpAlias );
+		    pfa->faTypeFace = HEAP_strdupA( GetProcessHeap(), 0, lpAlias );
 		prev = pfa;
 	    }
 						
@@ -1511,7 +1511,7 @@
 	XFONT_LoadAlias( lfd, "Times New Roman", FALSE);
 
 	XFONT_LoadDefaultLFD( lfd, "serif ");
-	HeapFree(SystemHeap, 0, lfd);
+	HeapFree(GetProcessHeap(), 0, lfd);
     }
 	
     PROFILE_GetWineIniString( INIFontSection, INIDefaultSansSerif,
@@ -1525,7 +1525,7 @@
 	XFONT_LoadAlias( lfd, "Arial", FALSE);
 
 	XFONT_LoadDefaultLFD( lfd, "sans serif ");
-	HeapFree(SystemHeap, 0, lfd);
+	HeapFree(GetProcessHeap(), 0, lfd);
     }
 
     /* then user specified aliases */
@@ -1549,7 +1549,7 @@
 	    if (lfd)
 	    {
 		XFONT_LoadAlias(lfd, buffer, bSubst);
-		HeapFree(SystemHeap, 0, lfd);
+		HeapFree(GetProcessHeap(), 0, lfd);
 	    }
 	}
 	else
@@ -1601,10 +1601,10 @@
     while( pfr->fi )
     {
 	pfi = pfr->fi->next;
-	HeapFree( SystemHeap, 0, pfr->fi );
+	HeapFree( GetProcessHeap(), 0, pfr->fi );
 	pfr->fi = pfi;
     }
-    HeapFree( SystemHeap, 0, pfr );
+    HeapFree( GetProcessHeap(), 0, pfr );
 #endif
     *ppfr = pfr->next;
 }
@@ -1647,7 +1647,7 @@
     else
 	WARN("Malformed font resource\n");
     
-    HeapFree(SystemHeap, 0, lfd);
+    HeapFree(GetProcessHeap(), 0, lfd);
 }
 
 static void XFONT_LoadIgnores(void)
@@ -1696,7 +1696,7 @@
 	int i = strlen( home ) + strlen( INIWinePrefix ) + 
 		strlen( INIFontMetrics ) + strlen( pchDisplay ) + 2;
 	if( i > *buf_size ) 
-	    buffer = (char*) HeapReAlloc( SystemHeap, 0, buffer, *buf_size = i );
+	    buffer = (char*) HeapReAlloc( GetProcessHeap(), 0, buffer, *buf_size = i );
 	strcpy( buffer, home );
 	strcat( buffer, INIWinePrefix );
 	strcat( buffer, INIFontMetrics );
@@ -1759,7 +1759,7 @@
 	    fr->fi_count--;
             if( prev ) prev->next = pfi = pfi->next;
             else fr->fi = pfi = pfi->next;
-	    HeapFree( SystemHeap, 0, subset );
+	    HeapFree( GetProcessHeap(), 0, subset );
 	    continue;
         }
     }
@@ -1834,14 +1834,14 @@
 	XFontStruct*  x_fs;
 	fontInfo*    pfi;
 
-	typeface = HEAP_strdupA(SystemHeap, 0, x_pattern[i]);
+	typeface = HEAP_strdupA(GetProcessHeap(), 0, x_pattern[i]);
 	if (!typeface)
 	    break;
 
 	lfd = LFD_Parse(typeface);
 	if (!lfd)
 	{
-	    HeapFree(SystemHeap, 0, typeface);
+	    HeapFree(GetProcessHeap(), 0, typeface);
 	    continue;
 	}
 
@@ -1854,7 +1854,7 @@
 	    pfr = fr;
 	}  
 	
-	if( !fi ) fi = (fontInfo*) HeapAlloc(SystemHeap, 0, sizeof(fontInfo));
+	if( !fi ) fi = (fontInfo*) HeapAlloc(GetProcessHeap(), 0, sizeof(fontInfo));
 	
 	if( !LFD_InitFontInfo( fi, lfd, x_pattern[i]) )
 	    goto nextfont;
@@ -1862,17 +1862,17 @@
 	if( !fr ) /* add new family */
 	{
 	    n_ff++;
-	    fr = (fontResource*) HeapAlloc(SystemHeap, 0, sizeof(fontResource)); 
+	    fr = (fontResource*) HeapAlloc(GetProcessHeap(), 0, sizeof(fontResource)); 
 	    if (fr)
 	    {
 		memset(fr, 0, sizeof(fontResource));
 	      
-		fr->resource = (LFD*) HeapAlloc(SystemHeap, 0, sizeof(LFD)); 
+		fr->resource = (LFD*) HeapAlloc(GetProcessHeap(), 0, sizeof(LFD)); 
 		memset(fr->resource, 0, sizeof(LFD));
 	      
 		TRACE("family: -%s-%s-\n", lfd->foundry, lfd->family );
-		fr->resource->foundry = HEAP_strdupA(SystemHeap, 0, lfd->foundry);
-		fr->resource->family = HEAP_strdupA(SystemHeap, 0, lfd->family);
+		fr->resource->foundry = HEAP_strdupA(GetProcessHeap(), 0, lfd->foundry);
+		fr->resource->family = HEAP_strdupA(GetProcessHeap(), 0, lfd->family);
 		fr->resource->weight = "";
 
 		if( pfr ) pfr->next = fr;
@@ -1934,10 +1934,10 @@
 	    XFONT_CheckFIList( fr, fi, UNMARK_SUBSETS );
 	}
     nextfont:
-	HeapFree(SystemHeap, 0, lfd);
-	HeapFree(SystemHeap, 0, typeface);
+	HeapFree(GetProcessHeap(), 0, lfd);
+	HeapFree(GetProcessHeap(), 0, typeface);
     }
-    if( fi ) HeapFree(SystemHeap, 0, fi);
+    if( fi ) HeapFree(GetProcessHeap(), 0, fi);
 
     return n_ff;
 }
@@ -1969,7 +1969,7 @@
 	    if( length == (i + offset) )
 	    {
 		lseek( fd, offset, SEEK_SET );
-		fontList = (fontResource*)HeapAlloc( SystemHeap, 0, i);
+		fontList = (fontResource*)HeapAlloc( GetProcessHeap(), 0, i);
 		if( fontList )
 		{
 		    fontResource* 	pfr = fontList;
@@ -2033,7 +2033,7 @@
 	    }
 	}
 fail:
-	if( fontList ) HeapFree( SystemHeap, 0, fontList );
+	if( fontList ) HeapFree( GetProcessHeap(), 0, fontList );
 	fontList = NULL;
 	close( fd );
     }
@@ -2576,7 +2576,7 @@
 
 	    /* FIXME: lpXForm, lpPixmap */
 	    if(fontCache[j].lpX11Trans)
-	        HeapFree( SystemHeap, 0, fontCache[j].lpX11Trans );
+	        HeapFree( GetProcessHeap(), 0, fontCache[j].lpX11Trans );
 
 	    TSXFreeFont( display, fontCache[j].fs );
 
@@ -2591,7 +2591,7 @@
 
 	    TRACE("\tgrowing font cache from %i to %i\n", fontCacheSize, prev_i );
 
-	    if( (newCache = (fontObject*)HeapReAlloc(SystemHeap, 0,  
+	    if( (newCache = (fontObject*)HeapReAlloc(GetProcessHeap(), 0,  
 						     fontCache, prev_i)) )
 	    {
 		i = fontCacheSize;
@@ -2654,7 +2654,7 @@
   }
   x_checksum |= X_PFONT_MAGIC;
   buf_size = 128;
-  buffer = HeapAlloc( SystemHeap, 0, buf_size );
+  buffer = HeapAlloc( GetProcessHeap(), 0, buf_size );
 
   /* deal with systemwide font metrics cache */
 
@@ -2700,7 +2700,7 @@
 	  TSXFreeFont(display, x_fs);
       }
   }
-  HeapFree(SystemHeap, 0, buffer);
+  HeapFree(GetProcessHeap(), 0, buffer);
 
   XFONT_WindowsNames();
   XFONT_LoadAliases();
@@ -2712,7 +2712,7 @@
 
   /* fontList initialization is over, allocate X font cache */
 
-  fontCache = (fontObject*) HeapAlloc(SystemHeap, 0, fontCacheSize * sizeof(fontObject));
+  fontCache = (fontObject*) HeapAlloc(GetProcessHeap(), 0, fontCacheSize * sizeof(fontObject));
   XFONT_GrowFreeList(0, fontCacheSize - 1);
 
   TRACE("done!\n");
@@ -2746,7 +2746,7 @@
   }
 
   if (lfd->pixel_size[0] != '[') {
-      HeapFree(SystemHeap, 0, lfd);
+      HeapFree(GetProcessHeap(), 0, lfd);
       TSXFree(fontName);
       return FALSE;
   }
@@ -2755,7 +2755,7 @@
 
   sscanf(lfd->pixel_size, "[%f%f%f%f]", &PX->a, &PX->b, &PX->c, &PX->d);
   TSXFree(fontName);
-  HeapFree(SystemHeap, 0, lfd);
+  HeapFree(GetProcessHeap(), 0, lfd);
 
   TSXGetFontProperty( pfo->fs, RAW_ASCENT, &PX->RAW_ASCENT );
   TSXGetFontProperty( pfo->fs, RAW_DESCENT, &PX->RAW_DESCENT );
@@ -2830,9 +2830,9 @@
 
 		
 	    if(pfo->lf.lfEscapement != 0) {
-		pfo->lpX11Trans = HeapAlloc(SystemHeap, 0, sizeof(XFONTTRANS));
+		pfo->lpX11Trans = HeapAlloc(GetProcessHeap(), 0, sizeof(XFONTTRANS));
 		if(!XFONT_SetX11Trans( pfo )) {
-		    HeapFree(SystemHeap, 0, pfo->lpX11Trans);
+		    HeapFree(GetProcessHeap(), 0, pfo->lpX11Trans);
 		    pfo->lpX11Trans = NULL;
 		}
 	    }
diff --git a/if1632/snoop.c b/if1632/snoop.c
index ac22334..c49667a 100644
--- a/if1632/snoop.c
+++ b/if1632/snoop.c
@@ -118,18 +118,18 @@
 			return; /* already registered */
 		dll = &((*dll)->next);
 	}
-	*dll = (SNOOP16_DLL*)HeapAlloc(SystemHeap,HEAP_ZERO_MEMORY,sizeof(SNOOP16_DLL));
+	*dll = (SNOOP16_DLL*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(SNOOP16_DLL));
 	(*dll)->next	= NULL;
 	(*dll)->hmod	= pModule->self;
 	if ((s=strrchr(name,'\\')))
 		name = s+1;
-	(*dll)->name	= HEAP_strdupA(SystemHeap,0,name);
+	(*dll)->name	= HEAP_strdupA(GetProcessHeap(),0,name);
 	if ((s=strrchr((*dll)->name,'.')))
 		*s='\0';
 	(*dll)->funhandle = GlobalHandleToSel16(GLOBAL_Alloc(GMEM_ZEROINIT,65535,0,TRUE,FALSE,FALSE));
 	(*dll)->funs = GlobalLock16((*dll)->funhandle);
 	if (!(*dll)->funs) {
-		HeapFree(SystemHeap,0,*dll);
+		HeapFree(GetProcessHeap(),0,*dll);
 		FIXME("out of memory\n");
 		return;
 	}
@@ -185,9 +185,9 @@
 		}
 	}
 	if (*cpnt)
-		fun->name = HEAP_strdupA(SystemHeap,0,name);
+		fun->name = HEAP_strdupA(GetProcessHeap(),0,name);
 	else
-		fun->name = HEAP_strdupA(SystemHeap,0,"");
+		fun->name = HEAP_strdupA(GetProcessHeap(),0,"");
 	if (!SNOOP_ShowDebugmsgSnoop(dll->name, ordinal, fun->name))
 		return origfun;
 
@@ -196,7 +196,7 @@
 		char *s=strchr(fun->name,'_');
 
 		if (!strncasecmp(s,"_thunkdata",10)) {
-			HeapFree(SystemHeap,0,fun->name);
+			HeapFree(GetProcessHeap(),0,fun->name);
 			fun->name = NULL;
 			return origfun;
 		}
@@ -270,7 +270,7 @@
 			DPRINTF(" ...");
 	} else if (fun->nrofargs<0) {
 		DPRINTF("<unknown, check return>");
-		ret->args = HeapAlloc(SystemHeap,0,16*sizeof(WORD));
+		ret->args = HeapAlloc(GetProcessHeap(),0,16*sizeof(WORD));
 		memcpy(ret->args,(LPBYTE)((char *) PTR_SEG_OFF_TO_LIN(SS_reg(context),LOWORD(ESP_reg(context)))+8),sizeof(WORD)*16);
 	}
 	DPRINTF(") ret=%04x:%04x\n",HIWORD(ret->origreturn),LOWORD(ret->origreturn));
@@ -306,7 +306,7 @@
 		DPRINTF(") retval = %04x:%04x ret=%04x:%04x\n",
 			DX_reg(context),AX_reg(context),HIWORD(ret->origreturn),LOWORD(ret->origreturn)
 		);
-		HeapFree(SystemHeap,0,ret->args);
+		HeapFree(GetProcessHeap(),0,ret->args);
 		ret->args = NULL;
 	} else
 		DPRINTF("Ret  %s.%ld: %s() retval = %04x:%04x ret=%04x:%04x\n",
diff --git a/if1632/thunk.c b/if1632/thunk.c
index 1f176ec..60da112 100644
--- a/if1632/thunk.c
+++ b/if1632/thunk.c
@@ -150,7 +150,7 @@
     }
 
     /* Otherwise, we need to alloc a thunk */
-    thunk = HeapAlloc( SystemHeap, 0, sizeof(*thunk) );
+    thunk = HeapAlloc( GetProcessHeap(), 0, sizeof(*thunk) );
     if (thunk)
     {
         thunk->popl_eax   = 0x58;
@@ -179,14 +179,14 @@
             || t->magic != CALLTO16_THUNK_MAGIC )
          return;
 
-    if (HEAP_IsInsideHeap( SystemHeap, 0, t ))
+    if (HEAP_IsInsideHeap( GetProcessHeap(), 0, t ))
     {
         THUNK **prev = &firstThunk;
         while (*prev && (*prev != t)) prev = &(*prev)->next;
         if (*prev)
         {
             *prev = t->next;
-            HeapFree( SystemHeap, 0, t );
+            HeapFree( GetProcessHeap(), 0, t );
             return;
         }
     }
diff --git a/include/region.h b/include/region.h
index db321b2..48a125b 100644
--- a/include/region.h
+++ b/include/region.h
@@ -1,63 +1,15 @@
 /*
  * GDI region definitions
- * Mainly taken from the X11 distribution.
- * Modifications: Copyright 1998 Huw Davies
+ *
+ * Copyright 1998 Huw Davies
  */
 
-/************************************************************************
-
-Copyright (c) 1987  X Consortium
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
-X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
-AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-Except as contained in this notice, the name of the X Consortium shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from the X Consortium.
-
-
-Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
-
-                        All Rights Reserved
-
-Permission to use, copy, modify, and distribute this software and its 
-documentation for any purpose and without fee is hereby granted, 
-provided that the above copyright notice appear in all copies and that
-both that copyright notice and this permission notice appear in 
-supporting documentation, and that the name of Digital not be
-used in advertising or publicity pertaining to distribution of the
-software without specific, written prior permission.  
-
-DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
-ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
-DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
-ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
-WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
-ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
-SOFTWARE.
-
-************************************************************************/
 #ifndef __WINE_REGION_H
 #define __WINE_REGION_H
 
 #include "wingdi.h"
 #include "gdi.h"
 
-
 typedef struct {
     INT size;
     INT numRects;
@@ -73,309 +25,6 @@
     WINEREGION  *rgn;
 } RGNOBJ;
 
-/*  1 if two RECTs overlap.
- *  0 if two RECTs do not overlap.
- */
-#define EXTENTCHECK(r1, r2) \
-	((r1)->right > (r2)->left && \
-	 (r1)->left < (r2)->right && \
-	 (r1)->bottom > (r2)->top && \
-	 (r1)->top < (r2)->bottom)
-
-/*
- *   Check to see if there is enough memory in the present region.
- */
-#define MEMCHECK(reg, rect, firstrect){\
-        if ((reg)->numRects >= ((reg)->size - 1)){\
-          (firstrect) = HeapReAlloc( SystemHeap, 0, \
-           (firstrect), (2 * (sizeof(RECT)) * ((reg)->size)));\
-          if ((firstrect) == 0)\
-            return;\
-          (reg)->size *= 2;\
-          (rect) = &(firstrect)[(reg)->numRects];\
-         }\
-       }
-
-#define EMPTY_REGION(pReg) { \
-    (pReg)->numRects = 0; \
-    (pReg)->extents.left = (pReg)->extents.top = 0; \
-    (pReg)->extents.right = (pReg)->extents.bottom = 0; \
-    (pReg)->type = NULLREGION; \
- }
-
-#define REGION_NOT_EMPTY(pReg) pReg->numRects
-
-#define INRECT(r, x, y) \
-      ( ( ((r).right >  x)) && \
-        ( ((r).left <= x)) && \
-        ( ((r).bottom >  y)) && \
-        ( ((r).top <= y)) )
-
-
-/*
- * number of points to buffer before sending them off
- * to scanlines() :  Must be an even number
- */
-#define NUMPTSTOBUFFER 200
-
-/*
- * used to allocate buffers for points and link
- * the buffers together
- */
-
-typedef struct _POINTBLOCK {
-    POINT pts[NUMPTSTOBUFFER];
-    struct _POINTBLOCK *next;
-} POINTBLOCK;
-
-
-
-/*
- *     This file contains a few macros to help track
- *     the edge of a filled object.  The object is assumed
- *     to be filled in scanline order, and thus the
- *     algorithm used is an extension of Bresenham's line
- *     drawing algorithm which assumes that y is always the
- *     major axis.
- *     Since these pieces of code are the same for any filled shape,
- *     it is more convenient to gather the library in one
- *     place, but since these pieces of code are also in
- *     the inner loops of output primitives, procedure call
- *     overhead is out of the question.
- *     See the author for a derivation if needed.
- */
-
-
-/*
- *  In scan converting polygons, we want to choose those pixels
- *  which are inside the polygon.  Thus, we add .5 to the starting
- *  x coordinate for both left and right edges.  Now we choose the
- *  first pixel which is inside the pgon for the left edge and the
- *  first pixel which is outside the pgon for the right edge.
- *  Draw the left pixel, but not the right.
- *
- *  How to add .5 to the starting x coordinate:
- *      If the edge is moving to the right, then subtract dy from the
- *  error term from the general form of the algorithm.
- *      If the edge is moving to the left, then add dy to the error term.
- *
- *  The reason for the difference between edges moving to the left
- *  and edges moving to the right is simple:  If an edge is moving
- *  to the right, then we want the algorithm to flip immediately.
- *  If it is moving to the left, then we don't want it to flip until
- *  we traverse an entire pixel.
- */
-#define BRESINITPGON(dy, x1, x2, xStart, d, m, m1, incr1, incr2) { \
-    int dx;      /* local storage */ \
-\
-    /* \
-     *  if the edge is horizontal, then it is ignored \
-     *  and assumed not to be processed.  Otherwise, do this stuff. \
-     */ \
-    if ((dy) != 0) { \
-        xStart = (x1); \
-        dx = (x2) - xStart; \
-        if (dx < 0) { \
-            m = dx / (dy); \
-            m1 = m - 1; \
-            incr1 = -2 * dx + 2 * (dy) * m1; \
-            incr2 = -2 * dx + 2 * (dy) * m; \
-            d = 2 * m * (dy) - 2 * dx - 2 * (dy); \
-        } else { \
-            m = dx / (dy); \
-            m1 = m + 1; \
-            incr1 = 2 * dx - 2 * (dy) * m1; \
-            incr2 = 2 * dx - 2 * (dy) * m; \
-            d = -2 * m * (dy) + 2 * dx; \
-        } \
-    } \
-}
-
-#define BRESINCRPGON(d, minval, m, m1, incr1, incr2) { \
-    if (m1 > 0) { \
-        if (d > 0) { \
-            minval += m1; \
-            d += incr1; \
-        } \
-        else { \
-            minval += m; \
-            d += incr2; \
-        } \
-    } else {\
-        if (d >= 0) { \
-            minval += m1; \
-            d += incr1; \
-        } \
-        else { \
-            minval += m; \
-            d += incr2; \
-        } \
-    } \
-}
-
-/*
- *     This structure contains all of the information needed
- *     to run the bresenham algorithm.
- *     The variables may be hardcoded into the declarations
- *     instead of using this structure to make use of
- *     register declarations.
- */
-typedef struct {
-    INT minor_axis;	/* minor axis        */
-    INT d;		/* decision variable */
-    INT m, m1;       	/* slope and slope+1 */
-    INT incr1, incr2;	/* error increments */
-} BRESINFO;
-
-
-#define BRESINITPGONSTRUCT(dmaj, min1, min2, bres) \
-	BRESINITPGON(dmaj, min1, min2, bres.minor_axis, bres.d, \
-                     bres.m, bres.m1, bres.incr1, bres.incr2)
-
-#define BRESINCRPGONSTRUCT(bres) \
-        BRESINCRPGON(bres.d, bres.minor_axis, bres.m, bres.m1, bres.incr1, bres.incr2)
-
-
-
-/*
- *     These are the data structures needed to scan
- *     convert regions.  Two different scan conversion
- *     methods are available -- the even-odd method, and
- *     the winding number method.
- *     The even-odd rule states that a point is inside
- *     the polygon if a ray drawn from that point in any
- *     direction will pass through an odd number of
- *     path segments.
- *     By the winding number rule, a point is decided
- *     to be inside the polygon if a ray drawn from that
- *     point in any direction passes through a different
- *     number of clockwise and counter-clockwise path
- *     segments.
- *
- *     These data structures are adapted somewhat from
- *     the algorithm in (Foley/Van Dam) for scan converting
- *     polygons.
- *     The basic algorithm is to start at the top (smallest y)
- *     of the polygon, stepping down to the bottom of
- *     the polygon by incrementing the y coordinate.  We
- *     keep a list of edges which the current scanline crosses,
- *     sorted by x.  This list is called the Active Edge Table (AET)
- *     As we change the y-coordinate, we update each entry in 
- *     in the active edge table to reflect the edges new xcoord.
- *     This list must be sorted at each scanline in case
- *     two edges intersect.
- *     We also keep a data structure known as the Edge Table (ET),
- *     which keeps track of all the edges which the current
- *     scanline has not yet reached.  The ET is basically a
- *     list of ScanLineList structures containing a list of
- *     edges which are entered at a given scanline.  There is one
- *     ScanLineList per scanline at which an edge is entered.
- *     When we enter a new edge, we move it from the ET to the AET.
- *
- *     From the AET, we can implement the even-odd rule as in
- *     (Foley/Van Dam).
- *     The winding number rule is a little trickier.  We also
- *     keep the EdgeTableEntries in the AET linked by the
- *     nextWETE (winding EdgeTableEntry) link.  This allows
- *     the edges to be linked just as before for updating
- *     purposes, but only uses the edges linked by the nextWETE
- *     link as edges representing spans of the polygon to
- *     drawn (as with the even-odd rule).
- */
-
-/*
- * for the winding number rule
- */
-#define CLOCKWISE          1
-#define COUNTERCLOCKWISE  -1 
-
-typedef struct _EdgeTableEntry {
-     INT ymax;           /* ycoord at which we exit this edge. */
-     BRESINFO bres;        /* Bresenham info to run the edge     */
-     struct _EdgeTableEntry *next;       /* next in the list     */
-     struct _EdgeTableEntry *back;       /* for insertion sort   */
-     struct _EdgeTableEntry *nextWETE;   /* for winding num rule */
-     int ClockWise;        /* flag for winding number rule       */
-} EdgeTableEntry;
-
-
-typedef struct _ScanLineList{
-     INT scanline;            /* the scanline represented */
-     EdgeTableEntry *edgelist;  /* header node              */
-     struct _ScanLineList *next;  /* next in the list       */
-} ScanLineList;
-
-
-typedef struct {
-     INT ymax;               /* ymax for the polygon     */
-     INT ymin;               /* ymin for the polygon     */
-     ScanLineList scanlines;   /* header node              */
-} EdgeTable;
-
-
-/*
- * Here is a struct to help with storage allocation
- * so we can allocate a big chunk at a time, and then take
- * pieces from this heap when we need to.
- */
-#define SLLSPERBLOCK 25
-
-typedef struct _ScanLineListBlock {
-     ScanLineList SLLs[SLLSPERBLOCK];
-     struct _ScanLineListBlock *next;
-} ScanLineListBlock;
-
-
-/*
- *
- *     a few macros for the inner loops of the fill code where
- *     performance considerations don't allow a procedure call.
- *
- *     Evaluate the given edge at the given scanline.
- *     If the edge has expired, then we leave it and fix up
- *     the active edge table; otherwise, we increment the
- *     x value to be ready for the next scanline.
- *     The winding number rule is in effect, so we must notify
- *     the caller when the edge has been removed so he
- *     can reorder the Winding Active Edge Table.
- */
-#define EVALUATEEDGEWINDING(pAET, pPrevAET, y, fixWAET) { \
-   if (pAET->ymax == y) {          /* leaving this edge */ \
-      pPrevAET->next = pAET->next; \
-      pAET = pPrevAET->next; \
-      fixWAET = 1; \
-      if (pAET) \
-         pAET->back = pPrevAET; \
-   } \
-   else { \
-      BRESINCRPGONSTRUCT(pAET->bres); \
-      pPrevAET = pAET; \
-      pAET = pAET->next; \
-   } \
-}
-
-
-/*
- *     Evaluate the given edge at the given scanline.
- *     If the edge has expired, then we leave it and fix up
- *     the active edge table; otherwise, we increment the
- *     x value to be ready for the next scanline.
- *     The even-odd rule is in effect.
- */
-#define EVALUATEEDGEEVENODD(pAET, pPrevAET, y) { \
-   if (pAET->ymax == y) {          /* leaving this edge */ \
-      pPrevAET->next = pAET->next; \
-      pAET = pPrevAET->next; \
-      if (pAET) \
-         pAET->back = pPrevAET; \
-   } \
-   else { \
-      BRESINCRPGONSTRUCT(pAET->bres); \
-      pPrevAET = pAET; \
-      pAET = pAET->next; \
-   } \
-}
-
 extern BOOL REGION_DeleteObject( HRGN hrgn, RGNOBJ * obj );
 extern BOOL REGION_UnionRectWithRgn( HRGN hrgn, const RECT *lpRect );
 extern HRGN REGION_CropRgn( HRGN hDst, HRGN hSrc, const RECT *lpRect, const POINT *lpPt );
diff --git a/loader/loadorder.c b/loader/loadorder.c
index 554f57e..df47cdd 100644
--- a/loader/loadorder.c
+++ b/loader/loadorder.c
@@ -90,13 +90,13 @@
 
 	if(str && buf)
 	{
-		HeapFree(SystemHeap, 0, buf);
+		HeapFree(GetProcessHeap(), 0, buf);
 		buf = NULL;
 	}
 
 	if(str && !buf)
 	{
-		buf = HEAP_strdupA(SystemHeap, 0, str);
+		buf = HEAP_strdupA(GetProcessHeap(), 0, str);
 		cptr = strtok(buf, delim);
 	}
 	else
@@ -106,7 +106,7 @@
 
 	if(!cptr)
 	{
-		HeapFree(SystemHeap, 0, buf);
+		HeapFree(GetProcessHeap(), 0, buf);
 		buf = NULL;
 	}
 	return cptr;
@@ -193,7 +193,7 @@
 	{
 		/* No space in current array, make it larger */
 		nmodule_loadorder_alloc += LOADORDER_ALLOC_CLUSTER;
-		module_loadorder = (module_loadorder_t *)HeapReAlloc(SystemHeap,
+		module_loadorder = (module_loadorder_t *)HeapReAlloc(GetProcessHeap(),
 								     0,
 								     module_loadorder,
 								     nmodule_loadorder_alloc * sizeof(module_loadorder_t));
@@ -204,7 +204,7 @@
 		}
 	}
 	memcpy(module_loadorder[nmodule_loadorder].loadorder, plo->loadorder, sizeof(plo->loadorder));
-	module_loadorder[nmodule_loadorder].modulename = HEAP_strdupA(SystemHeap, 0, plo->modulename);
+	module_loadorder[nmodule_loadorder].modulename = HEAP_strdupA(GetProcessHeap(), 0, plo->modulename);
 	nmodule_loadorder++;
 	return TRUE;
 }
@@ -262,7 +262,7 @@
 	if(!Options.dllFlags)
 		return TRUE;
 
-	cpy = HEAP_strdupA(SystemHeap, 0, Options.dllFlags);
+	cpy = HEAP_strdupA(GetProcessHeap(), 0, Options.dllFlags);
 	key = cpy;
 	next = key;
 	for(; next; key = next)
@@ -291,7 +291,7 @@
 		}
 	}
 endit:
-	HeapFree(SystemHeap, 0, cpy);
+	HeapFree(GetProcessHeap(), 0, cpy);
 	return retval;;
 }
 
@@ -375,7 +375,7 @@
 
 	if(nbuffer)
 	{
-		extra_ld_library_path = HEAP_strdupA(SystemHeap, 0, buffer);
+		extra_ld_library_path = HEAP_strdupA(GetProcessHeap(), 0, buffer);
 		TRACE("Setting extra LD_LIBRARY_PATH=%s\n", buffer);
 	}
 #endif
diff --git a/loader/ne/module.c b/loader/ne/module.c
index 3f203d7..74ad1aa 100644
--- a/loader/ne/module.c
+++ b/loader/ne/module.c
@@ -499,12 +499,12 @@
         fastload_length=ne_header.fastload_length<<ne_header.align_shift_count;
         TRACE("Using fast-load area offset=%x len=%d\n",
                         fastload_offset, fastload_length );
-        if ((fastload = HeapAlloc( SystemHeap, 0, fastload_length )) != NULL)
+        if ((fastload = HeapAlloc( GetProcessHeap(), 0, fastload_length )) != NULL)
         {
             _llseek16( hFile, fastload_offset, SEEK_SET);
             if (_hread16(hFile, fastload, fastload_length) != fastload_length)
             {
-                HeapFree( SystemHeap, 0, fastload );
+                HeapFree( GetProcessHeap(), 0, fastload );
                 WARN("Error reading fast-load area!\n");
                 fastload = NULL;
             }
@@ -514,7 +514,7 @@
     /* Get the segment table */
 
     pModule->seg_table = (int)pData - (int)pModule;
-    buffer = HeapAlloc( SystemHeap, 0, ne_header.n_segment_tab *
+    buffer = HeapAlloc( GetProcessHeap(), 0, ne_header.n_segment_tab *
                                       sizeof(struct ne_segment_table_entry_s));
     if (buffer)
     {
@@ -525,9 +525,9 @@
              ne_header.n_segment_tab * sizeof(struct ne_segment_table_entry_s),
              buffer ))
         {
-            HeapFree( SystemHeap, 0, buffer );
+            HeapFree( GetProcessHeap(), 0, buffer );
             if (fastload)
-		HeapFree( SystemHeap, 0, fastload );
+		HeapFree( GetProcessHeap(), 0, fastload );
             GlobalFree16( hModule );
             _lclose16( hFile );
             return (HMODULE16)11;  /* invalid exe */
@@ -538,12 +538,12 @@
             memcpy( pData, pSeg, sizeof(*pSeg) );
             pData += sizeof(SEGTABLEENTRY);
         }
-        HeapFree( SystemHeap, 0, buffer );
+        HeapFree( GetProcessHeap(), 0, buffer );
     }
     else
     {
         if (fastload)
-	    HeapFree( SystemHeap, 0, fastload );
+	    HeapFree( GetProcessHeap(), 0, fastload );
         GlobalFree16( hModule );
         _lclose16( hFile );
         return (HMODULE16)11;  /* invalid exe */
@@ -574,7 +574,7 @@
                pData ))
     {
         if (fastload)
-	    HeapFree( SystemHeap, 0, fastload );
+	    HeapFree( GetProcessHeap(), 0, fastload );
         GlobalFree16( hModule );
         _lclose16( hFile );
         return (HMODULE16)11;  /* invalid exe */
@@ -591,7 +591,7 @@
                   pData ))
         {
             if (fastload)
-		HeapFree( SystemHeap, 0, fastload );
+		HeapFree( GetProcessHeap(), 0, fastload );
             GlobalFree16( hModule );
             _lclose16( hFile );
             return (HMODULE16)11;  /* invalid exe */
@@ -608,7 +608,7 @@
                pData ))
     {
         if (fastload)
-	    HeapFree( SystemHeap, 0, fastload );
+	    HeapFree( GetProcessHeap(), 0, fastload );
         GlobalFree16( hModule );
         _lclose16( hFile );
         return (HMODULE16)11;  /* invalid exe */
@@ -617,7 +617,7 @@
 
     /* Load entry table, convert it to the optimized version used by Windows */
 
-    if ((pTempEntryTable = HeapAlloc( SystemHeap, 0, ne_header.entry_tab_length)) != NULL)
+    if ((pTempEntryTable = HeapAlloc( GetProcessHeap(), 0, ne_header.entry_tab_length)) != NULL)
     {
         BYTE nr_entries, type, *s;
 
@@ -626,9 +626,9 @@
     if (!READ( mz_header.e_lfanew + ne_header.entry_tab_offset,
                 ne_header.entry_tab_length, pTempEntryTable ))
     {
-            HeapFree( SystemHeap, 0, pTempEntryTable );
+            HeapFree( GetProcessHeap(), 0, pTempEntryTable );
             if (fastload)
-		HeapFree( SystemHeap, 0, fastload );
+		HeapFree( GetProcessHeap(), 0, fastload );
         GlobalFree16( hModule );
         _lclose16( hFile );
         return (HMODULE16)11;  /* invalid exe */
@@ -689,12 +689,12 @@
                 }
             }
         }
-	HeapFree( SystemHeap, 0, pTempEntryTable );
+	HeapFree( GetProcessHeap(), 0, pTempEntryTable );
     }
     else
     {
         if (fastload)
-	    HeapFree( SystemHeap, 0, fastload );
+	    HeapFree( GetProcessHeap(), 0, fastload );
         GlobalFree16( hModule );
         _lclose16( hFile );
         return (HMODULE16)11;  /* invalid exe */
@@ -718,7 +718,7 @@
 
 #undef READ
     if (fastload)
-	HeapFree( SystemHeap, 0, fastload );
+	HeapFree( GetProcessHeap(), 0, fastload );
 
     /* Get the non-resident names table */
 
diff --git a/misc/ddeml.c b/misc/ddeml.c
index 41bd899..ee20075 100644
--- a/misc/ddeml.c
+++ b/misc/ddeml.c
@@ -305,7 +305,7 @@
 	if (!ReleaseMutex(mutex))
         {
 		ERR("ReleaseMutex failed - %s mutex %li\n",mutex_name,GetLastError());
-		HeapFree(SystemHeap, 0, this_instance);
+		HeapFree(GetProcessHeap(), 0, this_instance);
 		if ( release_handle_m )
 		{
 			ReleaseMutex(handle_mutex);
@@ -314,7 +314,7 @@
          }
 	if ( release_this_i )
 	{
-                HeapFree(SystemHeap, 0, this_instance);
+                HeapFree(GetProcessHeap(), 0, this_instance);
 	}
 	return DMLERR_NO_ERROR;
 }
@@ -565,7 +565,7 @@
 
      /* grab enough heap for one control struct - not really necessary for re-initialise
       *	but allows us to use same validation routines */
-     this_instance= (DDE_HANDLE_ENTRY*)HeapAlloc( SystemHeap, 0, sizeof(DDE_HANDLE_ENTRY) );
+     this_instance= (DDE_HANDLE_ENTRY*)HeapAlloc( GetProcessHeap(), 0, sizeof(DDE_HANDLE_ENTRY) );
      if ( this_instance == NULL )
      {
 	/* catastrophe !! warn user & abort */
@@ -616,7 +616,7 @@
 	handle_mutex = ConvertToGlobalHandle(handle_mutex); /* fixme when having seperate adresspaces*/
 	if ( !handle_mutex ) {
 		ERR("CreateMutex failed - handle list  %li\n",GetLastError());
-		HeapFree(SystemHeap, 0, this_instance);
+		HeapFree(GetProcessHeap(), 0, this_instance);
 		return DMLERR_SYS_ERROR;
 	}
     } else {
@@ -706,7 +706,7 @@
 
 	if ( !WaitForMutex(handle_mutex)  )
 	{
-		HeapFree(SystemHeap, 0, this_instance);
+		HeapFree(GetProcessHeap(), 0, this_instance);
 		return DMLERR_SYS_ERROR;
         }
 
@@ -715,7 +715,7 @@
 		if ( Release_reserved_mutex(handle_mutex,"handle_mutex",0,1,this_instance)) return DMLERR_SYS_ERROR;
         	return DMLERR_DLL_USAGE;
  	}
-        HeapFree(SystemHeap, 0, this_instance); /* finished - release heap space used as work store */
+        HeapFree(GetProcessHeap(), 0, this_instance); /* finished - release heap space used as work store */
         /* can't reinitialise if we have initialised nothing !! */
         reference_inst =  DDE_Handle_Table_Base;
         /* must first check if we have been given a valid instance to re-initialise !!  how do we do that ? */
@@ -1888,10 +1888,10 @@
 			reference_service = this_service;
 			this_service = this_service->next;
 			DdeReleaseAtom(reference_inst,reference_service->hsz);
-        		HeapFree(SystemHeap, 0, reference_service); /* finished - release heap space used as work store */
+        		HeapFree(GetProcessHeap(), 0, reference_service); /* finished - release heap space used as work store */
 		}
 		DdeReleaseAtom(reference_inst,this_service->hsz);
-        	HeapFree(SystemHeap, 0, this_service); /* finished - release heap space used as work store */
+        	HeapFree(GetProcessHeap(), 0, this_service); /* finished - release heap space used as work store */
 		reference_inst->ServiceNames = NULL;
 		TRACE("General de-register - finished\n");
 	}
@@ -1913,7 +1913,7 @@
 
 		DdeReserveAtom(reference_inst, hsz1);
 
-		this_service = (ServiceNode*)HeapAlloc( SystemHeap, 0, sizeof(ServiceNode) );
+		this_service = (ServiceNode*)HeapAlloc( GetProcessHeap(), 0, sizeof(ServiceNode) );
 		this_service->hsz = hsz1;
 		this_service->FilterOn = TRUE;
 
@@ -1937,7 +1937,7 @@
 	{
 		*pServiceNode = this_service->next;
 		DdeReleaseAtom(reference_inst,this_service->hsz);
-        	HeapFree(SystemHeap, 0, this_service);
+        	HeapFree(GetProcessHeap(), 0, this_service);
  	}
   }
   if ( afCmd & DNS_FILTERON )
diff --git a/misc/toolhelp.c b/misc/toolhelp.c
index 136d344..6a664f0 100644
--- a/misc/toolhelp.c
+++ b/misc/toolhelp.c
@@ -50,10 +50,10 @@
             break;
     if (i==nrofnotifys) {
         if (notifys==NULL)
-            notifys=(struct notify*)HeapAlloc( SystemHeap, 0,
+            notifys=(struct notify*)HeapAlloc( GetProcessHeap(), 0,
                                                sizeof(struct notify) );
         else
-            notifys=(struct notify*)HeapReAlloc( SystemHeap, 0, notifys,
+            notifys=(struct notify*)HeapReAlloc( GetProcessHeap(), 0, notifys,
                                         sizeof(struct notify)*(nrofnotifys+1));
         if (!notifys) return FALSE;
         nrofnotifys++;
@@ -76,7 +76,7 @@
     if (i==-1)
         return FALSE;
     memcpy(notifys+i,notifys+(i+1),sizeof(struct notify)*(nrofnotifys-i-1));
-    notifys=(struct notify*)HeapReAlloc( SystemHeap, 0, notifys,
+    notifys=(struct notify*)HeapReAlloc( GetProcessHeap(), 0, notifys,
                                         (nrofnotifys-1)*sizeof(struct notify));
     nrofnotifys--;
     return TRUE;
diff --git a/objects/enhmetafile.c b/objects/enhmetafile.c
index db5df94..21a95c7 100644
--- a/objects/enhmetafile.c
+++ b/objects/enhmetafile.c
@@ -63,7 +63,7 @@
 	CloseHandle( metaObj->hMapping );
 	CloseHandle( metaObj->hFile );
     } else
-        HeapFree( SystemHeap, 0, metaObj->emh );
+        HeapFree( GetProcessHeap(), 0, metaObj->emh );
     return GDI_FreeObject( hmf );
 }
 
@@ -256,7 +256,7 @@
  */
 HENHMETAFILE WINAPI SetEnhMetaFileBits(UINT bufsize, const BYTE *buf)
 {
-    ENHMETAHEADER *emh = HeapAlloc( SystemHeap, 0, bufsize );
+    ENHMETAHEADER *emh = HeapAlloc( GetProcessHeap(), 0, bufsize );
     memmove(emh, buf, bufsize);
     return EMF_Create_HENHMETAFILE( emh, 0, 0 );
 }
@@ -1333,7 +1333,7 @@
 
     if(!emrSrc) return FALSE;
     if (!file) {
-        emrDst = HeapAlloc( SystemHeap, 0, emrSrc->nBytes );
+        emrDst = HeapAlloc( GetProcessHeap(), 0, emrSrc->nBytes );
 	memcpy( emrDst, emrSrc, emrSrc->nBytes );
 	hmfDst = EMF_Create_HENHMETAFILE( emrDst, 0, 0 );
     } else {
@@ -1478,7 +1478,7 @@
      /* 1. Get the header - skip over this and get straight to the records  */
 
      uNewEnhMetaFileBufferSize = sizeof( ENHMETAHEADER );
-     lpNewEnhMetaFileBuffer = HeapAlloc( SystemHeap, HEAP_ZERO_MEMORY, 
+     lpNewEnhMetaFileBuffer = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, 
                                          uNewEnhMetaFileBufferSize );
 
      if( lpNewEnhMetaFileBuffer == NULL )
@@ -1533,7 +1533,7 @@
 #define EMF_ReAllocAndAdjustPointers( a , b ) \
                                         { \
                                           LPVOID lpTmp; \
-                                          lpTmp = HeapReAlloc( SystemHeap, 0, \
+                                          lpTmp = HeapReAlloc( GetProcessHeap(), 0, \
                                                                lpNewEnhMetaFileBuffer, \
                                                                uNewEnhMetaFileBufferSize + (b) ); \
                                           if( lpTmp == NULL ) { ERR( "No memory!\n" ); goto error; } \
@@ -1802,7 +1802,7 @@
 
 error:
      /* Free the data associated with our copy since it's been copied */
-     HeapFree( SystemHeap, 0, lpNewEnhMetaFileBuffer ); 
+     HeapFree( GetProcessHeap(), 0, lpNewEnhMetaFileBuffer ); 
 
      return 0;  
 }
diff --git a/objects/metafile.c b/objects/metafile.c
index f16d1ba..6c52e57 100644
--- a/objects/metafile.c
+++ b/objects/metafile.c
@@ -165,7 +165,7 @@
     METAHEADER *mh = MF_GetMetaHeader( hmf );
 
     if(!mh) return FALSE;
-    HeapFree( SystemHeap, 0, mh );
+    HeapFree( GetProcessHeap(), 0, mh );
     GDI_FreeObject( hmf );
     return TRUE;
 }
@@ -182,21 +182,21 @@
     DWORD BytesRead, size;
 
     size = sizeof(METAHEADER);
-    mh = HeapAlloc( SystemHeap, 0, size );
+    mh = HeapAlloc( GetProcessHeap(), 0, size );
     if(!mh) return NULL;
     if(ReadFile( hfile, mh, size, &BytesRead, NULL) == 0 ||
        BytesRead != size) {
-        HeapFree( SystemHeap, 0, mh );
+        HeapFree( GetProcessHeap(), 0, mh );
 	return NULL;
     }
     size = mh->mtSize * 2;
-    mh = HeapReAlloc( SystemHeap, 0, mh, size );
+    mh = HeapReAlloc( GetProcessHeap(), 0, mh, size );
     if(!mh) return NULL;
     size -= sizeof(METAHEADER);
     if(ReadFile( hfile, (char *)mh + sizeof(METAHEADER), size, &BytesRead,
 		 NULL) == 0 ||
        BytesRead != size) {
-        HeapFree( SystemHeap, 0, mh );
+        HeapFree( GetProcessHeap(), 0, mh );
 	return NULL;
     }
 
@@ -319,10 +319,10 @@
     METAHEADERDISK *mhd;
     DWORD size;
 
-    mh = HeapReAlloc( SystemHeap, 0, mh,
+    mh = HeapReAlloc( GetProcessHeap(), 0, mh,
 		      sizeof(METAHEADER) + sizeof(METAHEADERDISK));
     mh->mtType = METAFILE_DISK;
-    size = HeapSize( SystemHeap, 0, mh );
+    size = HeapSize( GetProcessHeap(), 0, mh );
     mhd = (METAHEADERDISK *)((char *)mh + sizeof(METAHEADER));
     strcpy(mhd->filename, filename);
     return mh;
@@ -344,7 +344,7 @@
     if(mh->mtType == METAFILE_DISK)
         mh2 = MF_LoadDiskBasedMetaFile(mh);
     else {
-        mh2 = HeapAlloc( SystemHeap, 0, mh->mtSize * 2 );
+        mh2 = HeapAlloc( GetProcessHeap(), 0, mh->mtSize * 2 );
         memcpy( mh2, mh, mh->mtSize * 2 );
     }
     MF_ReleaseMetaHeader16( hSrcMetaFile );
@@ -352,7 +352,7 @@
     if(lpFilename) {         /* disk based metafile */
         if((hFile = CreateFileA(lpFilename, GENERIC_WRITE, 0, NULL,
 				CREATE_ALWAYS, 0, -1)) == HFILE_ERROR) {
-	    HeapFree( SystemHeap, 0, mh2 );
+	    HeapFree( GetProcessHeap(), 0, mh2 );
 	    return 0;
 	}
 	WriteFile(hFile, mh2, mh2->mtSize * 2, NULL, NULL);
@@ -394,7 +394,7 @@
     if(mh->mtType == METAFILE_DISK)
         mh2 = MF_LoadDiskBasedMetaFile(mh);
     else {
-        mh2 = HeapAlloc( SystemHeap, 0, mh->mtSize * 2 );
+        mh2 = HeapAlloc( GetProcessHeap(), 0, mh->mtSize * 2 );
         memcpy( mh2, mh, mh->mtSize * 2 );
     }
     MF_ReleaseMetaHeader( hSrcMetaFile );
@@ -402,7 +402,7 @@
     if(lpFilename) {         /* disk based metafile */
         if((hFile = CreateFileA(lpFilename, GENERIC_WRITE, 0, NULL,
 				CREATE_ALWAYS, 0, -1)) == HFILE_ERROR) {
-	    HeapFree( SystemHeap, 0, mh2 );
+	    HeapFree( GetProcessHeap(), 0, mh2 );
 	    return 0;
 	}
 	WriteFile(hFile, mh2, mh2->mtSize * 2, NULL, NULL);
@@ -487,7 +487,7 @@
     hFont = GetCurrentObject(hdc, OBJ_FONT);
 
     /* create the handle table */
-    ht = HeapAlloc( SystemHeap, HEAP_ZERO_MEMORY,
+    ht = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
 		    sizeof(HANDLETABLE16) * mh->mtNoObjects);
     if(!ht) return FALSE;
     
@@ -518,9 +518,9 @@
         DeleteObject(*(ht->objectHandle + i));
     
     /* free handle table */
-    HeapFree( SystemHeap, 0, ht );
+    HeapFree( GetProcessHeap(), 0, ht );
     if(loaded)
-        HeapFree( SystemHeap, 0, mh );
+        HeapFree( GetProcessHeap(), 0, mh );
     return TRUE;
 }
 
@@ -631,7 +631,7 @@
     /* free handle table */
     GlobalFree16(hHT);
     if(loaded)
-        HeapFree( SystemHeap, 0, mh );
+        HeapFree( GetProcessHeap(), 0, mh );
     MF_ReleaseMetaHeader16(hmf);
     return result;
 }
@@ -679,7 +679,7 @@
     hBrush = GetCurrentObject(hdc, OBJ_BRUSH);
     hFont = GetCurrentObject(hdc, OBJ_FONT);
 
-    ht = HeapAlloc( SystemHeap, HEAP_ZERO_MEMORY, 
+    ht = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, 
 			    sizeof(HANDLETABLE) * mh->mtNoObjects);
 
     /* loop through metafile records */
@@ -710,9 +710,9 @@
         DeleteObject(*(ht->objectHandle + i));
 
     /* free handle table */
-    HeapFree( SystemHeap, 0, ht);
+    HeapFree( GetProcessHeap(), 0, ht);
     if(loaded)
-        HeapFree( SystemHeap, 0, mh );
+        HeapFree( GetProcessHeap(), 0, mh );
     MF_ReleaseMetaHeader(hmf);
     return result;
 }
@@ -1269,7 +1269,7 @@
      const BYTE *lpData /* pointer to metafile data */  
     )
 {
-    METAHEADER *mh = HeapAlloc( SystemHeap, 0, size );
+    METAHEADER *mh = HeapAlloc( GetProcessHeap(), 0, size );
     if (!mh) return 0;
     memcpy(mh, lpData, size);
     return MF_Create_HMETAFILE(mh);
diff --git a/objects/region.c b/objects/region.c
index 3e1c382..4c973b2 100644
--- a/objects/region.c
+++ b/objects/region.c
@@ -93,6 +93,309 @@
 
 DEFAULT_DEBUG_CHANNEL(region);
 
+/*  1 if two RECTs overlap.
+ *  0 if two RECTs do not overlap.
+ */
+#define EXTENTCHECK(r1, r2) \
+	((r1)->right > (r2)->left && \
+	 (r1)->left < (r2)->right && \
+	 (r1)->bottom > (r2)->top && \
+	 (r1)->top < (r2)->bottom)
+
+/*
+ *   Check to see if there is enough memory in the present region.
+ */
+#define MEMCHECK(reg, rect, firstrect){\
+        if ((reg)->numRects >= ((reg)->size - 1)){\
+          (firstrect) = HeapReAlloc( GetProcessHeap(), 0, \
+           (firstrect), (2 * (sizeof(RECT)) * ((reg)->size)));\
+          if ((firstrect) == 0)\
+            return;\
+          (reg)->size *= 2;\
+          (rect) = &(firstrect)[(reg)->numRects];\
+         }\
+       }
+
+#define EMPTY_REGION(pReg) { \
+    (pReg)->numRects = 0; \
+    (pReg)->extents.left = (pReg)->extents.top = 0; \
+    (pReg)->extents.right = (pReg)->extents.bottom = 0; \
+    (pReg)->type = NULLREGION; \
+ }
+
+#define REGION_NOT_EMPTY(pReg) pReg->numRects
+
+#define INRECT(r, x, y) \
+      ( ( ((r).right >  x)) && \
+        ( ((r).left <= x)) && \
+        ( ((r).bottom >  y)) && \
+        ( ((r).top <= y)) )
+
+
+/*
+ * number of points to buffer before sending them off
+ * to scanlines() :  Must be an even number
+ */
+#define NUMPTSTOBUFFER 200
+
+/*
+ * used to allocate buffers for points and link
+ * the buffers together
+ */
+
+typedef struct _POINTBLOCK {
+    POINT pts[NUMPTSTOBUFFER];
+    struct _POINTBLOCK *next;
+} POINTBLOCK;
+
+
+
+/*
+ *     This file contains a few macros to help track
+ *     the edge of a filled object.  The object is assumed
+ *     to be filled in scanline order, and thus the
+ *     algorithm used is an extension of Bresenham's line
+ *     drawing algorithm which assumes that y is always the
+ *     major axis.
+ *     Since these pieces of code are the same for any filled shape,
+ *     it is more convenient to gather the library in one
+ *     place, but since these pieces of code are also in
+ *     the inner loops of output primitives, procedure call
+ *     overhead is out of the question.
+ *     See the author for a derivation if needed.
+ */
+
+
+/*
+ *  In scan converting polygons, we want to choose those pixels
+ *  which are inside the polygon.  Thus, we add .5 to the starting
+ *  x coordinate for both left and right edges.  Now we choose the
+ *  first pixel which is inside the pgon for the left edge and the
+ *  first pixel which is outside the pgon for the right edge.
+ *  Draw the left pixel, but not the right.
+ *
+ *  How to add .5 to the starting x coordinate:
+ *      If the edge is moving to the right, then subtract dy from the
+ *  error term from the general form of the algorithm.
+ *      If the edge is moving to the left, then add dy to the error term.
+ *
+ *  The reason for the difference between edges moving to the left
+ *  and edges moving to the right is simple:  If an edge is moving
+ *  to the right, then we want the algorithm to flip immediately.
+ *  If it is moving to the left, then we don't want it to flip until
+ *  we traverse an entire pixel.
+ */
+#define BRESINITPGON(dy, x1, x2, xStart, d, m, m1, incr1, incr2) { \
+    int dx;      /* local storage */ \
+\
+    /* \
+     *  if the edge is horizontal, then it is ignored \
+     *  and assumed not to be processed.  Otherwise, do this stuff. \
+     */ \
+    if ((dy) != 0) { \
+        xStart = (x1); \
+        dx = (x2) - xStart; \
+        if (dx < 0) { \
+            m = dx / (dy); \
+            m1 = m - 1; \
+            incr1 = -2 * dx + 2 * (dy) * m1; \
+            incr2 = -2 * dx + 2 * (dy) * m; \
+            d = 2 * m * (dy) - 2 * dx - 2 * (dy); \
+        } else { \
+            m = dx / (dy); \
+            m1 = m + 1; \
+            incr1 = 2 * dx - 2 * (dy) * m1; \
+            incr2 = 2 * dx - 2 * (dy) * m; \
+            d = -2 * m * (dy) + 2 * dx; \
+        } \
+    } \
+}
+
+#define BRESINCRPGON(d, minval, m, m1, incr1, incr2) { \
+    if (m1 > 0) { \
+        if (d > 0) { \
+            minval += m1; \
+            d += incr1; \
+        } \
+        else { \
+            minval += m; \
+            d += incr2; \
+        } \
+    } else {\
+        if (d >= 0) { \
+            minval += m1; \
+            d += incr1; \
+        } \
+        else { \
+            minval += m; \
+            d += incr2; \
+        } \
+    } \
+}
+
+/*
+ *     This structure contains all of the information needed
+ *     to run the bresenham algorithm.
+ *     The variables may be hardcoded into the declarations
+ *     instead of using this structure to make use of
+ *     register declarations.
+ */
+typedef struct {
+    INT minor_axis;	/* minor axis        */
+    INT d;		/* decision variable */
+    INT m, m1;       	/* slope and slope+1 */
+    INT incr1, incr2;	/* error increments */
+} BRESINFO;
+
+
+#define BRESINITPGONSTRUCT(dmaj, min1, min2, bres) \
+	BRESINITPGON(dmaj, min1, min2, bres.minor_axis, bres.d, \
+                     bres.m, bres.m1, bres.incr1, bres.incr2)
+
+#define BRESINCRPGONSTRUCT(bres) \
+        BRESINCRPGON(bres.d, bres.minor_axis, bres.m, bres.m1, bres.incr1, bres.incr2)
+
+
+
+/*
+ *     These are the data structures needed to scan
+ *     convert regions.  Two different scan conversion
+ *     methods are available -- the even-odd method, and
+ *     the winding number method.
+ *     The even-odd rule states that a point is inside
+ *     the polygon if a ray drawn from that point in any
+ *     direction will pass through an odd number of
+ *     path segments.
+ *     By the winding number rule, a point is decided
+ *     to be inside the polygon if a ray drawn from that
+ *     point in any direction passes through a different
+ *     number of clockwise and counter-clockwise path
+ *     segments.
+ *
+ *     These data structures are adapted somewhat from
+ *     the algorithm in (Foley/Van Dam) for scan converting
+ *     polygons.
+ *     The basic algorithm is to start at the top (smallest y)
+ *     of the polygon, stepping down to the bottom of
+ *     the polygon by incrementing the y coordinate.  We
+ *     keep a list of edges which the current scanline crosses,
+ *     sorted by x.  This list is called the Active Edge Table (AET)
+ *     As we change the y-coordinate, we update each entry in 
+ *     in the active edge table to reflect the edges new xcoord.
+ *     This list must be sorted at each scanline in case
+ *     two edges intersect.
+ *     We also keep a data structure known as the Edge Table (ET),
+ *     which keeps track of all the edges which the current
+ *     scanline has not yet reached.  The ET is basically a
+ *     list of ScanLineList structures containing a list of
+ *     edges which are entered at a given scanline.  There is one
+ *     ScanLineList per scanline at which an edge is entered.
+ *     When we enter a new edge, we move it from the ET to the AET.
+ *
+ *     From the AET, we can implement the even-odd rule as in
+ *     (Foley/Van Dam).
+ *     The winding number rule is a little trickier.  We also
+ *     keep the EdgeTableEntries in the AET linked by the
+ *     nextWETE (winding EdgeTableEntry) link.  This allows
+ *     the edges to be linked just as before for updating
+ *     purposes, but only uses the edges linked by the nextWETE
+ *     link as edges representing spans of the polygon to
+ *     drawn (as with the even-odd rule).
+ */
+
+/*
+ * for the winding number rule
+ */
+#define CLOCKWISE          1
+#define COUNTERCLOCKWISE  -1 
+
+typedef struct _EdgeTableEntry {
+     INT ymax;           /* ycoord at which we exit this edge. */
+     BRESINFO bres;        /* Bresenham info to run the edge     */
+     struct _EdgeTableEntry *next;       /* next in the list     */
+     struct _EdgeTableEntry *back;       /* for insertion sort   */
+     struct _EdgeTableEntry *nextWETE;   /* for winding num rule */
+     int ClockWise;        /* flag for winding number rule       */
+} EdgeTableEntry;
+
+
+typedef struct _ScanLineList{
+     INT scanline;            /* the scanline represented */
+     EdgeTableEntry *edgelist;  /* header node              */
+     struct _ScanLineList *next;  /* next in the list       */
+} ScanLineList;
+
+
+typedef struct {
+     INT ymax;               /* ymax for the polygon     */
+     INT ymin;               /* ymin for the polygon     */
+     ScanLineList scanlines;   /* header node              */
+} EdgeTable;
+
+
+/*
+ * Here is a struct to help with storage allocation
+ * so we can allocate a big chunk at a time, and then take
+ * pieces from this heap when we need to.
+ */
+#define SLLSPERBLOCK 25
+
+typedef struct _ScanLineListBlock {
+     ScanLineList SLLs[SLLSPERBLOCK];
+     struct _ScanLineListBlock *next;
+} ScanLineListBlock;
+
+
+/*
+ *
+ *     a few macros for the inner loops of the fill code where
+ *     performance considerations don't allow a procedure call.
+ *
+ *     Evaluate the given edge at the given scanline.
+ *     If the edge has expired, then we leave it and fix up
+ *     the active edge table; otherwise, we increment the
+ *     x value to be ready for the next scanline.
+ *     The winding number rule is in effect, so we must notify
+ *     the caller when the edge has been removed so he
+ *     can reorder the Winding Active Edge Table.
+ */
+#define EVALUATEEDGEWINDING(pAET, pPrevAET, y, fixWAET) { \
+   if (pAET->ymax == y) {          /* leaving this edge */ \
+      pPrevAET->next = pAET->next; \
+      pAET = pPrevAET->next; \
+      fixWAET = 1; \
+      if (pAET) \
+         pAET->back = pPrevAET; \
+   } \
+   else { \
+      BRESINCRPGONSTRUCT(pAET->bres); \
+      pPrevAET = pAET; \
+      pAET = pAET->next; \
+   } \
+}
+
+
+/*
+ *     Evaluate the given edge at the given scanline.
+ *     If the edge has expired, then we leave it and fix up
+ *     the active edge table; otherwise, we increment the
+ *     x value to be ready for the next scanline.
+ *     The even-odd rule is in effect.
+ */
+#define EVALUATEEDGEEVENODD(pAET, pPrevAET, y) { \
+   if (pAET->ymax == y) {          /* leaving this edge */ \
+      pPrevAET->next = pAET->next; \
+      pAET = pPrevAET->next; \
+      if (pAET) \
+         pAET->back = pPrevAET; \
+   } \
+   else { \
+      BRESINCRPGONSTRUCT(pAET->bres); \
+      pPrevAET = pAET; \
+      pAET = pAET->next; \
+   } \
+}
+
 typedef void (*voidProcp)();
 
 /* Note the parameter order is different from the X11 equivalents */
@@ -132,15 +435,15 @@
 {
     WINEREGION *pReg;
 
-    if ((pReg = HeapAlloc(SystemHeap, 0, sizeof( WINEREGION ))))
+    if ((pReg = HeapAlloc(GetProcessHeap(), 0, sizeof( WINEREGION ))))
     {
-        if ((pReg->rects = HeapAlloc(SystemHeap, 0, n * sizeof( RECT ))))
+        if ((pReg->rects = HeapAlloc(GetProcessHeap(), 0, n * sizeof( RECT ))))
         {
             pReg->size = n;
             EMPTY_REGION(pReg);
             return pReg;
         }
-        HeapFree(SystemHeap, 0, pReg);
+        HeapFree(GetProcessHeap(), 0, pReg);
     }
     return NULL;
 }
@@ -172,8 +475,8 @@
  */
 static void REGION_DestroyWineRegion( WINEREGION* pReg )
 {
-    HeapFree( SystemHeap, 0, pReg->rects );
-    HeapFree( SystemHeap, 0, pReg );
+    HeapFree( GetProcessHeap(), 0, pReg->rects );
+    HeapFree( GetProcessHeap(), 0, pReg );
     return;
 }
 
@@ -998,7 +1301,7 @@
     {  
 	if (dst->size < src->numRects)
 	{
-	    if (! (dst->rects = HeapReAlloc( SystemHeap, 0, dst->rects,
+	    if (! (dst->rects = HeapReAlloc( GetProcessHeap(), 0, dst->rects,
 				src->numRects * sizeof(RECT) )))
 		return;
 	    dst->size = src->numRects;
@@ -1233,7 +1536,7 @@
      */
     newReg->size = MAX(reg1->numRects,reg2->numRects) * 2;
 
-    if (! (newReg->rects = HeapAlloc( SystemHeap, 0, 
+    if (! (newReg->rects = HeapAlloc( GetProcessHeap(), 0, 
 			          sizeof(RECT) * newReg->size )))
     {
 	newReg->size = 0;
@@ -1426,7 +1729,7 @@
 	{
 	    RECT *prev_rects = newReg->rects;
 	    newReg->size = newReg->numRects;
-	    newReg->rects = HeapReAlloc( SystemHeap, 0, newReg->rects,
+	    newReg->rects = HeapReAlloc( GetProcessHeap(), 0, newReg->rects,
 				   sizeof(RECT) * newReg->size );
 	    if (! newReg->rects)
 		newReg->rects = prev_rects;
@@ -1438,11 +1741,11 @@
 	     * the region is empty
 	     */
 	    newReg->size = 1;
-	    HeapFree( SystemHeap, 0, newReg->rects );
-	    newReg->rects = HeapAlloc( SystemHeap, 0, sizeof(RECT) );
+	    HeapFree( GetProcessHeap(), 0, newReg->rects );
+	    newReg->rects = HeapAlloc( GetProcessHeap(), 0, sizeof(RECT) );
 	}
     }
-    HeapFree( SystemHeap, 0, oldRects );
+    HeapFree( GetProcessHeap(), 0, oldRects );
     return;
 }
 
@@ -1989,7 +2292,7 @@
     {
         if (*iSLLBlock > SLLSPERBLOCK-1) 
         {
-            tmpSLLBlock = HeapAlloc( SystemHeap, 0, sizeof(ScanLineListBlock));
+            tmpSLLBlock = HeapAlloc( GetProcessHeap(), 0, sizeof(ScanLineListBlock));
 	    if(!tmpSLLBlock)
 	    {
 	        WARN("Can't alloc SLLB\n");
@@ -2273,7 +2576,7 @@
     while (pSLLBlock) 
     {
         tmpSLLBlock = pSLLBlock->next;
-        HeapFree( SystemHeap, 0, pSLLBlock );
+        HeapFree( GetProcessHeap(), 0, pSLLBlock );
         pSLLBlock = tmpSLLBlock;
     }
 }
@@ -2298,7 +2601,7 @@
  
     numRects = ((numFullPtBlocks * NUMPTSTOBUFFER) + iCurPtBlock) >> 1;
  
-    if (!(reg->rects = HeapReAlloc( SystemHeap, 0, reg->rects, 
+    if (!(reg->rects = HeapReAlloc( GetProcessHeap(), 0, reg->rects, 
 			   sizeof(RECT) * numRects )))
         return(0);
  
@@ -2401,7 +2704,7 @@
     
     for(poly = total = 0; poly < nbpolygons; poly++)
         total += Count[poly];
-    if (! (pETEs = HeapAlloc( SystemHeap, 0, sizeof(EdgeTableEntry) * total )))
+    if (! (pETEs = HeapAlloc( GetProcessHeap(), 0, sizeof(EdgeTableEntry) * total )))
     {
         REGION_DeleteObject( hrgn, obj );
 	return 0;
@@ -2438,7 +2741,7 @@
                  *  send out the buffer
                  */
                 if (iPts == NUMPTSTOBUFFER) {
-                    tmpPtBlock = HeapAlloc( SystemHeap, 0, sizeof(POINTBLOCK));
+                    tmpPtBlock = HeapAlloc( GetProcessHeap(), 0, sizeof(POINTBLOCK));
 		    if(!tmpPtBlock) {
 		        WARN("Can't alloc tPB\n");
 			return 0;
@@ -2488,7 +2791,7 @@
                      *  send out the buffer
                      */
                     if (iPts == NUMPTSTOBUFFER) {
-                        tmpPtBlock = HeapAlloc( SystemHeap, 0,
+                        tmpPtBlock = HeapAlloc( GetProcessHeap(), 0,
 					       sizeof(POINTBLOCK) );
 			if(!tmpPtBlock) {
 			    WARN("Can't alloc tPB\n");
@@ -2518,10 +2821,10 @@
     REGION_PtsToRegion(numFullPtBlocks, iPts, &FirstPtBlock, region);
     for (curPtBlock = FirstPtBlock.next; --numFullPtBlocks >= 0;) {
 	tmpPtBlock = curPtBlock->next;
-	HeapFree( SystemHeap, 0, curPtBlock );
+	HeapFree( GetProcessHeap(), 0, curPtBlock );
 	curPtBlock = tmpPtBlock;
     }
-    HeapFree( SystemHeap, 0, pETEs );
+    HeapFree( GetProcessHeap(), 0, pETEs );
     GDI_HEAP_UNLOCK( hrgn );
     return hrgn;
 }
@@ -2549,16 +2852,16 @@
 
     for (i = 0; i < nbpolygons; i++)
 	npts += count[i];
-    points32 = HeapAlloc( SystemHeap, 0, npts * sizeof(POINT) );
+    points32 = HeapAlloc( GetProcessHeap(), 0, npts * sizeof(POINT) );
     for (i = 0; i < npts; i++)
     	CONV_POINT16TO32( &(points[i]), &(points32[i]) );
 
-    count32 = HeapAlloc( SystemHeap, 0, nbpolygons * sizeof(INT) );
+    count32 = HeapAlloc( GetProcessHeap(), 0, nbpolygons * sizeof(INT) );
     for (i = 0; i < nbpolygons; i++)
     	count32[i] = count[i];
     hrgn = CreatePolyPolygonRgn( points32, count32, nbpolygons, mode );
-    HeapFree( SystemHeap, 0, count32 );
-    HeapFree( SystemHeap, 0, points32 );
+    HeapFree( GetProcessHeap(), 0, count32 );
+    HeapFree( GetProcessHeap(), 0, points32 );
     return hrgn;
 }
 
@@ -2633,7 +2936,7 @@
 		return TRUE;
 	}
 	else
-	    xrect = HeapReAlloc( SystemHeap, 0, rgnDst->rects,
+	    xrect = HeapReAlloc( GetProcessHeap(), 0, rgnDst->rects,
 				rgnSrc->size * sizeof( RECT ));
 	if( xrect )
 	{
@@ -2664,7 +2967,7 @@
 empty:
 	if( !rgnDst->rects )
 	{
-	    rgnDst->rects = HeapAlloc(SystemHeap, 0, RGN_DEFAULT_RECTS * sizeof( RECT ));
+	    rgnDst->rects = HeapAlloc(GetProcessHeap(), 0, RGN_DEFAULT_RECTS * sizeof( RECT ));
 	    if( rgnDst->rects )
 		rgnDst->size = RGN_DEFAULT_RECTS;
 	    else
@@ -2694,7 +2997,7 @@
 
 	if((rgnDst != rgnSrc) && (rgnDst->size < (i = (clipb - clipa))))
 	{
-	    rgnDst->rects = HeapReAlloc( SystemHeap, 0, 
+	    rgnDst->rects = HeapReAlloc( GetProcessHeap(), 0, 
 				rgnDst->rects, i * sizeof(RECT));
 	    if( !rgnDst->rects ) return FALSE;
 	    rgnDst->size = i;
@@ -2816,7 +3119,7 @@
 	}
 	else
 	{
-	    if ((rgnDst = HeapAlloc(SystemHeap, 0, sizeof( WINEREGION ))))
+	    if ((rgnDst = HeapAlloc(GetProcessHeap(), 0, sizeof( WINEREGION ))))
 	    {
 	        rgnDst->size = rgnDst->numRects = 0;
 	        rgnDst->rects = NULL;	/* back end will allocate exact number */
@@ -2851,8 +3154,8 @@
 		{
 fail:
 		    if( rgnDst->rects )
-			HeapFree( SystemHeap, 0, rgnDst->rects );
-		    HeapFree( SystemHeap, 0, rgnDst );
+			HeapFree( GetProcessHeap(), 0, rgnDst->rects );
+		    HeapFree( GetProcessHeap(), 0, rgnDst );
 		    goto done;
 		}
 
diff --git a/relay32/snoop.c b/relay32/snoop.c
index 00c8a54..e9b7592 100644
--- a/relay32/snoop.c
+++ b/relay32/snoop.c
@@ -131,17 +131,17 @@
 			return; /* already registered */
 		dll = &((*dll)->next);
 	}
-	*dll = (SNOOP_DLL*)HeapAlloc(SystemHeap,HEAP_ZERO_MEMORY,sizeof(SNOOP_DLL));
+	*dll = (SNOOP_DLL*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(SNOOP_DLL));
 	(*dll)->next	= NULL;
 	(*dll)->hmod	= hmod;
 	(*dll)->nrofordinals = nrofordinals;
-	(*dll)->name	= HEAP_strdupA(SystemHeap,0,name);
+	(*dll)->name	= HEAP_strdupA(GetProcessHeap(),0,name);
 	if ((s=strrchr((*dll)->name,'.')))
 		*s='\0';
 	(*dll)->funs = VirtualAlloc(NULL,nrofordinals*sizeof(SNOOP_FUN),MEM_COMMIT|MEM_RESERVE,PAGE_EXECUTE_READWRITE);
 	memset((*dll)->funs,0,nrofordinals*sizeof(SNOOP_FUN));
 	if (!(*dll)->funs) {
-		HeapFree(SystemHeap,0,*dll);
+		HeapFree(GetProcessHeap(),0,*dll);
 		FIXME("out of memory\n");
 		return;
 	}
@@ -187,7 +187,7 @@
 		return origfun;
 	assert(ordinal<dll->nrofordinals);
 	fun = dll->funs+ordinal;
-	if (!fun->name) fun->name = HEAP_strdupA(SystemHeap,0,name);
+	if (!fun->name) fun->name = HEAP_strdupA(GetProcessHeap(),0,name);
 	fun->lcall	= 0xe8;
 	/* NOTE: origreturn struct member MUST come directly after snoopentry */
 	fun->snoopentry	= (char*)SNOOP_Entry-((char*)(&fun->nrofargs));
@@ -323,7 +323,7 @@
 			DPRINTF(" ...");
 	} else if (fun->nrofargs<0) {
 		DPRINTF("<unknown, check return>");
-		ret->args = HeapAlloc(SystemHeap,0,16*sizeof(DWORD));
+		ret->args = HeapAlloc(GetProcessHeap(),0,16*sizeof(DWORD));
 		memcpy(ret->args,(LPBYTE)(ESP_reg(context)+4),sizeof(DWORD)*16);
 	}
 	DPRINTF(") ret=%08lx fs=%04lx\n",(DWORD)ret->origreturn,FS_reg(context));
@@ -355,7 +355,7 @@
 		DPRINTF(") retval = %08lx ret=%08lx fs=%04lx\n",
 			EAX_reg(context),(DWORD)ret->origreturn,FS_reg(context)
 		);
-		HeapFree(SystemHeap,0,ret->args);
+		HeapFree(GetProcessHeap(),0,ret->args);
 		ret->args = NULL;
 	} else
 		DPRINTF("Ret  %s.%ld: %s() retval = %08lx ret=%08lx fs=%04lx\n",
diff --git a/windows/driver.c b/windows/driver.c
index 0899be7..402b5d7 100644
--- a/windows/driver.c
+++ b/windows/driver.c
@@ -180,7 +180,7 @@
 	    *lParam1 = (DWORD)PTR_SEG_TO_LIN(*lParam1);
 	if (*lParam2 && wMsg == DRV_OPEN) {
             LPMCI_OPEN_DRIVER_PARMS16	modp16 = PTR_SEG_TO_LIN(*lParam2);
-            char*			ptr = HeapAlloc(SystemHeap, 0, sizeof(LPMCI_OPEN_DRIVER_PARMS16) + sizeof(MCI_OPEN_DRIVER_PARMSA));
+            char*			ptr = HeapAlloc(GetProcessHeap(), 0, sizeof(LPMCI_OPEN_DRIVER_PARMS16) + sizeof(MCI_OPEN_DRIVER_PARMSA));
             LPMCI_OPEN_DRIVER_PARMSA	modp32;
 	    
 	    if (ptr) {
@@ -200,13 +200,13 @@
     case DRV_INSTALL:
 	/* lParam1 is a handle to a window (or not used), lParam2 is a pointer to DRVCONFIGINFO */
 	if (*lParam2) {
-            LPDRVCONFIGINFO	dci32 = HeapAlloc(SystemHeap, 0, sizeof(DRVCONFIGINFO));
+            LPDRVCONFIGINFO	dci32 = HeapAlloc(GetProcessHeap(), 0, sizeof(DRVCONFIGINFO));
             LPDRVCONFIGINFO16	dci16 = PTR_SEG_TO_LIN(*lParam2);
 	    
 	    if (dci32) {
 		dci32->dwDCISize = sizeof(DRVCONFIGINFO);
-		dci32->lpszDCISectionName = HEAP_strdupAtoW(SystemHeap, 0, PTR_SEG_TO_LIN(dci16->lpszDCISectionName));
-		dci32->lpszDCIAliasName   = HEAP_strdupAtoW(SystemHeap, 0, PTR_SEG_TO_LIN(dci16->lpszDCIAliasName));
+		dci32->lpszDCISectionName = HEAP_strdupAtoW(GetProcessHeap(), 0, PTR_SEG_TO_LIN(dci16->lpszDCISectionName));
+		dci32->lpszDCIAliasName   = HEAP_strdupAtoW(GetProcessHeap(), 0, PTR_SEG_TO_LIN(dci16->lpszDCIAliasName));
 		if (dci32->lpszDCISectionName == NULL || dci32->lpszDCIAliasName == NULL)
 		    return -2;
 	    } else {
@@ -265,7 +265,7 @@
 
 	    modp16->wCustomCommandTable = modp32->wCustomCommandTable;
 	    modp16->wType = modp32->wType;
-	    if (!HeapFree(SystemHeap, 0, modp32))
+	    if (!HeapFree(GetProcessHeap(), 0, modp32))
 		FIXME("bad free line=%d\n", __LINE__);
 	}
 	ret = 0;
@@ -275,11 +275,11 @@
 	/* lParam1 is a handle to a window (or not used), lParam2 is a pointer to DRVCONFIGINFO, lParam2 */
 	if (lParam2) {
 	    LPDRVCONFIGINFO	dci32 = (LPDRVCONFIGINFO)lParam2;
-	    if (!HeapFree(SystemHeap, 0, (LPVOID)dci32->lpszDCISectionName))
+	    if (!HeapFree(GetProcessHeap(), 0, (LPVOID)dci32->lpszDCISectionName))
 		FIXME("bad free line=%d\n", __LINE__);
-	    if (!HeapFree(SystemHeap, 0, (LPVOID)dci32->lpszDCIAliasName))
+	    if (!HeapFree(GetProcessHeap(), 0, (LPVOID)dci32->lpszDCIAliasName))
 		FIXME("bad free line=%d\n", __LINE__);
-	    if (!HeapFree(SystemHeap, 0, dci32))
+	    if (!HeapFree(GetProcessHeap(), 0, dci32))
 		FIXME("bad free line=%d\n", __LINE__);
 	}
 	ret = 0;
@@ -369,18 +369,18 @@
 		
 		dci16->dwDCISize = sizeof(DRVCONFIGINFO16);
 		
-		if ((str1 = HEAP_strdupWtoA(SystemHeap, 0, dci32->lpszDCISectionName)) != NULL &&
+		if ((str1 = HEAP_strdupWtoA(GetProcessHeap(), 0, dci32->lpszDCISectionName)) != NULL &&
 		    (str2 = SEGPTR_STRDUP(str1)) != NULL) {
 		    dci16->lpszDCISectionName = (LPSTR)SEGPTR_GET(str2);
-		    if (!HeapFree(SystemHeap, 0, str1))
+		    if (!HeapFree(GetProcessHeap(), 0, str1))
 			FIXME("bad free line=%d\n", __LINE__);
 		} else {
 		    return -2;
 		}
-		if ((str1 = HEAP_strdupWtoA(SystemHeap, 0, dci32->lpszDCIAliasName)) != NULL &&
+		if ((str1 = HEAP_strdupWtoA(GetProcessHeap(), 0, dci32->lpszDCIAliasName)) != NULL &&
 		    (str2 = SEGPTR_STRDUP(str1)) != NULL) {
 		    dci16->lpszDCIAliasName = (LPSTR)SEGPTR_GET(str2);
-		    if (!HeapFree(SystemHeap, 0, str1))
+		    if (!HeapFree(GetProcessHeap(), 0, str1))
 			FIXME("bad free line=%d\n", __LINE__);
 		} else {
 		    return -2;
@@ -655,7 +655,7 @@
 	SendDriverMessage((HDRVR)lpDrv, DRV_CLOSE, lParam1, lParam2);
     
 	if (DRIVER_RemoveFromList(lpDrv)) {
-	    HeapFree(SystemHeap, 0, lpDrv);
+	    HeapFree(GetProcessHeap(), 0, lpDrv);
 	    return TRUE;
 	}
     }
@@ -674,7 +674,7 @@
 {
     LPWINE_DRIVER	lpDrv;
     
-    lpDrv = HeapAlloc(SystemHeap, 0, sizeof(WINE_DRIVER));
+    lpDrv = HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_DRIVER));
     if (lpDrv != NULL) {
 	lpDrv->dwFlags         = WINE_GDF_EXIST|WINE_GDF_16BIT;
 	lpDrv->dwDriverID      = 0;
@@ -684,7 +684,7 @@
 	lpDrv->d.d16.lpDrvProc = lpProc;
 	
 	if (!DRIVER_AddToList(lpDrv, lParam, bCallFrom32)) {
-	    HeapFree(SystemHeap, 0, lpDrv);
+	    HeapFree(GetProcessHeap(), 0, lpDrv);
 	    lpDrv = NULL;
 	}
     }
@@ -702,7 +702,7 @@
 {
     LPWINE_DRIVER	lpDrv;
     
-    lpDrv = HeapAlloc(SystemHeap, 0, sizeof(WINE_DRIVER));
+    lpDrv = HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_DRIVER));
     if (lpDrv != NULL) {
 	lpDrv->dwFlags          = WINE_GDF_EXIST;
 	lpDrv->dwDriverID       = 0;
@@ -712,7 +712,7 @@
 	lpDrv->d.d32.lpDrvProc  = lpProc;
 	
 	if (!DRIVER_AddToList(lpDrv, lParam, bCallFrom32)) {
-	    HeapFree(SystemHeap, 0, lpDrv);
+	    HeapFree(GetProcessHeap(), 0, lpDrv);
 	    lpDrv = NULL;
 	}
     }
diff --git a/windows/hook.c b/windows/hook.c
index ad8c728..3349792 100644
--- a/windows/hook.c
+++ b/windows/hook.c
@@ -72,7 +72,7 @@
 	case WH_JOURNALRECORD:
         {
             LPMSG16 lpmsg16 = PTR_SEG_TO_LIN(*plParam);
-            LPMSG lpmsg32 = HeapAlloc( SystemHeap, 0, sizeof(*lpmsg32) );
+            LPMSG lpmsg32 = HeapAlloc( GetProcessHeap(), 0, sizeof(*lpmsg32) );
 	
             STRUCT32_MSG16to32( lpmsg16, lpmsg32 );
             *plParam = (LPARAM)lpmsg32;
@@ -82,7 +82,7 @@
 	case WH_JOURNALPLAYBACK:
         {
             LPEVENTMSG16 lpem16 = PTR_SEG_TO_LIN(*plParam);
-            LPEVENTMSG lpem32 = HeapAlloc( SystemHeap, 0, sizeof(*lpem32) );
+            LPEVENTMSG lpem32 = HeapAlloc( GetProcessHeap(), 0, sizeof(*lpem32) );
 
             lpem32->message = lpem16->message;
             lpem32->paramL = lpem16->paramL;
@@ -97,7 +97,7 @@
 	case WH_CALLWNDPROC:
 	{
 	    LPCWPSTRUCT16   lpcwp16 = PTR_SEG_TO_LIN(*plParam);
-	    LPCWPSTRUCT   lpcwp32 = HeapAlloc( SystemHeap, 0, sizeof(*lpcwp32) );
+	    LPCWPSTRUCT   lpcwp32 = HeapAlloc( GetProcessHeap(), 0, sizeof(*lpcwp32) );
 	    
 	    lpcwp32->hwnd = lpcwp16->hwnd;
 	    lpcwp32->lParam = lpcwp16->lParam;
@@ -119,9 +119,9 @@
 	    {
 		LPCBT_CREATEWND16  lpcbtcw16 = PTR_SEG_TO_LIN(*plParam);
 		LPCREATESTRUCT16   lpcs16 = PTR_SEG_TO_LIN(lpcbtcw16->lpcs);
-		LPCBT_CREATEWNDA lpcbtcw32 = HeapAlloc( SystemHeap, 0,
+		LPCBT_CREATEWNDA lpcbtcw32 = HeapAlloc( GetProcessHeap(), 0,
 							  sizeof(*lpcbtcw32) );
-		lpcbtcw32->lpcs = HeapAlloc( SystemHeap, 0,
+		lpcbtcw32->lpcs = HeapAlloc( GetProcessHeap(), 0,
 					     sizeof(*lpcbtcw32->lpcs) );
 
 		STRUCT32_CREATESTRUCT16to32A( lpcs16,
@@ -130,7 +130,7 @@
 		if (HIWORD(lpcs16->lpszName))
 		    lpcbtcw32->lpcs->lpszName = 
 			(bA) ? PTR_SEG_TO_LIN(lpcs16->lpszName)
-			     : HEAP_strdupAtoW( SystemHeap, 0,
+			     : HEAP_strdupAtoW( GetProcessHeap(), 0,
                                                 PTR_SEG_TO_LIN(lpcs16->lpszName) );
 		else
 		    lpcbtcw32->lpcs->lpszName = (LPCSTR)lpcs16->lpszName;
@@ -138,7 +138,7 @@
 		if (HIWORD(lpcs16->lpszClass))
 		    lpcbtcw32->lpcs->lpszClass =
 			(bA) ? PTR_SEG_TO_LIN(lpcs16->lpszClass)
-			     : HEAP_strdupAtoW( SystemHeap, 0,
+			     : HEAP_strdupAtoW( GetProcessHeap(), 0,
                                                 PTR_SEG_TO_LIN(lpcs16->lpszClass) );
 		else
 		    lpcbtcw32->lpcs->lpszClass = (LPCSTR)lpcs16->lpszClass;
@@ -151,7 +151,7 @@
 	    case HCBT_ACTIVATE:
             {
                 LPCBTACTIVATESTRUCT16 lpcas16 = PTR_SEG_TO_LIN(*plParam);
-                LPCBTACTIVATESTRUCT lpcas32 = HeapAlloc( SystemHeap, 0,
+                LPCBTACTIVATESTRUCT lpcas32 = HeapAlloc( GetProcessHeap(), 0,
                                                            sizeof(*lpcas32) );
                 lpcas32->fMouse = lpcas16->fMouse;
                 lpcas32->hWndActive = lpcas16->hWndActive;
@@ -161,7 +161,7 @@
             case HCBT_CLICKSKIPPED:
             {
                 LPMOUSEHOOKSTRUCT16 lpms16 = PTR_SEG_TO_LIN(*plParam);
-                LPMOUSEHOOKSTRUCT lpms32 = HeapAlloc( SystemHeap, 0,
+                LPMOUSEHOOKSTRUCT lpms32 = HeapAlloc( GetProcessHeap(), 0,
                                                         sizeof(*lpms32) );
 
                 CONV_POINT16TO32( &lpms16->pt, &lpms32->pt );
@@ -178,7 +178,7 @@
             case HCBT_MOVESIZE:
             {
                 LPRECT16 lprect16 = PTR_SEG_TO_LIN(*plParam);
-                LPRECT lprect32 = HeapAlloc( SystemHeap, 0,
+                LPRECT lprect32 = HeapAlloc( GetProcessHeap(), 0,
                                                sizeof(*lprect32) );
 
                 CONV_RECT16TO32( lprect16, lprect32 );
@@ -191,7 +191,7 @@
 	case WH_MOUSE:
         {
             LPMOUSEHOOKSTRUCT16 lpms16 = PTR_SEG_TO_LIN(*plParam);
-            LPMOUSEHOOKSTRUCT lpms32 = HeapAlloc( SystemHeap, 0,
+            LPMOUSEHOOKSTRUCT lpms32 = HeapAlloc( GetProcessHeap(), 0,
                                                     sizeof(*lpms32) );
 
             CONV_POINT16TO32( &lpms16->pt, &lpms32->pt );
@@ -208,7 +208,7 @@
 	case WH_DEBUG:
         {
             LPDEBUGHOOKINFO16 lpdh16 = PTR_SEG_TO_LIN(*plParam);
-            LPDEBUGHOOKINFO lpdh32 = HeapAlloc( SystemHeap, 0,
+            LPDEBUGHOOKINFO lpdh32 = HeapAlloc( GetProcessHeap(), 0,
                                                   sizeof(*lpdh32) );
 
             lpdh32->idThread = 0;               /* FIXME */
@@ -270,7 +270,7 @@
 	case WH_JOURNALRECORD:
 	case WH_JOURNALPLAYBACK:
       
-	    HeapFree( SystemHeap, 0, (LPVOID)lParam );
+	    HeapFree( GetProcessHeap(), 0, (LPVOID)lParam );
 	    break;
 
 	case WH_CALLWNDPROC:
@@ -280,7 +280,7 @@
                                              lpcwp32->lParam, 0 );
             else WINPROC_UnmapMsg16To32W( lpcwp32->hwnd,lpcwp32->message, lpcwp32->wParam,
                                           lpcwp32->lParam, 0 );
-	    HeapFree( SystemHeap, 0, lpcwp32 );
+	    HeapFree( GetProcessHeap(), 0, lpcwp32 );
             break;
 	}
 
@@ -288,14 +288,14 @@
         {
 	    LPMSG16 lpmsg16 = PTR_SEG_TO_LIN(lParamOrig);
 	    STRUCT32_MSG32to16( (LPMSG)lParam, lpmsg16 );
-	    HeapFree( SystemHeap, 0, (LPVOID)lParam );
+	    HeapFree( GetProcessHeap(), 0, (LPVOID)lParam );
 	    break;
         }
 
         case WH_MOUSE:
         case WH_DEBUG:
 
-	    HeapFree( SystemHeap, 0, (LPVOID)lParam );
+	    HeapFree( GetProcessHeap(), 0, (LPVOID)lParam );
 	    break;
 
         case WH_CBT:
@@ -309,21 +309,21 @@
 		if( !bA )
 		{
 		   if (HIWORD(lpcbtcw32->lpcs->lpszName))
-                       HeapFree( SystemHeap, 0, (LPWSTR)lpcbtcw32->lpcs->lpszName );
+                       HeapFree( GetProcessHeap(), 0, (LPWSTR)lpcbtcw32->lpcs->lpszName );
 		   if (HIWORD(lpcbtcw32->lpcs->lpszClass))
-                       HeapFree( SystemHeap, 0, (LPWSTR)lpcbtcw32->lpcs->lpszClass );
+                       HeapFree( GetProcessHeap(), 0, (LPWSTR)lpcbtcw32->lpcs->lpszClass );
 		}
 
 		lpcbtcw16->hwndInsertAfter = lpcbtcw32->hwndInsertAfter;
 
-		HeapFree( SystemHeap, 0, lpcbtcw32->lpcs );
+		HeapFree( GetProcessHeap(), 0, lpcbtcw32->lpcs );
 	      } /* fall through */
 
 	      case HCBT_ACTIVATE:
 	      case HCBT_CLICKSKIPPED:
 	      case HCBT_MOVESIZE:
 
-	        HeapFree( SystemHeap, 0, (LPVOID)lParam);
+	        HeapFree( GetProcessHeap(), 0, (LPVOID)lParam);
 	        break;
 	    }
   	    break;
@@ -687,16 +687,16 @@
     if (id == WH_CBT && code == HCBT_CREATEWND)
     {
 	LPCBT_CREATEWNDA lpcbtcwA = (LPCBT_CREATEWNDA)*plParam;
-	LPCBT_CREATEWNDW lpcbtcwW = HeapAlloc( SystemHeap, 0,
+	LPCBT_CREATEWNDW lpcbtcwW = HeapAlloc( GetProcessHeap(), 0,
 						 sizeof(*lpcbtcwW) );
-	lpcbtcwW->lpcs = HeapAlloc( SystemHeap, 0, sizeof(*lpcbtcwW->lpcs) );
+	lpcbtcwW->lpcs = HeapAlloc( GetProcessHeap(), 0, sizeof(*lpcbtcwW->lpcs) );
 
 	lpcbtcwW->hwndInsertAfter = lpcbtcwA->hwndInsertAfter;
 	*lpcbtcwW->lpcs = *(LPCREATESTRUCTW)lpcbtcwA->lpcs;
 
 	if (HIWORD(lpcbtcwA->lpcs->lpszName))
 	{
-	    lpcbtcwW->lpcs->lpszName = HEAP_strdupAtoW( SystemHeap, 0,
+	    lpcbtcwW->lpcs->lpszName = HEAP_strdupAtoW( GetProcessHeap(), 0,
                                                     lpcbtcwA->lpcs->lpszName );
 	}
 	else
@@ -704,7 +704,7 @@
 
 	if (HIWORD(lpcbtcwA->lpcs->lpszClass))
 	{
-	    lpcbtcwW->lpcs->lpszClass = HEAP_strdupAtoW( SystemHeap, 0,
+	    lpcbtcwW->lpcs->lpszClass = HEAP_strdupAtoW( GetProcessHeap(), 0,
                                                    lpcbtcwA->lpcs->lpszClass );
 	}
 	else
@@ -726,11 +726,11 @@
     {
 	LPCBT_CREATEWNDW lpcbtcwW = (LPCBT_CREATEWNDW)lParam;
 	if (HIWORD(lpcbtcwW->lpcs->lpszName))
-            HeapFree( SystemHeap, 0, (LPWSTR)lpcbtcwW->lpcs->lpszName );
+            HeapFree( GetProcessHeap(), 0, (LPWSTR)lpcbtcwW->lpcs->lpszName );
 	if (HIWORD(lpcbtcwW->lpcs->lpszClass))
-            HeapFree( SystemHeap, 0, (LPWSTR)lpcbtcwW->lpcs->lpszClass );
-	HeapFree( SystemHeap, 0, lpcbtcwW->lpcs );
-	HeapFree( SystemHeap, 0, lpcbtcwW );
+            HeapFree( GetProcessHeap(), 0, (LPWSTR)lpcbtcwW->lpcs->lpszClass );
+	HeapFree( GetProcessHeap(), 0, lpcbtcwW->lpcs );
+	HeapFree( GetProcessHeap(), 0, lpcbtcwW );
     }
     return;
 }
@@ -745,21 +745,21 @@
     if (id == WH_CBT && code == HCBT_CREATEWND)
     {
 	LPCBT_CREATEWNDW lpcbtcwW = (LPCBT_CREATEWNDW)*plParam;
-	LPCBT_CREATEWNDA lpcbtcwA = HeapAlloc( SystemHeap, 0,
+	LPCBT_CREATEWNDA lpcbtcwA = HeapAlloc( GetProcessHeap(), 0,
 						 sizeof(*lpcbtcwA) );
-	lpcbtcwA->lpcs = HeapAlloc( SystemHeap, 0, sizeof(*lpcbtcwA->lpcs) );
+	lpcbtcwA->lpcs = HeapAlloc( GetProcessHeap(), 0, sizeof(*lpcbtcwA->lpcs) );
 
 	lpcbtcwA->hwndInsertAfter = lpcbtcwW->hwndInsertAfter;
 	*lpcbtcwA->lpcs = *(LPCREATESTRUCTA)lpcbtcwW->lpcs;
 
 	if (HIWORD(lpcbtcwW->lpcs->lpszName))
-	  lpcbtcwA->lpcs->lpszName = HEAP_strdupWtoA( SystemHeap, 0,
+	  lpcbtcwA->lpcs->lpszName = HEAP_strdupWtoA( GetProcessHeap(), 0,
                                                     lpcbtcwW->lpcs->lpszName );
 	else
 	  lpcbtcwA->lpcs->lpszName = (LPSTR)lpcbtcwW->lpcs->lpszName;
 
 	if (HIWORD(lpcbtcwW->lpcs->lpszClass))
-	  lpcbtcwA->lpcs->lpszClass = HEAP_strdupWtoA( SystemHeap, 0,
+	  lpcbtcwA->lpcs->lpszClass = HEAP_strdupWtoA( GetProcessHeap(), 0,
                                                    lpcbtcwW->lpcs->lpszClass );
 	else
 	  lpcbtcwA->lpcs->lpszClass = (LPSTR)lpcbtcwW->lpcs->lpszClass;
@@ -780,11 +780,11 @@
     {
 	LPCBT_CREATEWNDA lpcbtcwA = (LPCBT_CREATEWNDA)lParam;
 	if (HIWORD(lpcbtcwA->lpcs->lpszName))
-            HeapFree( SystemHeap, 0, (LPSTR)lpcbtcwA->lpcs->lpszName );
+            HeapFree( GetProcessHeap(), 0, (LPSTR)lpcbtcwA->lpcs->lpszName );
 	if (HIWORD(lpcbtcwA->lpcs->lpszClass))
-            HeapFree( SystemHeap, 0, (LPSTR)lpcbtcwA->lpcs->lpszClass );
-	HeapFree( SystemHeap, 0, lpcbtcwA->lpcs );
-	HeapFree( SystemHeap, 0, lpcbtcwA );
+            HeapFree( GetProcessHeap(), 0, (LPSTR)lpcbtcwA->lpcs->lpszClass );
+	HeapFree( GetProcessHeap(), 0, lpcbtcwA->lpcs );
+	HeapFree( GetProcessHeap(), 0, lpcbtcwA );
     }
     return;
 }
diff --git a/windows/win.c b/windows/win.c
index 52d47cc..938b48c 100644
--- a/windows/win.c
+++ b/windows/win.c
@@ -2704,7 +2704,7 @@
  *           WIN_BuildWinArray
  *
  * Build an array of pointers to the children of a given window.
- * The array must be freed with HeapFree(SystemHeap). Return NULL
+ * The array must be freed with WIN_ReleaseWinArray. Return NULL
  * when no windows are found.
  */
 WND **WIN_BuildWinArray( WND *wndPtr, UINT bwaFlags, UINT* pTotal )
@@ -2739,7 +2739,7 @@
     {
 	/* Now build the list of all windows */
 
-	if ((list = (WND **)HeapAlloc( SystemHeap, 0, sizeof(WND *) * (count + 1))))
+	if ((list = (WND **)HeapAlloc( GetProcessHeap(), 0, sizeof(WND *) * (count + 1))))
 	{
 	    for (pWnd = WIN_LockWndPtr(wndPtr->child), ppWnd = list, count = 0; pWnd; WIN_UpdateWndPtr(&pWnd,pWnd->next))
 	    {
@@ -2765,7 +2765,7 @@
 void WIN_ReleaseWinArray(WND **wndArray)
 {
     /* Future : this function will also unlock all windows associated with wndArray */
-     HeapFree( SystemHeap, 0, wndArray );
+     HeapFree( GetProcessHeap(), 0, wndArray );
 
 }
 
diff --git a/windows/winproc.c b/windows/winproc.c
index 0c8f4fa..aea1ac6 100644
--- a/windows/winproc.c
+++ b/windows/winproc.c
@@ -524,7 +524,7 @@
     {
     case WM_GETTEXT:
         {
-            LPARAM *ptr = (LPARAM *)HeapAlloc( SystemHeap, 0,
+            LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0,
                                      wParam * sizeof(WCHAR) + sizeof(LPARAM) );
             if (!ptr) return -1;
             *ptr++ = *plparam;  /* Store previous lParam */
@@ -543,7 +543,7 @@
     case LB_FINDSTRING:
     case LB_SELECTSTRING:
     case EM_REPLACESEL:
-        *plparam = (LPARAM)HEAP_strdupAtoW( SystemHeap, 0, (LPCSTR)*plparam );
+        *plparam = (LPARAM)HEAP_strdupAtoW( GetProcessHeap(), 0, (LPCSTR)*plparam );
         return (*plparam ? 1 : -1);
 
     case WM_NCCREATE:
@@ -555,14 +555,14 @@
 	      LPCWSTR lpszClass;	/* allocated Class */
 	    };
 
-	    struct s *xs = HeapAlloc( SystemHeap, HEAP_ZERO_MEMORY, sizeof(struct s));
+	    struct s *xs = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct s));
             if (!xs) return -1;
             xs->cs = *(CREATESTRUCTW *)*plparam;
             if (HIWORD(xs->cs.lpszName))
-                xs->lpszName = xs->cs.lpszName = HEAP_strdupAtoW( SystemHeap, 0,
+                xs->lpszName = xs->cs.lpszName = HEAP_strdupAtoW( GetProcessHeap(), 0,
                                                                   (LPCSTR)xs->cs.lpszName );
             if (HIWORD(xs->cs.lpszClass))
-                xs->lpszClass = xs->cs.lpszClass = HEAP_strdupAtoW( SystemHeap, 0,
+                xs->lpszClass = xs->cs.lpszClass = HEAP_strdupAtoW( GetProcessHeap(), 0,
                                                                     (LPCSTR)xs->cs.lpszClass );
             *plparam = (LPARAM)xs;
         }
@@ -570,14 +570,14 @@
     case WM_MDICREATE:
         {
             MDICREATESTRUCTW *cs =
-                (MDICREATESTRUCTW *)HeapAlloc( SystemHeap, 0, sizeof(*cs) );
+                (MDICREATESTRUCTW *)HeapAlloc( GetProcessHeap(), 0, sizeof(*cs) );
             if (!cs) return -1;
             *cs = *(MDICREATESTRUCTW *)*plparam;
             if (HIWORD(cs->szClass))
-                cs->szClass = HEAP_strdupAtoW( SystemHeap, 0,
+                cs->szClass = HEAP_strdupAtoW( GetProcessHeap(), 0,
                                                (LPCSTR)cs->szClass );
             if (HIWORD(cs->szTitle))
-                cs->szTitle = HEAP_strdupAtoW( SystemHeap, 0,
+                cs->szTitle = HEAP_strdupAtoW( GetProcessHeap(), 0,
                                                (LPCSTR)cs->szTitle );
             *plparam = (LPARAM)cs;
         }
@@ -587,12 +587,12 @@
     case LB_ADDSTRING:
     case LB_INSERTSTRING:
 	if ( WINPROC_TestLBForStr( hwnd ))
-          *plparam = (LPARAM)HEAP_strdupAtoW( SystemHeap, 0, (LPCSTR)*plparam );
+          *plparam = (LPARAM)HEAP_strdupAtoW( GetProcessHeap(), 0, (LPCSTR)*plparam );
         return (*plparam ? 1 : -1);
 
     case LB_GETTEXT:		    /* fixme: fixed sized buffer */
         { if ( WINPROC_TestLBForStr( hwnd ))
-	  { LPARAM *ptr = (LPARAM *)HeapAlloc( SystemHeap, 0, 256 * sizeof(WCHAR) + sizeof(LPARAM) );
+	  { LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0, 256 * sizeof(WCHAR) + sizeof(LPARAM) );
             if (!ptr) return -1;
             *ptr++ = *plparam;  /* Store previous lParam */
             *plparam = (LPARAM)ptr;
@@ -604,12 +604,12 @@
     case CB_ADDSTRING:
     case CB_INSERTSTRING:
 	if ( WINPROC_TestCBForStr( hwnd ))
-          *plparam = (LPARAM)HEAP_strdupAtoW( SystemHeap, 0, (LPCSTR)*plparam );
+          *plparam = (LPARAM)HEAP_strdupAtoW( GetProcessHeap(), 0, (LPCSTR)*plparam );
         return (*plparam ? 1 : -1);
 
     case CB_GETLBTEXT:    /* fixme: fixed sized buffer */
         { if ( WINPROC_TestCBForStr( hwnd ))
-          { LPARAM *ptr = (LPARAM *)HeapAlloc( SystemHeap, 0, 256 * sizeof(WCHAR) + sizeof(LPARAM) );
+          { LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0, 256 * sizeof(WCHAR) + sizeof(LPARAM) );
             if (!ptr) return -1;
             *ptr++ = *plparam;  /* Store previous lParam */
             *plparam = (LPARAM)ptr;
@@ -620,7 +620,7 @@
 /* Multiline edit */
     case EM_GETLINE:
         { WORD len = (WORD)*plparam;
-	  LPARAM *ptr = (LPARAM *) HEAP_xalloc( SystemHeap, 0, sizeof(LPARAM) + sizeof (WORD) + len*sizeof(WCHAR) );
+	  LPARAM *ptr = (LPARAM *) HEAP_xalloc( GetProcessHeap(), 0, sizeof(LPARAM) + sizeof (WORD) + len*sizeof(WCHAR) );
           if (!ptr) return -1;
           *ptr++ = *plparam;  /* Store previous lParam */
 	  *((WORD *) ptr) = len;   /* Store the length */
@@ -654,7 +654,7 @@
         {
             LPARAM *ptr = (LPARAM *)lParam - 1;
             lstrcpynWtoA( (LPSTR)*ptr, (LPWSTR)lParam, wParam );
-            HeapFree( SystemHeap, 0, ptr );
+            HeapFree( GetProcessHeap(), 0, ptr );
         }
         break;
 
@@ -667,9 +667,9 @@
 	      LPWSTR lpszClass;		/* allocated Class */
 	    };
             struct s *xs = (struct s *)lParam;
-            if (xs->lpszName)  HeapFree( SystemHeap, 0, xs->lpszName );
-            if (xs->lpszClass) HeapFree( SystemHeap, 0, xs->lpszClass );
-            HeapFree( SystemHeap, 0, xs );
+            if (xs->lpszName)  HeapFree( GetProcessHeap(), 0, xs->lpszName );
+            if (xs->lpszClass) HeapFree( GetProcessHeap(), 0, xs->lpszClass );
+            HeapFree( GetProcessHeap(), 0, xs );
         }
         break;
 
@@ -677,10 +677,10 @@
         {
             MDICREATESTRUCTW *cs = (MDICREATESTRUCTW *)lParam;
             if (HIWORD(cs->szTitle))
-                HeapFree( SystemHeap, 0, (LPVOID)cs->szTitle );
+                HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szTitle );
             if (HIWORD(cs->szClass))
-                HeapFree( SystemHeap, 0, (LPVOID)cs->szClass );
-            HeapFree( SystemHeap, 0, cs );
+                HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szClass );
+            HeapFree( GetProcessHeap(), 0, cs );
         }
         break;
 
@@ -695,21 +695,21 @@
     case LB_FINDSTRING:
     case LB_SELECTSTRING:
     case EM_REPLACESEL:
-        HeapFree( SystemHeap, 0, (void *)lParam );
+        HeapFree( GetProcessHeap(), 0, (void *)lParam );
         break;
 
 /* Listbox */
     case LB_ADDSTRING:
     case LB_INSERTSTRING:
 	if ( WINPROC_TestLBForStr( hwnd ))
-          HeapFree( SystemHeap, 0, (void *)lParam );
+          HeapFree( GetProcessHeap(), 0, (void *)lParam );
         break;
 
     case LB_GETTEXT:
         { if ( WINPROC_TestLBForStr( hwnd ))
           { LPARAM *ptr = (LPARAM *)lParam - 1;
 	    lstrcpyWtoA( (LPSTR)*ptr, (LPWSTR)(lParam) );
-            HeapFree( SystemHeap, 0, ptr );
+            HeapFree( GetProcessHeap(), 0, ptr );
 	  }
         }
         break;
@@ -718,14 +718,14 @@
     case CB_ADDSTRING:
     case CB_INSERTSTRING:
 	if ( WINPROC_TestCBForStr( hwnd ))
-          HeapFree( SystemHeap, 0, (void *)lParam );
+          HeapFree( GetProcessHeap(), 0, (void *)lParam );
         break;
 
     case CB_GETLBTEXT:
         { if ( WINPROC_TestCBForStr( hwnd ))
 	  { LPARAM *ptr = (LPARAM *)lParam - 1;
             lstrcpyWtoA( (LPSTR)*ptr, (LPWSTR)(lParam) );
-            HeapFree( SystemHeap, 0, ptr );
+            HeapFree( GetProcessHeap(), 0, ptr );
 	  }
         }
         break;
@@ -735,7 +735,7 @@
         { LPARAM * ptr = (LPARAM *)lParam - 1;  /* get the old lParam */
 	  WORD len = *(WORD *) lParam;
           lstrcpynWtoA( (LPSTR)*ptr , (LPWSTR)lParam, len );
-          HeapFree( SystemHeap, 0, ptr );
+          HeapFree( GetProcessHeap(), 0, ptr );
         }
         break;
     }
@@ -753,7 +753,7 @@
     {
     case WM_GETTEXT:
         {
-            LPARAM *ptr = (LPARAM *)HeapAlloc( SystemHeap, 0,
+            LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0,
                                                wParam + sizeof(LPARAM) );
             if (!ptr) return -1;
             *ptr++ = *plparam;  /* Store previous lParam */
@@ -772,21 +772,21 @@
     case LB_FINDSTRING:
     case LB_SELECTSTRING:
     case EM_REPLACESEL:
-        *plparam = (LPARAM)HEAP_strdupWtoA( SystemHeap, 0, (LPCWSTR)*plparam );
+        *plparam = (LPARAM)HEAP_strdupWtoA( GetProcessHeap(), 0, (LPCWSTR)*plparam );
         return (*plparam ? 1 : -1);
 
     case WM_NCCREATE:
     case WM_CREATE:
         {
-            CREATESTRUCTA *cs = (CREATESTRUCTA *)HeapAlloc( SystemHeap, 0,
+            CREATESTRUCTA *cs = (CREATESTRUCTA *)HeapAlloc( GetProcessHeap(), 0,
                                                                 sizeof(*cs) );
             if (!cs) return -1;
             *cs = *(CREATESTRUCTA *)*plparam;
             if (HIWORD(cs->lpszName))
-                cs->lpszName  = HEAP_strdupWtoA( SystemHeap, 0,
+                cs->lpszName  = HEAP_strdupWtoA( GetProcessHeap(), 0,
                                                  (LPCWSTR)cs->lpszName );
             if (HIWORD(cs->lpszClass))
-                cs->lpszClass = HEAP_strdupWtoA( SystemHeap, 0,
+                cs->lpszClass = HEAP_strdupWtoA( GetProcessHeap(), 0,
                                                  (LPCWSTR)cs->lpszClass);
             *plparam = (LPARAM)cs;
         }
@@ -794,14 +794,14 @@
     case WM_MDICREATE:
         {
             MDICREATESTRUCTA *cs =
-                (MDICREATESTRUCTA *)HeapAlloc( SystemHeap, 0, sizeof(*cs) );
+                (MDICREATESTRUCTA *)HeapAlloc( GetProcessHeap(), 0, sizeof(*cs) );
             if (!cs) return -1;
             *cs = *(MDICREATESTRUCTA *)*plparam;
             if (HIWORD(cs->szTitle))
-                cs->szTitle = HEAP_strdupWtoA( SystemHeap, 0,
+                cs->szTitle = HEAP_strdupWtoA( GetProcessHeap(), 0,
                                                (LPCWSTR)cs->szTitle );
             if (HIWORD(cs->szClass))
-                cs->szClass = HEAP_strdupWtoA( SystemHeap, 0,
+                cs->szClass = HEAP_strdupWtoA( GetProcessHeap(), 0,
                                                (LPCWSTR)cs->szClass );
             *plparam = (LPARAM)cs;
         }
@@ -811,12 +811,12 @@
     case LB_ADDSTRING:
     case LB_INSERTSTRING:
 	if ( WINPROC_TestLBForStr( hwnd ))
-          *plparam = (LPARAM)HEAP_strdupWtoA( SystemHeap, 0, (LPCWSTR)*plparam );
+          *plparam = (LPARAM)HEAP_strdupWtoA( GetProcessHeap(), 0, (LPCWSTR)*plparam );
         return (*plparam ? 1 : -1);
 
     case LB_GETTEXT:			/* fixme: fixed sized buffer */
         { if ( WINPROC_TestLBForStr( hwnd ))
-	  { LPARAM *ptr = (LPARAM *)HeapAlloc( SystemHeap, 0, 256 + sizeof(LPARAM) );
+	  { LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0, 256 + sizeof(LPARAM) );
             if (!ptr) return -1;
             *ptr++ = *plparam;  /* Store previous lParam */
             *plparam = (LPARAM)ptr;
@@ -828,12 +828,12 @@
     case CB_ADDSTRING:
     case CB_INSERTSTRING:
 	if ( WINPROC_TestCBForStr( hwnd ))
-          *plparam = (LPARAM)HEAP_strdupWtoA( SystemHeap, 0, (LPCWSTR)*plparam );
+          *plparam = (LPARAM)HEAP_strdupWtoA( GetProcessHeap(), 0, (LPCWSTR)*plparam );
         return (*plparam ? 1 : -1);
 
     case CB_GETLBTEXT:		/* fixme: fixed sized buffer */
         { if ( WINPROC_TestCBForStr( hwnd ))
-	  { LPARAM *ptr = (LPARAM *)HeapAlloc( SystemHeap, 0, 256 + sizeof(LPARAM) );
+	  { LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0, 256 + sizeof(LPARAM) );
             if (!ptr) return -1;
             *ptr++ = *plparam;  /* Store previous lParam */
             *plparam = (LPARAM)ptr;
@@ -844,7 +844,7 @@
 /* Multiline edit */
     case EM_GETLINE:
         { WORD len = (WORD)*plparam;
-	  LPARAM *ptr = (LPARAM *) HEAP_xalloc( SystemHeap, 0, sizeof(LPARAM) + sizeof (WORD) + len*sizeof(CHAR) );
+	  LPARAM *ptr = (LPARAM *) HEAP_xalloc( GetProcessHeap(), 0, sizeof(LPARAM) + sizeof (WORD) + len*sizeof(CHAR) );
           if (!ptr) return -1;
           *ptr++ = *plparam;  /* Store previous lParam */
 	  *((WORD *) ptr) = len;   /* Store the length */
@@ -878,7 +878,7 @@
         {
             LPARAM *ptr = (LPARAM *)lParam - 1;
             lstrcpynAtoW( (LPWSTR)*ptr, (LPSTR)lParam, wParam );
-            HeapFree( SystemHeap, 0, ptr );
+            HeapFree( GetProcessHeap(), 0, ptr );
         }
         break;
 
@@ -893,7 +893,7 @@
     case LB_FINDSTRING:
     case LB_SELECTSTRING:
     case EM_REPLACESEL:
-        HeapFree( SystemHeap, 0, (void *)lParam );
+        HeapFree( GetProcessHeap(), 0, (void *)lParam );
         break;
 
     case WM_NCCREATE:
@@ -901,10 +901,10 @@
         {
             CREATESTRUCTA *cs = (CREATESTRUCTA *)lParam;
             if (HIWORD(cs->lpszName))
-                HeapFree( SystemHeap, 0, (LPVOID)cs->lpszName );
+                HeapFree( GetProcessHeap(), 0, (LPVOID)cs->lpszName );
             if (HIWORD(cs->lpszClass))
-                HeapFree( SystemHeap, 0, (LPVOID)cs->lpszClass );
-            HeapFree( SystemHeap, 0, cs );
+                HeapFree( GetProcessHeap(), 0, (LPVOID)cs->lpszClass );
+            HeapFree( GetProcessHeap(), 0, cs );
         }
         break;
 
@@ -912,10 +912,10 @@
         {
             MDICREATESTRUCTA *cs = (MDICREATESTRUCTA *)lParam;
             if (HIWORD(cs->szTitle))
-                HeapFree( SystemHeap, 0, (LPVOID)cs->szTitle );
+                HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szTitle );
             if (HIWORD(cs->szClass))
-                HeapFree( SystemHeap, 0, (LPVOID)cs->szClass );
-            HeapFree( SystemHeap, 0, cs );
+                HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szClass );
+            HeapFree( GetProcessHeap(), 0, cs );
         }
         break;
 
@@ -923,14 +923,14 @@
     case LB_ADDSTRING:
     case LB_INSERTSTRING:
 	if ( WINPROC_TestLBForStr( hwnd ))
-          HeapFree( SystemHeap, 0, (void *)lParam );
+          HeapFree( GetProcessHeap(), 0, (void *)lParam );
         break;
 
     case LB_GETTEXT:
         { if ( WINPROC_TestLBForStr( hwnd ))
           { LPARAM *ptr = (LPARAM *)lParam - 1;
             lstrcpyAtoW( (LPWSTR)*ptr, (LPSTR)(lParam) );
-            HeapFree( SystemHeap, 0, ptr );
+            HeapFree( GetProcessHeap(), 0, ptr );
 	  }
         }
         break;
@@ -939,14 +939,14 @@
     case CB_ADDSTRING:
     case CB_INSERTSTRING:
 	if ( WINPROC_TestCBForStr( hwnd ))
-          HeapFree( SystemHeap, 0, (void *)lParam );
+          HeapFree( GetProcessHeap(), 0, (void *)lParam );
         break;
 
     case CB_GETLBTEXT:
         { if ( WINPROC_TestCBForStr( hwnd ))
           { LPARAM *ptr = (LPARAM *)lParam - 1;
             lstrcpyAtoW( (LPWSTR)*ptr, (LPSTR)(lParam) );
-            HeapFree( SystemHeap, 0, ptr );
+            HeapFree( GetProcessHeap(), 0, ptr );
 	  }
         }
         break;
@@ -956,7 +956,7 @@
         { LPARAM * ptr = (LPARAM *)lParam - 1;  /* get the old lparam */
 	  WORD len = *(WORD *)ptr;
           lstrcpynAtoW( (LPWSTR) *ptr, (LPSTR)lParam, len );
-          HeapFree( SystemHeap, 0, ptr );
+          HeapFree( GetProcessHeap(), 0, ptr );
         }
         break;
     }
@@ -998,7 +998,7 @@
         {
             COMPAREITEMSTRUCT16* cis16 = (COMPAREITEMSTRUCT16 *)PTR_SEG_TO_LIN(*plparam);
             COMPAREITEMSTRUCT *cis = (COMPAREITEMSTRUCT *)
-                                        HeapAlloc(SystemHeap, 0, sizeof(*cis));
+                                        HeapAlloc(GetProcessHeap(), 0, sizeof(*cis));
             if (!cis) return -1;
             cis->CtlType    = cis16->CtlType;
             cis->CtlID      = cis16->CtlID;
@@ -1015,7 +1015,7 @@
         {
             DELETEITEMSTRUCT16* dis16 = (DELETEITEMSTRUCT16 *)PTR_SEG_TO_LIN(*plparam);
             DELETEITEMSTRUCT *dis = (DELETEITEMSTRUCT *)
-                                        HeapAlloc(SystemHeap, 0, sizeof(*dis));
+                                        HeapAlloc(GetProcessHeap(), 0, sizeof(*dis));
             if (!dis) return -1;
             dis->CtlType  = dis16->CtlType;
             dis->CtlID    = dis16->CtlID;
@@ -1028,7 +1028,7 @@
         {
             MEASUREITEMSTRUCT16* mis16 = (MEASUREITEMSTRUCT16 *)PTR_SEG_TO_LIN(*plparam);
             MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *)
-                                        HeapAlloc(SystemHeap, 0,
+                                        HeapAlloc(GetProcessHeap(), 0,
                                                 sizeof(*mis) + sizeof(LPARAM));
             if (!mis) return -1;
             mis->CtlType    = mis16->CtlType;
@@ -1044,7 +1044,7 @@
     case WM_DRAWITEM:
         {
             DRAWITEMSTRUCT16* dis16 = (DRAWITEMSTRUCT16 *)PTR_SEG_TO_LIN(*plparam);
-            DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT*)HeapAlloc(SystemHeap, 0,
+            DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT*)HeapAlloc(GetProcessHeap(), 0,
                                                                  sizeof(*dis));
             if (!dis) return -1;
             dis->CtlType    = dis16->CtlType;
@@ -1061,7 +1061,7 @@
         return 1;
     case WM_GETMINMAXINFO:
         {
-            MINMAXINFO *mmi = (MINMAXINFO *)HeapAlloc( SystemHeap, 0,
+            MINMAXINFO *mmi = (MINMAXINFO *)HeapAlloc( GetProcessHeap(), 0,
                                                 sizeof(*mmi) + sizeof(LPARAM));
             if (!mmi) return -1;
             STRUCT32_MINMAXINFO16to32( (MINMAXINFO16*)PTR_SEG_TO_LIN(*plparam),
@@ -1079,7 +1079,7 @@
             MDICREATESTRUCT16 *cs16 =
                 (MDICREATESTRUCT16 *)PTR_SEG_TO_LIN(*plparam);
             MDICREATESTRUCTA *cs =
-                (MDICREATESTRUCTA *)HeapAlloc( SystemHeap, 0,
+                (MDICREATESTRUCTA *)HeapAlloc( GetProcessHeap(), 0,
                                                 sizeof(*cs) + sizeof(LPARAM) );
             if (!cs) return -1;
             STRUCT32_MDICREATESTRUCT16to32A( cs16, cs );
@@ -1090,7 +1090,7 @@
         }
         return 1;
     case WM_MDIGETACTIVE:
-        *plparam = (LPARAM)HeapAlloc( SystemHeap, 0, sizeof(BOOL) );
+        *plparam = (LPARAM)HeapAlloc( GetProcessHeap(), 0, sizeof(BOOL) );
         *(BOOL*)(*plparam) = 0;
         return 1;
     case WM_MDISETMENU:
@@ -1128,14 +1128,14 @@
             NCCALCSIZE_PARAMS16 *nc16;
             NCCALCSIZE_PARAMS *nc;
 
-            nc = (NCCALCSIZE_PARAMS *)HeapAlloc( SystemHeap, 0,
+            nc = (NCCALCSIZE_PARAMS *)HeapAlloc( GetProcessHeap(), 0,
                                                 sizeof(*nc) + sizeof(LPARAM) );
             if (!nc) return -1;
             nc16 = (NCCALCSIZE_PARAMS16 *)PTR_SEG_TO_LIN(*plparam);
             CONV_RECT16TO32( &nc16->rgrc[0], &nc->rgrc[0] );
             if (wParam16)
             {
-                nc->lppos = (WINDOWPOS *)HeapAlloc( SystemHeap, 0,
+                nc->lppos = (WINDOWPOS *)HeapAlloc( GetProcessHeap(), 0,
                                                       sizeof(*nc->lppos) );
                 CONV_RECT16TO32( &nc16->rgrc[1], &nc->rgrc[1] );
                 CONV_RECT16TO32( &nc16->rgrc[2], &nc->rgrc[2] );
@@ -1149,7 +1149,7 @@
     case WM_CREATE:
         {
             CREATESTRUCT16 *cs16 = (CREATESTRUCT16 *)PTR_SEG_TO_LIN(*plparam);
-            CREATESTRUCTA *cs = (CREATESTRUCTA *)HeapAlloc( SystemHeap, 0,
+            CREATESTRUCTA *cs = (CREATESTRUCTA *)HeapAlloc( GetProcessHeap(), 0,
                                                 sizeof(*cs) + sizeof(LPARAM) );
             if (!cs) return -1;
             STRUCT32_CREATESTRUCT16to32A( cs16, cs );
@@ -1169,7 +1169,7 @@
     case WM_WINDOWPOSCHANGING:
     case WM_WINDOWPOSCHANGED:
         {
-            WINDOWPOS *wp = (WINDOWPOS *)HeapAlloc( SystemHeap, 0,
+            WINDOWPOS *wp = (WINDOWPOS *)HeapAlloc( GetProcessHeap(), 0,
                                                 sizeof(*wp) + sizeof(LPARAM) );
             if (!wp) return -1;
             STRUCT32_WINDOWPOS16to32( (WINDOWPOS16 *)PTR_SEG_TO_LIN(*plparam),
@@ -1182,7 +1182,7 @@
         if (*plparam)
         {
             LPMSG16 msg16 = (LPMSG16)PTR_SEG_TO_LIN(*plparam);
-            LPMSG msg32 = (LPMSG)HeapAlloc( SystemHeap, 0, sizeof(MSG) );
+            LPMSG msg32 = (LPMSG)HeapAlloc( GetProcessHeap(), 0, sizeof(MSG) );
 
             if (!msg32) return -1;
             msg32->hwnd = msg16->hwnd;
@@ -1193,7 +1193,7 @@
             if (WINPROC_MapMsg16To32A(msg16->message,msg16->wParam,
                                      &msg32->message,&msg32->wParam,
                                      &msg32->lParam)<0) {
-                HeapFree( SystemHeap, 0, msg32 );
+                HeapFree( GetProcessHeap(), 0, msg32 );
                 return -1;
             }
             *plparam = (LPARAM)msg32;
@@ -1241,7 +1241,7 @@
     case WM_COMPAREITEM:
     case WM_DELETEITEM:
     case WM_DRAWITEM:
-        HeapFree( SystemHeap, 0, (LPVOID)lParam );
+        HeapFree( GetProcessHeap(), 0, (LPVOID)lParam );
         break;
     case WM_MEASUREITEM:
         {
@@ -1251,7 +1251,7 @@
             mis16 = (MEASUREITEMSTRUCT16 *)PTR_SEG_TO_LIN(lParam);
             mis16->itemWidth  = (UINT16)mis->itemWidth;
             mis16->itemHeight = (UINT16)mis->itemHeight;
-            HeapFree( SystemHeap, 0, mis );
+            HeapFree( GetProcessHeap(), 0, mis );
         }
         break;
     case WM_GETMINMAXINFO:
@@ -1260,7 +1260,7 @@
             lParam = *(LPARAM *)(mmi + 1);
             STRUCT32_MINMAXINFO32to16( mmi,
                                        (MINMAXINFO16 *)PTR_SEG_TO_LIN(lParam));
-            HeapFree( SystemHeap, 0, mmi );
+            HeapFree( GetProcessHeap(), 0, mmi );
         }
         break;
     case WM_MDICREATE:
@@ -1269,12 +1269,12 @@
             lParam = *(LPARAM *)(cs + 1);
             STRUCT32_MDICREATESTRUCT32Ato16( cs,
                                  (MDICREATESTRUCT16 *)PTR_SEG_TO_LIN(lParam) );
-            HeapFree( SystemHeap, 0, cs );
+            HeapFree( GetProcessHeap(), 0, cs );
         }
         break;
     case WM_MDIGETACTIVE:
         result = MAKELONG( LOWORD(result), (BOOL16)(*(BOOL *)lParam) );
-        HeapFree( SystemHeap, 0, (BOOL *)lParam );
+        HeapFree( GetProcessHeap(), 0, (BOOL *)lParam );
         break;
     case WM_NCCALCSIZE:
         {
@@ -1291,10 +1291,10 @@
                 {
                     STRUCT32_WINDOWPOS32to16( nc->lppos,
                                    (WINDOWPOS16 *)PTR_SEG_TO_LIN(nc16->lppos));
-                    HeapFree( SystemHeap, 0, nc->lppos );
+                    HeapFree( GetProcessHeap(), 0, nc->lppos );
                 }
             }
-            HeapFree( SystemHeap, 0, nc );
+            HeapFree( GetProcessHeap(), 0, nc );
         }
 	break;
     case WM_NCCREATE:
@@ -1304,7 +1304,7 @@
             lParam = *(LPARAM *)(cs + 1);
             STRUCT32_CREATESTRUCT32Ato16( cs,
                                     (CREATESTRUCT16 *)PTR_SEG_TO_LIN(lParam) );
-            HeapFree( SystemHeap, 0, cs );
+            HeapFree( GetProcessHeap(), 0, cs );
         }
         break;
     case WM_WINDOWPOSCHANGING:
@@ -1313,7 +1313,7 @@
             WINDOWPOS *wp = (WINDOWPOS *)lParam;
             lParam = *(LPARAM *)(wp + 1);
             STRUCT32_WINDOWPOS32to16(wp,(WINDOWPOS16 *)PTR_SEG_TO_LIN(lParam));
-            HeapFree( SystemHeap, 0, wp );
+            HeapFree( GetProcessHeap(), 0, wp );
         }
         break;
     case WM_GETDLGCODE:
@@ -1323,7 +1323,7 @@
 
             WINPROC_UnmapMsg16To32A( hwnd, msg32->message, msg32->wParam, msg32->lParam,
                                      result);
-            HeapFree( SystemHeap, 0, msg32 );
+            HeapFree( GetProcessHeap(), 0, msg32 );
         }
         break;
     }
@@ -1350,17 +1350,17 @@
     case WM_CREATE:
         {
             CREATESTRUCT16 *cs16 = (CREATESTRUCT16 *)PTR_SEG_TO_LIN(*plparam);
-            CREATESTRUCTW *cs = (CREATESTRUCTW *)HeapAlloc( SystemHeap, 0,
+            CREATESTRUCTW *cs = (CREATESTRUCTW *)HeapAlloc( GetProcessHeap(), 0,
                                                 sizeof(*cs) + sizeof(LPARAM) );
             if (!cs) return -1;
             STRUCT32_CREATESTRUCT16to32A( cs16, (CREATESTRUCTA *)cs );
             cs->lpszName  = (LPCWSTR)PTR_SEG_TO_LIN(cs16->lpszName);
             cs->lpszClass = (LPCWSTR)PTR_SEG_TO_LIN(cs16->lpszClass);
             if (HIWORD(cs->lpszName))
-                cs->lpszName = HEAP_strdupAtoW( SystemHeap, 0,
+                cs->lpszName = HEAP_strdupAtoW( GetProcessHeap(), 0,
                                                 (LPCSTR)cs->lpszName );
             if (HIWORD(cs->lpszClass))
-                cs->lpszClass = HEAP_strdupAtoW( SystemHeap, 0,
+                cs->lpszClass = HEAP_strdupAtoW( GetProcessHeap(), 0,
                                                  (LPCSTR)cs->lpszClass );
             *(LPARAM *)(cs + 1) = *plparam;  /* Store the previous lParam */
             *plparam = (LPARAM)cs;
@@ -1371,17 +1371,17 @@
             MDICREATESTRUCT16 *cs16 =
                 (MDICREATESTRUCT16 *)PTR_SEG_TO_LIN(*plparam);
             MDICREATESTRUCTW *cs =
-                (MDICREATESTRUCTW *)HeapAlloc( SystemHeap, 0,
+                (MDICREATESTRUCTW *)HeapAlloc( GetProcessHeap(), 0,
                                                 sizeof(*cs) + sizeof(LPARAM) );
             if (!cs) return -1;
             STRUCT32_MDICREATESTRUCT16to32A( cs16, (MDICREATESTRUCTA *)cs );
             cs->szTitle = (LPCWSTR)PTR_SEG_TO_LIN(cs16->szTitle);
             cs->szClass = (LPCWSTR)PTR_SEG_TO_LIN(cs16->szClass);
             if (HIWORD(cs->szTitle))
-                cs->szTitle = HEAP_strdupAtoW( SystemHeap, 0,
+                cs->szTitle = HEAP_strdupAtoW( GetProcessHeap(), 0,
                                                (LPCSTR)cs->szTitle );
             if (HIWORD(cs->szClass))
-                cs->szClass = HEAP_strdupAtoW( SystemHeap, 0,
+                cs->szClass = HEAP_strdupAtoW( GetProcessHeap(), 0,
                                                (LPCSTR)cs->szClass );
             *(LPARAM *)(cs + 1) = *plparam;  /* Store the previous lParam */
             *plparam = (LPARAM)cs;
@@ -1391,7 +1391,7 @@
         if (*plparam)
         {
             LPMSG16 msg16 = (LPMSG16)PTR_SEG_TO_LIN(*plparam);
-            LPMSG msg32 = (LPMSG)HeapAlloc( SystemHeap, 0, sizeof(MSG) );
+            LPMSG msg32 = (LPMSG)HeapAlloc( GetProcessHeap(), 0, sizeof(MSG) );
 
             if (!msg32) return -1;
             msg32->hwnd = msg16->hwnd;
@@ -1402,7 +1402,7 @@
             if (WINPROC_MapMsg16To32W(hwnd, msg16->message,msg16->wParam,
                                      &msg32->message,&msg32->wParam,
                                      &msg32->lParam)<0) {
-                HeapFree( SystemHeap, 0, msg32 );
+                HeapFree( GetProcessHeap(), 0, msg32 );
                 return -1;
             }
             *plparam = (LPARAM)msg32;
@@ -1438,10 +1438,10 @@
             STRUCT32_CREATESTRUCT32Ato16( (CREATESTRUCTA *)cs,
                                     (CREATESTRUCT16 *)PTR_SEG_TO_LIN(lParam) );
             if (HIWORD(cs->lpszName))
-                HeapFree( SystemHeap, 0, (LPVOID)cs->lpszName );
+                HeapFree( GetProcessHeap(), 0, (LPVOID)cs->lpszName );
             if (HIWORD(cs->lpszClass))
-                HeapFree( SystemHeap, 0, (LPVOID)cs->lpszClass );
-            HeapFree( SystemHeap, 0, cs );
+                HeapFree( GetProcessHeap(), 0, (LPVOID)cs->lpszClass );
+            HeapFree( GetProcessHeap(), 0, cs );
         }
         break;
     case WM_MDICREATE:
@@ -1451,10 +1451,10 @@
             STRUCT32_MDICREATESTRUCT32Ato16( (MDICREATESTRUCTA *)cs,
                                  (MDICREATESTRUCT16 *)PTR_SEG_TO_LIN(lParam) );
             if (HIWORD(cs->szTitle))
-                HeapFree( SystemHeap, 0, (LPVOID)cs->szTitle );
+                HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szTitle );
             if (HIWORD(cs->szClass))
-                HeapFree( SystemHeap, 0, (LPVOID)cs->szClass );
-            HeapFree( SystemHeap, 0, cs );
+                HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szClass );
+            HeapFree( GetProcessHeap(), 0, cs );
         }
         break;
     case WM_GETDLGCODE:
@@ -1464,7 +1464,7 @@
 
             WINPROC_UnmapMsg16To32W( hwnd, msg32->message, msg32->wParam, msg32->lParam,
                                      result);
-            HeapFree( SystemHeap, 0, msg32 );
+            HeapFree( GetProcessHeap(), 0, msg32 );
         }
         break;
     default: