1

I override the function library kernel32.dll in Pascal and OpenProcess function returns 0. Function GetLastError() returns 87 error, that means

ERROR_INVALID_PARAMETER 87 (0x57) The parameter is incorrect.

What could be wrong?

Program UODll;
const search_window = 'Ultima Online - xxx (The Abyss)';
function FindWindow(C1, C2: PChar): Longint; external '[email protected] stdcall';
function GetWindowThreadProcessId(hWnd: Longint; opt: Word): Word; external '[email protected] stdcall';
function OpenProcess(dwDesiredAccess: Word; inherit: Byte; pid: Word): Longint; external '[email protected] stdcall';
function GetProcessId(proc: Longint): Word; external '[email protected] stdcall';
function GetLastError(): Word; external '[email protected] stdcall';
var
res, err: Word;
wnd, proc: Longint;
Begin
wnd := Findwindow('', search_window);
if (wnd > 0) then
begin
res := GetWindowThreadProcessId(wnd, res);
proc := OpenProcess($0400,0,res);
err := GetLastError();
writeln(IntToStr(proc));
writeln(IntToStr(err));
end;
End.

Im trying to use LongWord and Cardinal, but i have the same error.. Who can help me?) P.S. its not delphi.. i dont know what is this :) Programm calls UOScript

1
  • If this is Delphi then these API functions are already (properly) declared in the Windows unit. May 15, 2013 at 20:53

1 Answer 1

2

OpenProcess has declaration

HANDLE WINAPI OpenProcess(
  _In_  DWORD dwDesiredAccess,
  _In_  BOOL bInheritHandle,
  _In_  DWORD dwProcessId
);

dwDesiredAccess and pid are double words that are

typedef unsigned long       DWORD;

i.e. 32bit on x86, according to this answer.

But Delphi/Pascal Word type is 16bit.

Also, BOOL is defined as

typedef int BOOL;

So, you should use Integer for inherit instead of Byte

So, your function declaration is incorrect.

Seems you should use Cardinal or LongWord instead of Word in your declarations.

If you use Delphi, you can import Windows module that has all Win API functions defined.

2
  • thx. but how can i declare that function on pascal? What type i should use?
    – Evgeniy
    May 15, 2013 at 20:41
  • Word is Borland (Turbo/Delphi Pascal) style. Original Pascal has only one signed integer and uses subranges for the rest May 16, 2013 at 18:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.