Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9170621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:02:58+00:00 2026-06-17T16:02:58+00:00

GetLastError tells me I’m getting the The program issued a command but the command

  • 0

GetLastError tells me I’m getting the “The program issued a command but the command length is incorrect.” error when calling Process32First() (see code below). I found one post that looked helpful (http://social.msdn.microsoft.com/Forums/is/vcgeneral/thread/6f43716f-fdd3-4c92-bfba-6a23178c32bf), but I’m not sure if this is my problem.

I’ve tried building a program that includes only "stdafx.h", <iostream>, <Windows.h> and <TlHelp32.h> to test __alignof(PROCESSENTRY32), but I still get a value of 4. Not sure if that’s correct or not.

Here is the code that’s failing:

HANDLE hProcess;
PROCESSENTRY32 pe32;

cout << "Size of PROCESSENTRY32 is: " << sizeof(PROCESSENTRY32) << "\r\n"; // 556
cout << "Align of PROCESSENTRY32 is: " << __alignof(PROCESSENTRY32) << "\r\n"; // 4

if ( !(hProcess = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)) ) {
    cout << "CreateToolhelp32Snapshot() failed: " << GetLastError() << "\r\n";
    return (HANDLE)NULL;
} else {
    cout << "CreateToolhelp32Snapshot() succeeded.\r\n";
}

if (Process32First(hProcess, &pe32)) {
    do {
        cout << pe32.th32ModuleID;
    } while (Process32Next(hProcess, &pe32));
} else {
    cout << "Process32First() failed: " << GetLastError() << "\r\n";
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T16:02:59+00:00Added an answer on June 17, 2026 at 4:02 pm

    From the docs on Process32First:

    The calling application must set the dwSize member of PROCESSENTRY32 to the size, in bytes, of the structure.

    I don’t see you doing that in your code, and I suspect it’s the problem. Fix it:

    pe32.dwSize = sizeof pe32;
    if (Process32First(...))
    

    The reasoning behind this mandatory action for many of the winapi structures is for the flexibility to add more onto the structure later on, but let functions know which version is being used by checking against known sizes of previous versions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following code: Tools::Logger.Log(string(GetLastError()), Error); GetLastError() returns a DWORD a numeric value, but
How can the return error code be specified on application exit? If this were
I am getting waring Warning: Window creation failed: GetLastError returns 0x00000579 when using below
i have the below code and find that the text value represented in Server.GetLastError
In my application the function CreateWindow is failing for some reason. GetLastError indicates error
In the Application_Error event, I get the last error via: Exception lastError = Context.Server.GetLastError();
I would like to use a generic error msg handler so I can GetLastError
Simple code: ATOM atom = GlobalAddAtom(LTestCpp1); It returns 0 and GetLastError returns 0x5 (Access
I want to retrieve error strings for DirectX 9, but I can find on
I have code(It is found in the Internet) to handle application error. I wrote

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.