I am trying to import GetModuleFileNameEx
in java application. The definition of the function is:
DWORD WINAPI GetModuleFileNameEx(
_In_ HANDLE hProcess,
_In_opt_ HMODULE hModule,
_Out_ LPTSTR lpFilename,
_In_ DWORD nSize
);
I translated that into:
public abstract DWORD GetModuleFileNameEx(
WinNT.HANDLE hProcess,
WinNT.HMODULE hModule,
char[] pathName,
WinNT.DWORD pathNameSize
);
Which I defined in class like this:
import com.sun.jna.Native;
import com.sun.jna.Pointer;
import com.sun.jna.platform.win32.Kernel32;
import com.sun.jna.platform.win32.WinDef;
import com.sun.jna.platform.win32.WinNT;
import com.sun.jna.win32.W32APIOptions;
public abstract interface Kernel32Ext
extends Kernel32
{
public static final Kernel32Ext INSTANCE = (Kernel32Ext)Native.loadLibrary("kernel32.dll", Kernel32Ext.class, W32APIOptions.DEFAULT_OPTIONS);
public abstract DWORD GetModuleFileNameEx(WinNT.HANDLE hProcess, WinNT.HMODULE hModule, char[] pathName, WinNT.DWORD pathNameSize);
}
But when I try to call the method I get an error:
java.lang.UnsatisfiedLinkError: Error looking up function 'GetModuleFileNameEx': Uvedená procedura nebyla nalezena.
I double checked and according to posts here on stack overflow and other JNA programs, LPTSTR
correctly translates to char[]
in JNA API. So there must be something else that is wrong. Am I importing wrong dll, or with wrong options?
I am running this on Windows 7 x64 bit (Czech, hence the non-english error message).
There is no function by that name in kernel32 (or elsewhere). See the MSDN page for GetModuleFileNameEx. The function you're looking for is GetModuleFileNameExW
.