本文介绍了函数SHGetFileInfo()内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我想关闭一个进程时,我编写如下代码:

When I want to close a process, I write code as follow:

ASSERT(lpszExeName != NULL);
CString strExeName = lpszExeName;
int iPos = strExeName.ReverseFind(''\\'');
if (iPos != -1)
{
    strExeName = strExeName.Right(strExeName.GetLength() - iPos - 1);
}
HANDLE hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hSnapShot == INVALID_HANDLE_VALUE)
{
    return FALSE;
}
SHFILEINFO shSmall;
ZeroMemory(&shSmall, sizeof(shSmall));

PROCESSENTRY32 processInfo;
ZeroMemory(&processInfo, sizeof(processInfo));
processInfo.dwSize = sizeof(processInfo);
BOOL bStatus = Process32First(hSnapShot, &processInfo);
while (bStatus)
{
    SHGetFileInfo(processInfo.szExeFile, -1, &shSmall, sizeof(shSmall), SHGFI_ICON | SHGFI_SMALLICON);

    strExeName.MakeUpper();
    CString strProcessName = processInfo.szExeFile;
    strProcessName.MakeUpper();
    if (strProcessName == strExeName)
    {
        HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, processInfo.th32ProcessID);
        if (::TerminateProcess(hProcess, 1))
        {
            Sleep(500);
        }
    }
    //::DestroyIcon(shSmall.hIcon);
    bStatus = Process32Next(hSnapShot, &processInfo);
}
CloseHandle(hSnapShot);
return TRUE;



但是内存泄漏,请帮帮我!谢谢!



But memory leaks, Please help me! Thank you!

推荐答案


这篇关于函数SHGetFileInfo()内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 23:03