Barbo24
Barbo24

Reputation: 49

GetProcessImageFileNameA throwing ERROR_INVALID_PARAMETER

I'm using JNA to call GetProcessImageFileNameA from Kernel32 but every time I run the program I get a random result, either I get ERROR_SUCCESS or ERROR_INVALID_PARAMETER.

Memory processName = new Memory(1024);
IntByReference read = new IntByReference(1024);
psapi.GetProcessImageFileNameA(handle, processName, read);

System.out.println(processName.getString(0));
System.out.println(kernel32.GetLastError());

The handle is valid every time and has nothing to do with the final result.

Upvotes: 0

Views: 79

Answers (1)

Daniel Widdis
Daniel Widdis

Reputation: 9091

The function mapping for the third parameter is DWORD nSize. A DWORD can be directly mapped to a (4-byte) int.

You have passed an IntByReference which is a pointer to an int.

Try

int read = 1024;

Upvotes: 1

Related Questions