📄 comptr.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.GenericStub;
import java.io.*;
abstract public class COMPtr implements IUnknown {
/**
* GIT cookie
*/
private int peer;
/**
* raw, context specific vtable ptr */
private int unknown;
void setPeer(int peer) {
if (this.peer != 0) throw new COMError("peer already exists");
this.peer = peer;
if (peer != 0) {
Identity i = IdentityManager.IncRef(peer);
}
}
void setUnknown(int unknown) {
if (this.unknown != 0) throw new COMError("unknown already exists");
this.unknown = unknown;
}
protected COMPtr() {
}
/**
* Only the IdentityManager creates COMPtrs
*/
protected COMPtr(int peer, int unk) {
this.peer = peer;
this.unknown = unk;
}
/**
* Steal the native unknown pointer from another COMPtr. This should
* only be used inside the marshalling layer when manipulating temporaries
*/
protected void stealUnknown(COMPtr src) {
setUnknown(src.unknown);
src.unknown = 0;
if (IdentityManager.traceRefs) {
System.out.println(this + " assigned reference");
}
}
public byte[] comInvoke(int vtable, String instructions, int stackSize, int arraySize, byte[] argStream)
throws COMException, IOException
{
return GenericStub.comInvokeString(instructions, stackSize, arraySize, argStream, null, vtable, getGuidToken(), peer, unknown);
}
protected void copyUnknown(COMPtr src) {
setUnknown(src.unknown);
int count = Bootstrap.directCOM(src.unknown, 1);
if (IdentityManager.traceRefs) {
System.out.println(this + " AddRef = " + count);
}
}
public String toString() {
return getClass().getName() + "[" + Integer.toHexString(peer)+","+Integer.toHexString(unknown)+"]";
}
public synchronized int getPeer() {
return peer;
}
public synchronized int getUnknown() {
return unknown;
}
public synchronized IUnknown queryInterface(Class newItf) {
return IdentityManager.queryInterface(newItf, this);
}
protected void finalize() {
if (unknown != 0) {
if (IdentityManager.traceRefs) {
System.err.println("****Failed to release reference to " + this);
}
}
synchronized (this) {
if (peer != 0) {
IdentityManager.DecRef(peer);
peer = 0;
}
}
}
public synchronized void close() {
releaseUnknown();
if (peer != 0) {
IdentityManager.DecRef(peer);
peer = 0;
}
}
/**
* call only from a synchronized method
*/
private void releaseUnknown() {
if (unknown != 0) {
int count = Bootstrap.directCOM(unknown, 2);
if (IdentityManager.traceRefs) {
System.out.println(this + " Release = " + count);
}
}
unknown = 0;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -