//---------------------------
//帮忙改改下面代码,//我从C++代码改过来的,还有部分我不会改;谢谢
//----------------------------procedure TForm1.Button1Click(Sender: TObject);
var
  hMod:HMODULE;
  cbNeeded:DWORD;
  buf:char;
  hProcess:thandle;
  pid:dword;
//假使process id是 pid 的话:
begin
  hProcess := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ,FALSE,pid);
  if hProcess<>0 then
  begin
    if( EnumProcessModules( hProcess, &hMod, sizeof( hMod ), &cbNeeded ) )  then//这里[:(]
    begin
      buf[MAX_PATH+1]='';
      if(GetModuleBaseName( hProcess, hMod,buf,sizeof buf)>0);
//
// buf放的就是名字
//
  end;
  CloseHandle(hProcess);
end;

解决方案 »

  1.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      hMod:HMODULE;
      cbNeeded:DWORD;
      buf: string;
      hProcess:thandle;
      pid:dword;
    //假使process id是 pid 的话:
    begin
      hProcess := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ,FALSE,pid);
      if hProcess<>0 then
      begin
        if( EnumProcessModules( hProcess, @hMod, sizeof( hMod ), @cbNeeded ) )  then//这里[:(]
        begin
            SetLength(buf, MAX_PATH); //if not enough, increase 1 byte
            if (GetModuleBaseName(hProcess, hMod, PChar(buf), MAX_PATH) > 0 then
            begin
                    SetLength(buf, StrLen(buf));
                    ...
            end;
        end;
      end;
      CloseHandle(hProcess);
    end;
      

  2.   

    是啊  在DELPHI 中我用API  是也有点问题
    谁有好的方法
      

  3.   

    EnumProcessModules 也许是一个需要另外申明的API.
    另外在Delphi中使用API主要是注意变量类型
      

  4.   

    windows  unit里面没有的api要另加申明
    你有没有加接口定义?