📄 funcptr.java
字号:
//******************************************************************
// Released under the DevelopMentor OpenSource Software License.
// Please consult the LICENSE file in the project root directory,
// or at http://www.develop.com for details before using this
// software.
//******************************************************************
package com.develop.jawin;
import com.develop.jawin.marshal.*;
public final class FuncPtr
{
/** The function pointer. */
private int peer;
/** The dll handle. */
private int dllHandle;
/** The library name. */
private String dll;
/** The entry point name. This may not be the same as the name in source code,
use DUMPBIN /EXPORTS to get the exact name. */
private String name;
private int hash;
public FuncPtr(String dll, String name) throws COMException {
this.name = name;
this.dll = dll;
dllHandle = Bootstrap.loadLibrary(dll);
peer = Bootstrap.loadFunction(dllHandle, name);
hash = dll.hashCode() ^ name.hashCode();
}
public int hashCode() {
return hash;
}
public int getPeer() {
return peer;
}
public boolean equals(Object o) {
if (o == null)
return false;
if (o.getClass() != getClass())
return false;
if (o == this)
return true;
FuncPtr fp = (FuncPtr) o;
return (dll.equals(fp.dll) && name.equals(fp.name));
}
/**
* Call to "free" the function pointer. Windows automatically
* manages a reference count for each library and will close the
* library if this was the last active function.
*/
public synchronized void close() {
if (peer != 0) {
Bootstrap.freeLibrary(dllHandle);
dllHandle = 0;
peer = 0;
}
}
protected void finalize() {
close();
}
public int invoke(ReturnFlags flags) {
return SharedStubs.invoke_I(peer, flags.value);
}
public int invoke(int arg0, ReturnFlags flags) {
return SharedStubs.invokeI_I(arg0, peer, flags.value);
}
public int invoke(int arg0, int arg1, ReturnFlags flags) {
return SharedStubs.invokeII_I(arg0, arg1, peer, flags.value);
}
public int invoke(int arg0, int arg1, int arg2, int arg3, ReturnFlags flags) {
return SharedStubs.invokeIIII_I(arg0, arg1, arg2, arg3, peer, flags.value);
}
public int invoke(String arg0, ReturnFlags flags) {
return SharedStubs.invokeG_I(arg0, peer, flags.value);
}
public int invoke(String arg0, String arg1, ReturnFlags flags) {
return SharedStubs.invokeGG_I(arg0, arg1, peer, flags.value);
}
public int invoke(int arg0, String arg1, String arg2, int arg3, ReturnFlags flags) {
return SharedStubs.invokeIGGI_I(arg0, arg1, arg2, arg3, peer, flags.value);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -