DWORD数组

时间:2014-03-18 13:55:09

标签: c++ winapi dword

我想读取多个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);
}

1 个答案:

答案 0 :(得分:0)

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

HRESULT hr = StringCchPrintf(names, ARRAYSIZE(names), L"%ld", proc32.th32ProcessID);
if (FAILED(hr)) {
    // Handle error...
}