Question

I want to read multiple DWORDS and concatenate them into an array of type TCHAR. How can I do that?

At the end, array should look like a list sepparated through endline characters.

TCHAR array[MAX_PATH];

while(reading dwords)
{
lstrcat(array, dword to be concatenated);
lstrcat(array, L"\n");}

Added my code after people asking me to. I am trying to get the ID's in the same manner I get the names.

void getProcessList()
{//snapshot la toate procesele din sistem
    HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
    PROCESSENTRY32 proc32;

    TCHAR names[MAX_PATH]; //wchar_t pentru ca folosim Unicode
    char* pids=new char[200];


    if(hSnap == INVALID_HANDLE_VALUE)
    {
        cout<<"invalid handle value error!\n";
        return;
    }

    //setez dimensiunea structurii
    proc32.dwSize = sizeof(PROCESSENTRY32);

    //get info despre primul proces(se va afisa in do...while)
    if(!Process32First(hSnap, &proc32))
    {
        cout<<"Tread32First() error!\n";
        CloseHandle(hSnap);
        return ;
    }
    wcscpy(names, L"");
    //cauta in restul proceselor
    //daca nr. threaduri<3, introdu in fisierul mapat
    do
    {
        if(proc32.cntThreads < 3)
        {   
            //cout<<"Current process id(adica programul A): "<<GetCurrentProcessId()<<"\n";
            wcout<<L"Process Name: "<<proc32.szExeFile<<"\n";
            cout<<"Process ID: "  <<proc32.th32ProcessID<<"\n";
            cout<<"Thread Count: "<<proc32.cntThreads<<"\n"<<endl;

            //exclud procesul curent, nu vreau sa-l termin
            //includ celelalte procese in string, separate de newline
            if(GetCurrentProcessId()!=proc32.th32ProcessID)
            {  // sprintf(pids,"%d",proc32.th32ProcessID);
                lstrcat(names, proc32.szExeFile);
                lstrcat(names, L"\n");
            }

        }       
    }while(Process32Next(hSnap, &proc32));

    //afisez
    wcout<<names;
    //printf("asd: %d",pids);
    //scriu in fisierul mapat
    writeToFileMap(names);

    //inchid handle la snapshot
    CloseHandle(hSnap);
}
Was it helpful?

Solution

If you want to do it all with win32, use StringCchPrintf:

HRESULT hr = StringCchPrintf(names, ARRAYSIZE(names), L"%ld", proc32.th32ProcessID);
if (FAILED(hr)) {
    // Handle error...
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top