Jump to content


This is a ready-only archive of the InstallSite Forum. You cannot post any new content here. / Dies ist ein Archiv des InstallSite Forums. Hier können keine neuen Beiträge veröffentlicht werden.
Photo

Array mit LONG  z.b. ProcessIDs[ 512 ] unter IS 6.3


2 replies to this topic

trutmrol

trutmrol
  • Members
  • 94 posts

Posted 26 October 2001 - 06:47

Hallo,

ich habe das Beispielprog. ShutDownApp von
install.org heruntergeladen und bin nun daran
es unter IS 6.3 zum laufen zu bringen.

Problem:
Dort wir ein Array mit LONG verwendet und diese
Dekleration 'LONG ProcessIDs[512];' geht unter
IS 6.3 nicht!

Frage:
Was hat sich geaendert?

Besten Dank fuer die Hinweise.


Lucky

Lucky
  • Members
  • 119 posts

Posted 29 October 2001 - 15:57

Ich glaube, die Syntax für Arrays sieht runde Klammern vor. Eckige Klammern nimmt man für Strings mit vorgegebener Länge.

jo21w

jo21w
  • Members
  • 5 posts

Posted 12 March 2003 - 18:02

Dieses Beispielprogramm hat bei mir auch nicht funktioniert.

Habe dann folgenden Code geschrieben:
.h Datei
#ifndef _ENUMPROGS_H_
#define _ENUMPROGS_H_

#define TH32CS_SNAPPROCESS   0x00000002

typedef PROCESSENTRY32
begin  
  NUMBER dwSize;
  NUMBER cntUsage;
  NUMBER th32ProcessID;
  NUMBER th32DefaultHeapID;
  NUMBER th32ModuleID;
  NUMBER cntThreads;
  NUMBER th32ParentProcessID;
  NUMBER pcPriClassBase;
  NUMBER dwFlags;
  STRING szexeFile[MAX_PATH];
end;


#define PSAPI_FILE        "psapi.dll"  // Windows NT process DLL
#define PROCESSID_LENGTH  4            // 4 bytes (DWORD) for a process ID

// Process information constants.

#define PROCESS_QUERY_INFORMATION  0x400
#define PROCESS_ALL_ACCESS         0x1f0fff
#define PROCESS_VM_READ            0x10

prototype NUMBER Kernel32.CreateToolhelp32Snapshot(BYVAL NUMBER,NUMBER);
prototype NUMBER Kernel32.Process32First(BYVAL NUMBER,POINTER);
prototype NUMBER Kernel32.Process32Next(BYVAL NUMBER,POINTER);

prototype NUMBER PSAPI.EnumProcesses(POINTER, NUMBER, BYREF NUMBER);
prototype NUMBER PSAPI.EnumProcessModules(NUMBER, POINTER, NUMBER,BYREF NUMBER);
prototype NUMBER PSAPI.GetModuleFileNameExA(NUMBER, NUMBER, BYREF STRING,NUMBER);
prototype NUMBER Kernel32.OpenProcess(NUMBER, BOOL, NUMBER);
prototype LONG Kernel32.GlobalAlloc(LONG,LONG);
prototype LONG Kernel32.GlobalFree(LONG);
prototype BOOL Kernel32.CloseHandle(LONG);
prototype Kernel32.Sleep(LONG);








.rul Datei
prototype GetProcessList9x(BYREF LIST);
function GetProcessList9x(ProcessList)
  PROCESSENTRY32 uProcess;
  NUMBER rProcessFound;
  NUMBER hSnapshot;
  STRING szExename;
  NUMBER exitCode;
  NUMBER myProcess;
  BOOL AppKill;
  NUMBER appCount;
  NUMBER i;
  NUMBER nMem;
begin  
  appCount = 0;  
  uProcess.dwSize = (9*4)+(MAX_PATH*2);
  hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
  rProcessFound = Process32First(hSnapshot, &uProcess);
  while rProcessFound
     szExename = uProcess.szexeFile;
     ListAddString(ProcessList,szExename,AFTER);
     rProcessFound = Process32Next(hSnapshot, &uProcess);
  endwhile;
  Kernel32.CloseHandle(hSnapshot);
end;

prototype GetProcessListNT(BYREF LIST);
function GetProcessListNT(ProcessList)
LONG cb;
LONG cbNeeded;
LONG nProcesses;
LONG nModules;
LONG hProcess;
STRING ModuleName;
NUMBER ModuleHandle;
POINTER ptrProcessIDs;
POINTER ptrModuleIDs;
POINTER ptrHelper;
INT i;
begin
  if UseDLL(WINSYSDIR ^ PSAPI_FILE) < 0 then
// Could not load psapi.dll.
MessageBox("ERROR: Could not load [" + WINSYSDIR ^ PSAPI_FILE +
"].", SEVERE);
return FALSE;
endif;
 cb=8;
 cbNeeded=96;
 ptrProcessIDs = GlobalAlloc(64,2048);
 ptrModuleIDs = GlobalAlloc(64,10000);
 
 while cb <= cbNeeded;
    cb = cb * 2;
    EnumProcesses(ptrProcessIDs,cb,cbNeeded);
 endwhile;
 nProcesses = (cbNeeded / 4);
 ptrHelper=ptrProcessIDs;
 for i = 0 to (nProcesses-1)
    ModuleHandle = 200;
    ModuleHandle = *ptrHelper;
    ptrHelper=ptrHelper+4;
 
  hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, 0,ModuleHandle );
  if hProcess != 0 then
       cb = 8;
       cbNeeded = 96;
       while cb <= cbNeeded
          cb = cb*2;
          EnumProcessModules(hProcess, ptrModuleIDs, cb, cbNeeded);
       endwhile;
       nModules = cbNeeded / 4;
       if nModules > 0 then
          cb = *ptrModuleIDs;
          GetModuleFileNameExA(hProcess, cb, ModuleName, MAX_PATH);
          ParsePath(ModuleName,ModuleName,FILENAME);
          ListAddString(ProcessList,ModuleName,AFTER);
       endif;  
       Kernel32.CloseHandle(hProcess);  
    endif;
 endfor;
 GlobalFree(ptrModuleIDs);
 GlobalFree(ptrProcessIDs);
 if UnUseDLL(PSAPI_FILE) < 0 then
MessageBox("ERROR: Could not unload [" + WINSYSDIR ^ PSAPI_FILE +
"].", SEVERE);
return FALSE;
endif;
 
end;

prototype GetProcessList(BYREF LIST);
function GetProcessList(ProcessList)
begin
   if(SYSINFO.WINNT.bWinNT4) then
   //  if(SYSINFO.WINNT) then
      GetProcessListNT(ProcessList);
   else
      GetProcessList9x(ProcessList);
   endif;
end;