Separated 32 bit functions to shellole.c.

diff --git a/dlls/shell32/shell.c b/dlls/shell32/shell.c
index 81ff988..d327542 100644
--- a/dlls/shell32/shell.c
+++ b/dlls/shell32/shell.c
@@ -3,7 +3,6 @@
  *
  *  1998 Marcus Meissner
  */
-#include <assert.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
@@ -26,8 +25,8 @@
 #include "debugtools.h"
 #include "winreg.h"
 #include "syslevel.h"
+#include "shlwapi.h"
 #include "imagelist.h"
-#include "tchar.h"
 
 DEFAULT_DEBUG_CHANNEL(shell)
 DECLARE_DEBUG_CHANNEL(exec)
@@ -124,22 +123,6 @@
 }
 
 /*************************************************************************
- *				DragAcceptFiles		[SHELL32.54]
- */
-void WINAPI DragAcceptFiles(HWND hWnd, BOOL b)
-{
-  LONG exstyle;
-  
-  
-  if( !IsWindow(hWnd) )
-  	return;
-  exstyle = GetWindowLongA(hWnd,GWL_EXSTYLE);
-  if (b)exstyle |= WS_EX_ACCEPTFILES;
-  else	exstyle &= ~WS_EX_ACCEPTFILES;
-  SetWindowLongA(hWnd,GWL_EXSTYLE,exstyle);
-}
-
-/*************************************************************************
  *				DragAcceptFiles16		[SHELL.9]
  */
 void WINAPI DragAcceptFiles16(HWND16 hWnd, BOOL16 b)
@@ -148,129 +131,43 @@
 }
 
 /*************************************************************************
- *				SHELL_DragQueryFile	[internal]
- * 
- */
-static UINT SHELL_DragQueryFile(LPSTR lpDrop, LPWSTR lpwDrop, UINT lFile, 
-				  LPSTR lpszFile, LPWSTR lpszwFile, UINT lLength)
-{
-    UINT i;
-
-    i = 0;
-    if (lpDrop) {
-    while (i++ < lFile) {
-	while (*lpDrop++); /* skip filename */
-	if (!*lpDrop) 
-	  return (lFile == 0xFFFFFFFF) ? i : 0;  
-      }
-    }
-    if (lpwDrop) {
-      while (i++ < lFile) {
-	while (*lpwDrop++); /* skip filename */
-	if (!*lpwDrop) 
-	  return (lFile == 0xFFFFFFFF) ? i : 0;  
-      }
-    }
-    
-    if (lpDrop)  i = lstrlenA(lpDrop);
-    if (lpwDrop) i = lstrlenW(lpwDrop);
-    i++;
-    if (!lpszFile && !lpszwFile) {
-      return i;   /* needed buffer size */
-    }
-    i = (lLength > i) ? i : lLength;
-    if (lpszFile) {
-      if (lpDrop) lstrcpynA (lpszFile,  lpDrop,  i);
-      else        lstrcpynWtoA(lpszFile,  lpwDrop, i);
-    } else {
-      if (lpDrop) lstrcpynAtoW(lpszwFile, lpDrop,  i);
-      else        lstrcpynW (lpszwFile, lpwDrop, i);
-    }
-    return i;
-}
-
-/*************************************************************************
- *				DragQueryFileA	[SHELL32.81] [shell32.82]
- */
-UINT WINAPI DragQueryFileA(HDROP hDrop, UINT lFile, LPSTR lpszFile,
-			      UINT lLength)
-{ /* hDrop is a global memory block allocated with GMEM_SHARE 
-     * with DROPFILESTRUCT as a header and filenames following
-     * it, zero length filename is in the end */       
-    
-    LPDROPFILESTRUCT lpDropFileStruct;
-    LPSTR lpCurrent;
-    UINT i;
-    
-    TRACE("(%08x, %x, %p, %u)\n",	hDrop,lFile,lpszFile,lLength);
-    
-    lpDropFileStruct = (LPDROPFILESTRUCT) GlobalLock(hDrop); 
-    if(!lpDropFileStruct)
-      return 0;
-
-    lpCurrent = (LPSTR) lpDropFileStruct + lpDropFileStruct->lSize;
-    i = SHELL_DragQueryFile(lpCurrent, NULL, lFile, lpszFile, NULL, lLength);
-    GlobalUnlock(hDrop);
-    return i;
-}
-
-/*************************************************************************
- *				DragQueryFileW	[shell32.133]
- */
-UINT WINAPI DragQueryFileW(HDROP hDrop, UINT lFile, LPWSTR lpszwFile,
-			      UINT lLength)
-{
-    LPDROPFILESTRUCT lpDropFileStruct;
-    LPWSTR lpwCurrent;
-    UINT i;
-    
-    TRACE("(%08x, %x, %p, %u)\n",	hDrop,lFile,lpszwFile,lLength);
-    
-    lpDropFileStruct = (LPDROPFILESTRUCT) GlobalLock(hDrop); 
-    if(!lpDropFileStruct)
-      return 0;
-
-    lpwCurrent = (LPWSTR) lpDropFileStruct + lpDropFileStruct->lSize;
-    i = SHELL_DragQueryFile(NULL, lpwCurrent, lFile, NULL, lpszwFile,lLength);
-    GlobalUnlock(hDrop);
-    return i;
-}
-/*************************************************************************
  *				DragQueryFile16		[SHELL.11]
  */
-UINT16 WINAPI DragQueryFile16(HDROP16 hDrop, WORD wFile, LPSTR lpszFile,
-                            WORD wLength)
-{ /* hDrop is a global memory block allocated with GMEM_SHARE 
-     * with DROPFILESTRUCT as a header and filenames following
-     * it, zero length filename is in the end */       
-    
-    LPDROPFILESTRUCT16 lpDropFileStruct;
-    LPSTR lpCurrent;
-    WORD  i;
-    
-    TRACE("(%04x, %x, %p, %u)\n", hDrop,wFile,lpszFile,wLength);
-    
-    lpDropFileStruct = (LPDROPFILESTRUCT16) GlobalLock16(hDrop); 
-    if(!lpDropFileStruct)
-      return 0;
-    
-    lpCurrent = (LPSTR) lpDropFileStruct + lpDropFileStruct->wSize;
-
-    i = (WORD)SHELL_DragQueryFile(lpCurrent, NULL, wFile==0xffff?0xffffffff:wFile,
-				  lpszFile, NULL, wLength);
-    GlobalUnlock16(hDrop);
-    return i;
-}
-
-
-
-/*************************************************************************
- *				DragFinish		[SHELL32.80]
- */
-void WINAPI DragFinish(HDROP h)
+UINT16 WINAPI DragQueryFile16(
+	HDROP16 hDrop,
+	WORD wFile,
+	LPSTR lpszFile,
+	WORD wLength)
 {
-    TRACE("\n");
-    GlobalFree((HGLOBAL)h);
+ 	LPSTR lpDrop;
+	UINT i = 0;
+	LPDROPFILESTRUCT16 lpDropFileStruct = (LPDROPFILESTRUCT16) GlobalLock16(hDrop); 
+   
+	TRACE("(%04x, %x, %p, %u)\n", hDrop,wFile,lpszFile,wLength);
+    
+	if(!lpDropFileStruct) goto end;
+    
+	lpDrop = (LPSTR) lpDropFileStruct + lpDropFileStruct->wSize;
+	wFile = (wFile==0xffff) ? 0xffffffff : wFile;
+
+	while (i++ < wFile)
+	{
+	  while (*lpDrop++); /* skip filename */
+	  if (!*lpDrop) 
+	  {
+	    i = (wFile == 0xFFFFFFFF) ? i : 0; 
+	    goto end;
+	  }
+	}
+    
+	i = lstrlenA(lpDrop);
+	i++;
+	if (!lpszFile ) goto end;   /* needed buffer size */
+	i = (wLength > i) ? i : wLength;
+	lstrcpynA (lpszFile,  lpDrop,  i);
+end:
+	GlobalUnlock16(hDrop);
+	return i;
 }
 
 /*************************************************************************
@@ -284,23 +181,6 @@
 
 
 /*************************************************************************
- *				DragQueryPoint		[SHELL32.135]
- */
-BOOL WINAPI DragQueryPoint(HDROP hDrop, POINT *p)
-{
-  LPDROPFILESTRUCT lpDropFileStruct;  
-  BOOL             bRet;
-  TRACE("\n");
-  lpDropFileStruct = (LPDROPFILESTRUCT) GlobalLock(hDrop);
-  
-  memcpy(p,&lpDropFileStruct->ptMousePos,sizeof(POINT));
-  bRet = lpDropFileStruct->fInNonClientArea;
-  
-  GlobalUnlock(hDrop);
-  return bRet;
-}
-
-/*************************************************************************
  *				DragQueryPoint16		[SHELL.13]
  */
 BOOL16 WINAPI DragQueryPoint16(HDROP16 hDrop, POINT16 *p)
@@ -553,7 +433,7 @@
 	
 	/* Remove File Protocol from lpFile */
 	/* In the case file://path/file     */
-	if(!_strnicmp(lpFile,"file",iSize))
+	if(!strncasecmp(lpFile,"file",iSize))
 	{
 	  lpFile += iSize;
 	  while(*lpFile == ':') lpFile++;
@@ -603,7 +483,7 @@
 	}
       }
     /* Check if file specified is in the form www.??????.*** */
-      else if(!_strnicmp(lpFile,"www",3))
+      else if(!strncasecmp(lpFile,"www",3))
       {
 	/* if so, append lpFile http:// and call ShellExecute */ 
         char lpstrTmpFile[256] = "http://" ;
diff --git a/dlls/shell32/shellole.c b/dlls/shell32/shellole.c
index c0aa481..e21b97e 100644
--- a/dlls/shell32/shellole.c
+++ b/dlls/shell32/shellole.c
@@ -215,7 +215,7 @@
 	lpclf->rclsid = (CLSID*)rclsid;
 
 	TRACE("(%p)->()\n",lpclf);
-	shell32_ObjCount++;
+	InterlockedIncrement(&shell32_ObjCount);
 	return (LPCLASSFACTORY)lpclf;
 }
 /**************************************************************************
@@ -252,8 +252,8 @@
 	ICOM_THIS(IClassFactoryImpl,iface);
 	TRACE("(%p)->(count=%lu)\n",This,This->ref);
 
-	shell32_ObjCount++;
-	return ++(This->ref);
+	InterlockedIncrement(&shell32_ObjCount);
+	return InterlockedIncrement(&This->ref);
 }
 /******************************************************************************
  * IClassFactory_Release
@@ -263,11 +263,12 @@
 	ICOM_THIS(IClassFactoryImpl,iface);
 	TRACE("(%p)->(count=%lu)\n",This,This->ref);
 
-	shell32_ObjCount--;
-	if (!--(This->ref)) 
-	{ TRACE("-- destroying IClassFactory(%p)\n",This);
-		HeapFree(GetProcessHeap(),0,This);
-		return 0;
+	InterlockedDecrement(&shell32_ObjCount);
+	if (!InterlockedDecrement(&This->ref)) 
+	{
+	  TRACE("-- destroying IClassFactory(%p)\n",This);
+	  HeapFree(GetProcessHeap(),0,This);
+	  return 0;
 	}
 	return This->ref;
 }
@@ -355,7 +356,7 @@
     CLSID			*rclsid;
     LPFNCREATEINSTANCE		lpfnCI;
     const IID *			riidInst;
-    UINT *			pcRefDll; /* pointer to refcounter in external dll (ugrrr...) */
+    ULONG *			pcRefDll; /* pointer to refcounter in external dll (ugrrr...) */
 } IDefClFImpl;
 
 static ICOM_VTABLE(IClassFactory) dclfvt;
@@ -364,7 +365,7 @@
  *  IDefClF_fnConstructor
  */
 
-IClassFactory * IDefClF_fnConstructor(LPFNCREATEINSTANCE lpfnCI, UINT * pcRefDll, REFIID riidInst)
+IClassFactory * IDefClF_fnConstructor(LPFNCREATEINSTANCE lpfnCI, PLONG pcRefDll, REFIID riidInst)
 {
 	IDefClFImpl* lpclf;
 
@@ -374,13 +375,11 @@
 	lpclf->lpfnCI = lpfnCI;
 	lpclf->pcRefDll = pcRefDll;
 
-	if (pcRefDll) 
-	  (*pcRefDll)++;
-
+	if (pcRefDll) InterlockedIncrement(pcRefDll);
 	lpclf->riidInst = riidInst;
 
 	TRACE("(%p)\n\tIID:\t%s\n",lpclf, debugstr_guid(riidInst));
-	shell32_ObjCount++;
+	InterlockedIncrement(&shell32_ObjCount);
 	return (LPCLASSFACTORY)lpclf;
 }
 /**************************************************************************
@@ -418,9 +417,8 @@
 	ICOM_THIS(IDefClFImpl,iface);
 	TRACE("(%p)->(count=%lu)\n",This,This->ref);
 
-	shell32_ObjCount++;
-
-	return ++(This->ref);
+	InterlockedIncrement(&shell32_ObjCount);
+	return InterlockedIncrement(&This->ref);
 }
 /******************************************************************************
  * IDefClF_fnRelease
@@ -430,12 +428,11 @@
 	ICOM_THIS(IDefClFImpl,iface);
 	TRACE("(%p)->(count=%lu)\n",This,This->ref);
 
-	shell32_ObjCount--;
+	InterlockedDecrement(&shell32_ObjCount);
 
-	if (!--(This->ref)) 
+	if (!InterlockedDecrement(&This->ref)) 
 	{ 
-	  if (This->pcRefDll) 
-	    (*This->pcRefDll)--;
+	  if (This->pcRefDll) InterlockedDecrement(This->pcRefDll);
 
 	  TRACE("-- destroying IClassFactory(%p)\n",This);
 	  HeapFree(GetProcessHeap(),0,This);
@@ -495,7 +492,7 @@
 	REFIID	riid,				
 	LPVOID*	ppv,	
 	LPFNCREATEINSTANCE lpfnCI,	/* create instance callback entry */
-	UINT	*pcRefDll,		/* ref count of the dll */
+	PLONG	pcRefDll,		/* ref count of the dll */
 	REFIID	riidInst)		/* optional interface to the instance */
 {
 	TRACE("\n\tIID:\t%s %p %p %p \n\tIIDIns:\t%s\n",
@@ -514,3 +511,126 @@
 	return E_NOINTERFACE;
 }
 
+/*************************************************************************
+ *  DragAcceptFiles		[SHELL32.54]
+ */
+void WINAPI DragAcceptFiles(HWND hWnd, BOOL b)
+{
+	LONG exstyle;
+  
+	if( !IsWindow(hWnd) ) return;
+	exstyle = GetWindowLongA(hWnd,GWL_EXSTYLE);
+	if (b)
+	  exstyle |= WS_EX_ACCEPTFILES;
+	else
+	  exstyle &= ~WS_EX_ACCEPTFILES;
+	SetWindowLongA(hWnd,GWL_EXSTYLE,exstyle);
+}
+
+/*************************************************************************
+ * DragFinish		[SHELL32.80]
+ */
+void WINAPI DragFinish(HDROP h)
+{
+	TRACE("\n");
+	GlobalFree((HGLOBAL)h);
+}
+
+/*************************************************************************
+ * DragQueryPoint		[SHELL32.135]
+ */
+BOOL WINAPI DragQueryPoint(HDROP hDrop, POINT *p)
+{
+	LPDROPFILESTRUCT lpDropFileStruct;  
+	BOOL bRet;
+
+	TRACE("\n");
+
+	lpDropFileStruct = (LPDROPFILESTRUCT) GlobalLock(hDrop);
+  
+	memcpy(p,&lpDropFileStruct->ptMousePos,sizeof(POINT));
+	bRet = lpDropFileStruct->fInNonClientArea;
+  
+	GlobalUnlock(hDrop);
+	return bRet;
+}
+
+/*************************************************************************
+ *  DragQueryFileA		[SHELL32.81] [shell32.82]
+ */
+UINT WINAPI DragQueryFileA(
+	HDROP hDrop,
+	UINT lFile,
+	LPSTR lpszFile,
+	UINT lLength)
+{
+	LPSTR lpDrop;
+	UINT i = 0;
+	LPDROPFILESTRUCT lpDropFileStruct = (LPDROPFILESTRUCT) GlobalLock(hDrop); 
+    
+	TRACE("(%08x, %x, %p, %u)\n",	hDrop,lFile,lpszFile,lLength);
+    
+	if(!lpDropFileStruct) goto end;
+
+	lpDrop = (LPSTR) lpDropFileStruct + lpDropFileStruct->lSize;
+
+	while (i++ < lFile)
+	{
+	  while (*lpDrop++); /* skip filename */
+	  if (!*lpDrop) 
+	  {
+	    i = (lFile == 0xFFFFFFFF) ? i : 0; 
+	    goto end;
+	  }
+	}
+    
+	i = lstrlenA(lpDrop);
+	i++;
+	if (!lpszFile ) goto end;   /* needed buffer size */
+	i = (lLength > i) ? i : lLength;
+	lstrcpynA (lpszFile,  lpDrop,  i);
+end:
+	GlobalUnlock(hDrop);
+	return i;
+}
+
+/*************************************************************************
+ *  DragQueryFileW		[shell32.133]
+ */
+UINT WINAPI DragQueryFileW(
+	HDROP hDrop,
+	UINT lFile,
+	LPWSTR lpszwFile,
+	UINT lLength)
+{
+	LPWSTR lpwDrop;
+	UINT i = 0;
+	LPDROPFILESTRUCT lpDropFileStruct = (LPDROPFILESTRUCT) GlobalLock(hDrop); 
+    
+	TRACE("(%08x, %x, %p, %u)\n", hDrop,lFile,lpszwFile,lLength);
+    
+	if(!lpDropFileStruct) goto end;
+
+	lpwDrop = (LPWSTR) lpDropFileStruct + lpDropFileStruct->lSize;
+
+	i = 0;
+	while (i++ < lFile)
+	{
+	  while (*lpwDrop++); /* skip filename */
+	  if (!*lpwDrop) 
+	  {
+	    i = (lFile == 0xFFFFFFFF) ? i : 0; 
+	    goto end;
+	  }
+	}
+    
+	i = lstrlenW(lpwDrop);
+	i++;
+	if ( !lpszwFile) goto end;   /* needed buffer size */
+
+	i = (lLength > i) ? i : lLength;
+	lstrcpynW (lpszwFile, lpwDrop, i);
+end:
+	GlobalUnlock(hDrop);
+	return i;
+}