[NTOS][NDK][RTL] A bunch of 'wrong size' fixes
[reactos.git] / dll / win32 / kernel32 / client / loader.c
index 4f33ff7..82f8c7d 100644 (file)
@@ -73,7 +73,7 @@ BasepMapModuleHandle(HMODULE hModule, BOOLEAN AsDataFile)
     if (LDR_IS_DATAFILE(hModule) && !AsDataFile)
         return NULL;
 
-    /* It'a a normal DLL, just return its handle */
+    /* It's a normal DLL, just return its handle */
     return hModule;
 }
 
@@ -177,7 +177,7 @@ DECLSPEC_HOTPATCH
 LoadLibraryW(LPCWSTR lpLibFileName)
 {
     /* Call Ex version of the API */
-    return LoadLibraryExW (lpLibFileName, 0, 0);
+    return LoadLibraryExW(lpLibFileName, 0, 0);
 }
 
 
@@ -381,6 +381,7 @@ done:
     /* Set last error in failure case */
     if (!NT_SUCCESS(Status))
     {
+        DPRINT1("LoadLibraryExW(%ls) failing with status %lx\n", lpLibFileName, Status);
         BaseSetLastNTError(Status);
         return NULL;
     }
@@ -431,7 +432,7 @@ GetProcAddress(HMODULE hModule, LPCSTR lpProcName)
     }
 
     /* Check for a special case when returned pointer is
-       the same as iamge's base address */
+       the same as image's base address */
     if (fnExp == hMapped)
     {
         /* Set correct error code */
@@ -568,7 +569,7 @@ GetModuleFileNameA(HINSTANCE hModule,
         Status = BasepUnicodeStringTo8BitString(&FilenameA, &FilenameW, TRUE);
         if (!NT_SUCCESS(Status))
         {
-            /* Set last error, free string and retun failure */
+            /* Set last error, free string and return failure */
             BaseSetLastNTError(Status);
             RtlFreeUnicodeString(&FilenameW);
             return 0;
@@ -609,7 +610,7 @@ GetModuleFileNameW(HINSTANCE hModule,
     PLIST_ENTRY ModuleListHead, Entry;
     PLDR_DATA_TABLE_ENTRY Module;
     ULONG Length = 0;
-    ULONG Cookie;
+    ULONG_PTR Cookie;
     PPEB Peb;
 
     hModule = BasepMapModuleHandle(hModule, FALSE);
@@ -720,9 +721,9 @@ BOOLEAN
 WINAPI
 BasepGetModuleHandleExW(BOOLEAN NoLock, DWORD dwPublicFlags, LPCWSTR lpwModuleName, HMODULE *phModule)
 {
-    DWORD Cookie;
+    ULONG_PTR Cookie;
     NTSTATUS Status = STATUS_SUCCESS, Status2;
-    HANDLE hModule = 0;
+    HANDLE hModule = NULL;
     UNICODE_STRING ModuleNameU;
     DWORD dwValid;
     BOOLEAN Redirected = FALSE; // FIXME
@@ -739,7 +740,7 @@ BasepGetModuleHandleExW(BOOLEAN NoLock, DWORD dwPublicFlags, LPCWSTR lpwModuleNa
         {
             /* Fail */
             BaseSetLastNTError(Status);
-            if (phModule) *phModule = 0;
+            if (phModule) *phModule = NULL;
             return NT_SUCCESS(Status);
         }
     }
@@ -789,11 +790,11 @@ BasepGetModuleHandleExW(BOOLEAN NoLock, DWORD dwPublicFlags, LPCWSTR lpwModuleNa
                               hModule);
     }
 
+quickie:
     /* Set last error in case of failure */
     if (!NT_SUCCESS(Status))
         BaseSetLastNTError(Status);
 
-quickie:
     /* Unlock loader lock if it was acquired */
     if (!NoLock)
     {
@@ -843,20 +844,20 @@ WINAPI
 GetModuleHandleW(LPCWSTR lpModuleName)
 {
     HMODULE hModule;
-    NTSTATUS Status;
+    BOOLEAN Success;
 
     /* If current module is requested - return it right away */
     if (!lpModuleName)
         return ((HMODULE)NtCurrentPeb()->ImageBaseAddress);
 
     /* Use common helper routine */
-    Status = BasepGetModuleHandleExW(TRUE,
-                                     GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
-                                     lpModuleName,
-                                     &hModule);
+    Success = BasepGetModuleHandleExW(TRUE,
+                                      GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
+                                      lpModuleName,
+                                      &hModule);
 
-    /* If it wasn't successful - return 0 */
-    if (!NT_SUCCESS(Status)) hModule = 0;
+    /* If it wasn't successful - return NULL */
+    if (!Success) hModule = NULL;
 
     /* Return the handle */
     return hModule;
@@ -872,9 +873,8 @@ GetModuleHandleExW(IN DWORD dwFlags,
                    IN LPCWSTR lpwModuleName  OPTIONAL,
                    OUT HMODULE* phModule)
 {
-    NTSTATUS Status;
     DWORD dwValid;
-    BOOL Ret = FALSE;
+    BOOL Ret;
 
     /* Validate parameters */
     dwValid = BasepGetModuleHandleExParameterValidation(dwFlags, lpwModuleName, phModule);
@@ -886,13 +886,10 @@ GetModuleHandleExW(IN DWORD dwFlags,
     if (dwValid == BASEP_GET_MODULE_HANDLE_EX_PARAMETER_VALIDATION_SUCCESS) return TRUE;
 
     /* Use common helper routine */
-    Status = BasepGetModuleHandleExW(FALSE,
-                                     dwFlags,
-                                     lpwModuleName,
-                                     phModule);
-
-    /* Return TRUE in case of success */
-    if (NT_SUCCESS(Status)) Ret = TRUE;
+    Ret = BasepGetModuleHandleExW(FALSE,
+                                  dwFlags,
+                                  lpwModuleName,
+                                  phModule);
 
     return Ret;
 }
@@ -908,8 +905,7 @@ GetModuleHandleExA(IN DWORD dwFlags,
 {
     PUNICODE_STRING lpModuleNameW;
     DWORD dwValid;
-    BOOL Ret = FALSE;
-    NTSTATUS Status;
+    BOOL Ret;
 
     /* Validate parameters */
     dwValid = BasepGetModuleHandleExParameterValidation(dwFlags, (LPCWSTR)lpModuleName, phModule);
@@ -924,10 +920,10 @@ GetModuleHandleExA(IN DWORD dwFlags,
     if (dwFlags & GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS)
     {
         /* Call the extended version of the API without conversion */
-        Status = BasepGetModuleHandleExW(FALSE,
-                                         dwFlags,
-                                         (LPCWSTR)lpModuleName,
-                                         phModule);
+        Ret = BasepGetModuleHandleExW(FALSE,
+                                      dwFlags,
+                                      (LPCWSTR)lpModuleName,
+                                      phModule);
     }
     else
     {
@@ -938,16 +934,12 @@ GetModuleHandleExA(IN DWORD dwFlags,
         if (!lpModuleNameW) return FALSE;
 
         /* Call the extended version of the API */
-        Status = BasepGetModuleHandleExW(FALSE,
-                                         dwFlags,
-                                         lpModuleNameW->Buffer,
-                                         phModule);
+        Ret = BasepGetModuleHandleExW(FALSE,
+                                      dwFlags,
+                                      lpModuleNameW->Buffer,
+                                      phModule);
     }
 
-    /* If result was successful - return true */
-    if (NT_SUCCESS(Status))
-        Ret = TRUE;
-
     /* Return result */
     return Ret;
 }