代码:http://www.applevb.com/sourcecode/moudle.zip
可以获得系统中内存中的DLL
www.applevb.com

解决方案 »

  1.   


    #include <vcl.h>
    #pragma hdrstop
    #include "ListUnit1.h"
    //---------------------------------------------------------------------------
    #pragma package(smart_init)
    #pragma resource "*.dfm"
    TForm1 *Form1;
    //---------------------------------------------------------------------------
    __fastcall TForm1::TForm1(TComponent* Owner)
            : TForm(Owner)
    {
    }
    //---------------------------------------------------------------------------
    #include <tlHelp32.h>
    int  ProcessID[1024];  // 存放进程标识号
    void __fastcall TForm1::Button1Click(TObject *Sender)
    {     // 显示进程列表
          HANDLE   ProcessListHandle=
              CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
              // 产生进程列表句柄
          ListBox1->Items->Clear();
          int i=0;      PROCESSENTRY32  ProcessStruct;
          ProcessStruct.dwSize=sizeof(ProcessStruct);
          int yn=Process32First(ProcessListHandle,
                                 &ProcessStruct);
          while (yn!=0)
             {
                 ProcessID[i++]=ProcessStruct.th32ProcessID;
                 ListBox1->Items->Add(ProcessStruct.szExeFile);
                 yn=Process32Next(ProcessListHandle,&ProcessStruct);
             }
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::Button2Click(TObject *Sender)
    {    // 强行中止进程
         int i=ListBox1->ItemIndex;
         if (i!=-1)
            {
               int pID=ProcessID[i];
               HANDLE h=OpenProcess(PROCESS_ALL_ACCESS,true,pID);
               DWORD ExitCode;
               GetExitCodeProcess(h,&ExitCode); // 取中止码
               TerminateProcess(h,ExitCode);    // 强行中止
               Sleep(100);                      // 延时100ms
               Button1->Click();                // 重新列表
            }
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::FormCreate(TObject *Sender)
    {
         Button1->Click();
    }
    int  ModuleID[1024];  // 存放DLL标识号
    void __fastcall TForm1::Button3Click(TObject *Sender)
    {    // 显示某进程的所有DLL名
         int i=ListBox1->ItemIndex;
         if (i!=-1)
            {
               int pID=ProcessID[i];  // 列这个进程的DLL名
               HANDLE   ModuleListHandle=
                        CreateToolhelp32Snapshot(TH32CS_SNAPMODULE,pID);
               ListBox2->Items->Clear();
               int j=0;
               MODULEENTRY32  ModuleStruct;
               ModuleStruct.dwSize=sizeof(ModuleStruct);
               int yn=Module32First(ModuleListHandle,
                               &ModuleStruct);
               while (yn!=0)
                 {
                   ModuleID[j++]=ModuleStruct.th32ModuleID;
                   ListBox2->Items->Add(ModuleStruct.szExePath);
                   yn=Module32Next(ModuleListHandle,&ModuleStruct);
                 }
            }
    }
    to TechnoFantasy:非常感谢,我之前只能列.exe,不能列.dll,原来我未掌握关键,现在明白了,
    先给你60分,
    下一个问题未完,怎样卸掉一个.DLL???请继续邦忙!!!
      

  2.   

    还有40分!
    若强行杀掉一个.exe,它的私有.DLL就自动释放了,
    若单独强行卸掉某进程的某一个.DLL,API怎么做?
      

  3.   

    每一个Module都有一个局柄,利用FreeLibrary试一下,刊可不可以释放,获得
    DLL局柄的方法在上面我提供的源程序中有(那60分给谁了 :-))
    www.applevb.com
      

  4.   

    60分当然给你TechnoFantasy了,等这个问题完了给!
    FreeLibrary只释放自已进程的.DLL,人家的可能就不行了;
    强行卸掉某进程的DLL,这个进程变得不稳定了,釜底抽薪吗
      

  5.   

    FreeLibrary()好象无效,结果返回总是0,说明不成功
      

  6.   

    那么这个呢?
    FreeLibraryAndExitThread
      

  7.   

    还有一个办法,就是安装一个内存释放软件,然后利用函数察看工具看它使用了
    那些API
      

  8.   

    FreeLibraryAndExitThread 
    参数中的线程句柄与退出码没法知道,也不行,
    就算了,明天给分就结束!已经很满意了
      

  9.   

    既然没解决问题,就不用给了,到我的竹叶看看,支持一下就可以了
    www.applevb.com