Commit in reactos/lib/psapi/misc on MAIN
stubs.c+1-311.8 -> 1.9
win32.c+116-11.12 -> 1.13
+117-32
2 modified files
implemented GetProcessImageFileNameA/W()

reactos/lib/psapi/misc
stubs.c 1.8 -> 1.9
diff -u -r1.8 -r1.9
--- stubs.c	5 Nov 2004 22:36:36 -0000	1.8
+++ stubs.c	5 Nov 2004 23:53:06 -0000	1.9
@@ -1,4 +1,4 @@
-/* $Id: stubs.c,v 1.8 2004/11/05 22:36:36 weiden Exp $ */
+/* $Id: stubs.c,v 1.9 2004/11/05 23:53:06 weiden Exp $ */
 #include "precomp.h"
 
 #define NDEBUG
@@ -75,34 +75,4 @@
   return FALSE;
 }
 
-
-/*
- * @unimplemented
- */
-DWORD
-STDCALL
-GetProcessImageFileNameW(HANDLE hProcess,
-                         LPWSTR lpImageFileName,
-                         DWORD nSize)
-{
-  DPRINT1("PSAPI: GetProcessImageFileNameW is UNIMPLEMENTED!\n");
-  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
-  return 0;
-}
-
-
-/*
- * @unimplemented
- */
-DWORD
-STDCALL
-GetProcessImageFileNameA(HANDLE hProcess,
-                         LPSTR lpImageFileName,
-                         DWORD nSize)
-{
-  DPRINT1("PSAPI: GetProcessImageFileNameA is UNIMPLEMENTED!\n");
-  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
-  return 0;
-}
-
 /* EOF */

reactos/lib/psapi/misc
win32.c 1.12 -> 1.13
diff -u -r1.12 -r1.13
--- win32.c	3 Nov 2004 22:43:00 -0000	1.12
+++ win32.c	5 Nov 2004 23:53:06 -0000	1.13
@@ -1,4 +1,4 @@
-/* $Id: win32.c,v 1.12 2004/11/03 22:43:00 weiden Exp $
+/* $Id: win32.c,v 1.13 2004/11/05 23:53:06 weiden Exp $
  */
 /*
  * COPYRIGHT:   See COPYING in the top level directory
@@ -924,5 +924,120 @@
   return TRUE;
 }
 
+
+/*
+ * @implemented
+ */
+DWORD
+STDCALL
+GetProcessImageFileNameW(HANDLE hProcess,
+                         LPWSTR lpImageFileName,
+                         DWORD nSize)
+{
+  PUNICODE_STRING ImageFileName;
+  ULONG BufferSize;
+  NTSTATUS Status;
+
+  BufferSize = sizeof(UNICODE_STRING) + (nSize * sizeof(WCHAR));
+
+  ImageFileName = (PUNICODE_STRING)LocalAlloc(LMEM_FIXED, BufferSize);
+  if(ImageFileName != NULL)
+  {
+    DWORD Ret;
+    Status = NtQueryInformationProcess(hProcess,
+                                       ProcessImageFileName,
+                                       ImageFileName,
+                                       BufferSize,
+                                       NULL);
+    if(NT_SUCCESS(Status))
+    {
+      memcpy(lpImageFileName, ImageFileName->Buffer, ImageFileName->Length);
+
+      /* make sure the string is null-terminated! */
+      lpImageFileName[ImageFileName->Length / sizeof(WCHAR)] = L'\0';
+      Ret = ImageFileName->Length / sizeof(WCHAR);
+    }
+    else
+    {
+      if(Status == STATUS_INFO_LENGTH_MISMATCH)
+      {
+        /* XP sets this error code for some reason if the buffer is too small */
+        SetLastError(ERROR_INSUFFICIENT_BUFFER);
+      }
+      else
+      {
+        SetLastErrorByStatus(Status);
+      }
+      Ret = 0;
+    }
+
+    LocalFree((HLOCAL)ImageFileName);
+    return Ret;
+  }
+
+  return 0;
+}
+
+
+/*
+ * @implemented
+ */
+DWORD
+STDCALL
+GetProcessImageFileNameA(HANDLE hProcess,
+                         LPSTR lpImageFileName,
+                         DWORD nSize)
+{
+  PUNICODE_STRING ImageFileName;
+  ULONG BufferSize;
+  NTSTATUS Status;
+
+  BufferSize = sizeof(UNICODE_STRING) + (nSize * sizeof(WCHAR));
+
+  ImageFileName = (PUNICODE_STRING)LocalAlloc(LMEM_FIXED, BufferSize);
+  if(ImageFileName != NULL)
+  {
+    DWORD Ret;
+    Status = NtQueryInformationProcess(hProcess,
+                                       ProcessImageFileName,
+                                       ImageFileName,
+                                       BufferSize,
+                                       NULL);
+    if(NT_SUCCESS(Status))
+    {
+      WideCharToMultiByte(CP_ACP,
+                          0,
+                          ImageFileName->Buffer,
+                          ImageFileName->Length / sizeof(WCHAR),
+                          lpImageFileName,
+                          nSize,
+                          NULL,
+                          NULL);
+
+      /* make sure the string is null-terminated! */
+      lpImageFileName[ImageFileName->Length / sizeof(WCHAR)] = '\0';
+      Ret = ImageFileName->Length / sizeof(WCHAR);
+    }
+    else
+    {
+      if(Status == STATUS_INFO_LENGTH_MISMATCH)
+      {
+        /* XP sets this error code for some reason if the buffer is too small */
+        SetLastError(ERROR_INSUFFICIENT_BUFFER);
+      }
+      else
+      {
+        SetLastErrorByStatus(Status);
+      }
+      Ret = 0;
+    }
+
+    LocalFree((HLOCAL)ImageFileName);
+    return Ret;
+  }
+
+  return 0;
+}
+
 /* EOF */
 
CVSspam 0.2.8