Here's what I have:
void function() {
struct APROCS
{
DWORD PID;
TCHAR processname[256];
};
static struct APROCS *aProcesses;
aProcesses = (APROCS *) calloc(8192, sizeof(APROCS));
//do work...
[get PIDs and process names]
if ((aProcesses[i].PID > 4) && (_tcslen(aProcesses[i].processname) > 0
//do more work...
free(aProcesses);aProcesses=NULL;
}
I'm looking to eliminate all bad code, and while this code works, it's probably not the correct way to do it. I basically setup an array of aProcesses[8192]. I want to use a class:
// CProcesses.h
class CProcesses
{
public:
DWORD PID;
TCHAR processname[256];
CProcesses(void);
~CProcesses(void);
};
and
// CProcesses.cpp
#include <Windows.h>
#include "CProcesses.h"
CProcesses::CProcesses(void)
{
}
CProcesses::~CProcesses(void)
{
}
Do I do this to allocate an array from the class?
void function() {
CProcesses *aProcesses[8192];
//do work...
[get PIDs and process names]
if ((aProcesses[i].PID > 4) && (_tcslen(aProcesses[i].processname) > 0
//do more work...
}
structand aclassis the default visibility? Forstructall fields are by defaultpublicwhile in aclassthey areprivate. That's it.std::vectorinstead. And instead of character arrays, usestd::string. And a last hint, try to avoid pointers as much as you can.