Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Error Code 87

Error Code 87

Scheduled Pinned Locked Moved C / C++ / MFC
helpcsharpc++algorithms
4 Posts 3 Posters 5 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Saksida Bojan
    wrote on last edited by
    #1

    Hello. I Know this isnt quite right forum to ask. The App is C#, however i am using Native WinAPI. I am trying to list all process, and get full path. PROCESSENTRY32 in 95/98 used full path for exe. But not on newer system. MODULEENTRY32 Have szExePath. I wanted to use this to get full path. I Used CreateToolhelp32Snapshot method to emurate process. (The only method that gave me good results). But to use Module32First() i need to open process, but i get error 87. On MSDN i found it is ERROR_INVALID_PARAMETER. Is there a whay to fix this problem, or a diffrent method of getting full path. And no, no searching files through HDD.(I am intrested in the first solution) Thanks in advance.

    int hWnd = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0);
    PROCESSENTRY32 pe = new PROCESSENTRY32();
    pe.dwSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(PROCESSENTRY32));

    int first = Process32First(hWnd, ref pe);
    int error = GetLastError();
    if (first == 0)
    throw new ProcessListException("Can not get process list");

    do
    {
    ProcessInfo pi = new ProcessInfo();
    pi.iProcessID = (int)pe.th32ProcessID;
    pi.sFileName = pe.szExeFile;
    SetLastError(0); // To Reset any Error Codes
    int handle = OpenProcess(PROCESS_ALL_ACCESS, true, pi.iProcessID);
    // 87 = GetLastError();
    MODULEENTRY32 me = new MODULEENTRY32();
    me.dwSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(MODULEENTRY32));
    bool t = Module32First(handle, ref me);
    } while (Process32Next(hWnd, ref pe) != 0);
    CloseHandle(hWnd);

    Edit: Styling

    L M 2 Replies Last reply
    0
    • S Saksida Bojan

      Hello. I Know this isnt quite right forum to ask. The App is C#, however i am using Native WinAPI. I am trying to list all process, and get full path. PROCESSENTRY32 in 95/98 used full path for exe. But not on newer system. MODULEENTRY32 Have szExePath. I wanted to use this to get full path. I Used CreateToolhelp32Snapshot method to emurate process. (The only method that gave me good results). But to use Module32First() i need to open process, but i get error 87. On MSDN i found it is ERROR_INVALID_PARAMETER. Is there a whay to fix this problem, or a diffrent method of getting full path. And no, no searching files through HDD.(I am intrested in the first solution) Thanks in advance.

      int hWnd = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0);
      PROCESSENTRY32 pe = new PROCESSENTRY32();
      pe.dwSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(PROCESSENTRY32));

      int first = Process32First(hWnd, ref pe);
      int error = GetLastError();
      if (first == 0)
      throw new ProcessListException("Can not get process list");

      do
      {
      ProcessInfo pi = new ProcessInfo();
      pi.iProcessID = (int)pe.th32ProcessID;
      pi.sFileName = pe.szExeFile;
      SetLastError(0); // To Reset any Error Codes
      int handle = OpenProcess(PROCESS_ALL_ACCESS, true, pi.iProcessID);
      // 87 = GetLastError();
      MODULEENTRY32 me = new MODULEENTRY32();
      me.dwSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(MODULEENTRY32));
      bool t = Module32First(handle, ref me);
      } while (Process32Next(hWnd, ref pe) != 0);
      CloseHandle(hWnd);

      Edit: Styling

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Hi, I'm no interopability expert, but error 87 means "INVALID_PARAMETER". I wonder if the C# Bool in

      OpenProcess(PROCESS_ALL_ACCESS, true, pi.iProcessID);

      translates to a Microsoft C TRUE which is a preprocessor define on 1. Maybe you should try this instead

      OpenProcess(PROCESS_ALL_ACCESS, 1, pi.iProcessID);

      So long, Stefan

      1 Reply Last reply
      0
      • S Saksida Bojan

        Hello. I Know this isnt quite right forum to ask. The App is C#, however i am using Native WinAPI. I am trying to list all process, and get full path. PROCESSENTRY32 in 95/98 used full path for exe. But not on newer system. MODULEENTRY32 Have szExePath. I wanted to use this to get full path. I Used CreateToolhelp32Snapshot method to emurate process. (The only method that gave me good results). But to use Module32First() i need to open process, but i get error 87. On MSDN i found it is ERROR_INVALID_PARAMETER. Is there a whay to fix this problem, or a diffrent method of getting full path. And no, no searching files through HDD.(I am intrested in the first solution) Thanks in advance.

        int hWnd = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0);
        PROCESSENTRY32 pe = new PROCESSENTRY32();
        pe.dwSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(PROCESSENTRY32));

        int first = Process32First(hWnd, ref pe);
        int error = GetLastError();
        if (first == 0)
        throw new ProcessListException("Can not get process list");

        do
        {
        ProcessInfo pi = new ProcessInfo();
        pi.iProcessID = (int)pe.th32ProcessID;
        pi.sFileName = pe.szExeFile;
        SetLastError(0); // To Reset any Error Codes
        int handle = OpenProcess(PROCESS_ALL_ACCESS, true, pi.iProcessID);
        // 87 = GetLastError();
        MODULEENTRY32 me = new MODULEENTRY32();
        me.dwSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(MODULEENTRY32));
        bool t = Module32First(handle, ref me);
        } while (Process32Next(hWnd, ref pe) != 0);
        CloseHandle(hWnd);

        Edit: Styling

        M Offline
        M Offline
        Mark Salsbery
        wrote on last edited by
        #3

        In addition to Stefan's reply... First, you shouldn't be calling GetLastError() unless a return value indicates an error actually occurred. If no error occurred, the return value of GetLastError() is undefined in many cases. SetLastError() may have no effect if you're calling a Windows API right after you use it. You have no idea how many times the error code for the thread may change during that one API call. Second, what do your marshaled structs look like? Are you marshaling them properly? Third, you should be using IntPtr types for handles instead of int. Mark

        S 1 Reply Last reply
        0
        • M Mark Salsbery

          In addition to Stefan's reply... First, you shouldn't be calling GetLastError() unless a return value indicates an error actually occurred. If no error occurred, the return value of GetLastError() is undefined in many cases. SetLastError() may have no effect if you're calling a Windows API right after you use it. You have no idea how many times the error code for the thread may change during that one API call. Second, what do your marshaled structs look like? Are you marshaling them properly? Third, you should be using IntPtr types for handles instead of int. Mark

          S Offline
          S Offline
          Saksida Bojan
          wrote on last edited by
          #4

          Mark Salsbery wrote:

          First, you shouldn't be calling GetLastError() unless a return value indicates an error actually occurred. If no error occurred, the return value of GetLastError() is undefined in many cases. SetLastError() may have no effect if you're calling a Windows API right after you use it. You have no idea how many times the error code for the thread may change during that one API call.

          I Used SetlastError(0) to clear error from before. It was error 1008. And i called it after OpenProcess, i got error 87. Yust to make sure where it fails. And in a loop, the OpenProcess Failed all the time.

          Mark Salsbery wrote:

          Second, what do your marshaled structs look like? Are you marshaling them properly?

          I didnt use it properly.

          Mark Salsbery wrote:

          Third, you should be using IntPtr types for handles instead of int.

          Changed it. And now it works. Thank you

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups