0

我想读取多个 DWORDS 并将它们连接成一个 TCHAR 类型的数组。我怎样才能做到这一点?

最后,数组应该看起来像一个由结束字符分隔的列表。

TCHAR array[MAX_PATH];

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

在人们要求我之后添加了我的代码。我正在尝试以与获取名称相同的方式获取 ID。

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);
}
4

1 回答 1

0

如果您想使用 win32 完成所有操作,请使用StringCchPrintf

HRESULT hr = StringCchPrintf(names, ARRAYSIZE(names), L"%ld", proc32.th32ProcessID);
if (FAILED(hr)) {
    // Handle error...
}
于 2014-03-18T14:11:07.677 回答