Wykluczenie AnsiCompareText z funkcji GetModuleBaseAddress

0

Witam,
Posiadam kod, który działa itd. Lecz chciałym nie używać tutaj biblioteki SysUtils.
Gdy ją wywalę niestety, kłóci mi się z AnsiCompareText .. Zna ktoś może funkcję w WinApi na AnsiCompareText, badz tez pomoże/podpowie mi jak zmodyfikować poniższą funkcje?
Pozdrawiam

function TFunctions.GetModuleBaseAddress(ProcessID: Cardinal; MName: String): Pointer;
var
  Modules         : Array of HMODULE;
  cbNeeded, i     : Cardinal;
  ModuleInfo      : TModuleInfo;
  ModuleName      : Array[0..MAX_PATH] of Char;
  PHandle         : THandle;
begin
  Result := nil;
  SetLength(Modules, 1024);
  PHandle := OpenProcess(PROCESS_QUERY_INFORMATION + PROCESS_VM_READ, False, ProcessID);
  if (PHandle <> 0) then
  begin
    EnumProcessModules(PHandle, @Modules[0], 1024 * SizeOf(HMODULE), cbNeeded); //Getting the enumeration of modules
    SetLength(Modules, cbNeeded div SizeOf(HMODULE)); //Setting the number of modules
    for i := 0 to Length(Modules) - 1 do //Start the loop
    begin
      GetModuleBaseName(PHandle, Modules[i], ModuleName, SizeOf(ModuleName)); //Getting the name of module
      if AnsiCompareText(MName, ModuleName) = 0 then //If the module name matches with the name of module we are looking for...
      begin
        GetModuleInformation(PHandle, Modules[i], @ModuleInfo, SizeOf(ModuleInfo)); //Get the information of module
        Result := ModuleInfo.lpBaseOfDll; //Return the information we want (The image base address)
        CloseHandle(PHandle);
        Exit;
      end;
    end;
  end;
end;
2

Chodzi o coś takiego jak poniżej? Bo ja wspieram śię kodami źródlowymi modułów VCL od wersji Delphi 7 Enterprise. Ułatwia mi to właśnie pisanie pod WinAPI, podglądając sobie kod pewnych rozwiązań pod VCL. Ewentualnie pozostaje Ci podejrzenie tego w kodach źródłowych Lazarusa.

//...
uses
  PsApi;

function AnsiCompareText(const S1, S2 : string) : integer;
begin
  Result := CompareString(LOCALE_USER_DEFAULT, NORM_IGNORECASE, PChar(S1),
    Length(S1), PChar(S2), Length(S2)) - 2;
end;

function GetModuleBaseAddress(ProcessId : Cardinal; MName : string; var ImageBase, ImageSize : DWORD) : boolean;
var
  PHandle : THandle;
  CbNeeded, I : Cardinal;
  ModuleInfo : TModuleInfo;
  Modules : array of HMODULE;
  ModuleName : array[0..MAX_PATH - 1] of Char;
begin
  ImageBase := 0;
  ImageSize := 0;
  Result := False;
  SetLength(Modules, 1024);
  PHandle := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, False, ProcessId);
  if (PHandle <> 0) then
  begin
    EnumProcessModules(PHandle, @Modules[0], 1024 * SizeOf(HMODULE), CbNeeded);
    SetLength(Modules, CbNeeded div SizeOf(HMODULE));
    for i := 0 to Length(Modules) - 1 do
    begin
      GetModuleBaseName(PHandle, Modules[I], ModuleName, SizeOf(ModuleName));
      if AnsiCompareText(MName, ModuleName) = 0 then
      begin
        GetModuleInformation(PHandle, Modules[I], @ModuleInfo, SizeOf(ModuleInfo));
        Result := True;
        ImageBase := DWORD(ModuleInfo.lpBaseOfDll);
        ImageSize := DWORD(ModuleInfo.SizeOfImage);
        CloseHandle(PHandle);
        Break;
      end;
    end;
  end;
end;
0

Szybko i na temat.
Bardzo dziękuję Olesio za pomoc.
Temat można zamknąć.

1 użytkowników online, w tym zalogowanych: 0, gości: 1