jnative 为什么调用失败,总是返回0

kevin liu 发布于 2011/07/30 03:52
阅读 1K+
收藏 1
import org.xvolks.jnative.JNative;
import org.xvolks.jnative.Type;
import org.xvolks.jnative.exceptions.NativeException;
import org.xvolks.jnative.pointers.Pointer;
import org.xvolks.jnative.pointers.memory.MemoryBlockFactory;

public class JNativTest {


	public static int FindWindow(String sClassName, String sWindowName)
									throws NativeException, IllegalAccessException {

		JNative jnative = new JNative("user32", "FindWindowW");
		jnative.setRetVal(Type.INT);
		jnative.setParameter(0,  sClassName);
		jnative.setParameter(1, sWindowName);
		jnative.invoke();
		int hWnd = Integer.parseInt(jnative.getRetVal());
		return hWnd;

	}
	
	public static int GetDriveType(String nDrive) throws Exception{

		JNative jnative = new JNative("kernel32", "GetDriveTypeA");
		jnative.setRetVal(Type.INT);
		jnative.setParameter(0, Type.STRING, nDrive);
		jnative.invoke();
		int hWnd = Integer.parseInt(jnative.getRetVal());
		return hWnd;
	}

	public static Integer InstallWinIoDriver()
			throws Exception {

		System.loadLibrary("WinIo32");

		Integer ret = new Integer(0);
		JNative jnative = new JNative("WinIo32", "InstallWinIoDriver");
		jnative.setRetVal(Type.INT);

		Pointer pszWinIoDriverPath = new Pointer(MemoryBlockFactory.createMemoryBlock(100));
		jnative.setParameter(0, pszWinIoDriverPath);
		jnative.setParameter(1, Type.INT, "0");

		jnative.invoke();
		ret = Integer.parseInt(jnative.getRetVal());
		
		String str = pszWinIoDriverPath.getAsString();
		System.out.println(str);
		return ret;

	}
	
	public static int InitializeWinIo() throws Exception{
		
		Integer ret = new Integer(0);
		JNative jnative = new JNative("WinIo32", "InitializeWinIo");
		jnative.setRetVal(Type.INT);
		jnative.invoke();
		ret = Integer.parseInt(jnative.getRetVal());
		return ret;

    }


	public static void main(String[] args) throws Exception {

		System.out.println(FindWindow("Notepad", ""));//return 0
		System.out.println(InstallWinIoDriver());//return 0
		System.out.println(GetDriveType("d:"));//这个可以返回结果
		System.out.println(InitializeWinIo());//return 0

	}

}
为什么有的可以,有的不行呢,检查来检查去。。。头疼,兄弟们帮忙瞧瞧,感激不尽
加载中
0
673
673

你的测试程序中: findWindow("Notepad","")返回0,参考解决方案:

a.将测试代码中的第二个参数改成null,然后用记事本随便打开个文本,然后再运行;

b.如果还不行,把调用的本地方法名"FindWindowW"改成"FindWindowA"


---------

其它俩个我机器是win7 32bit,貌似没有WinTo32这个库。


0
z
zfqzpp
楼主调用的window xp系统下的dll文件,那么这个dll文件中的相关的函数对应的含义和这个dll文件中的相关的函数使用的参数以及返回的参数是怎么知道了啊。。。求解 。。。
返回顶部
顶部