merged R-1_9 release tag against the root-B-1_9

This commit is contained in:
clay_shooter
2005-02-26 21:32:27 +00:00
parent ebb1eddb69
commit bcf7bb0f85
132 changed files with 7134 additions and 4068 deletions

4
jni/.cvsignore Normal file
View File

@@ -0,0 +1,4 @@
jacob.dll
jacob.lib
jacob.exp

View File

@@ -410,9 +410,22 @@ JNIEXPORT jobject JNICALL Java_com_jacob_com_Dispatch_invokev
// check for error and display a somewhat verbose error message
if (!SUCCEEDED(hr)) {
const char *nm = env->GetStringUTFChars(name, NULL);
char *buf = CreateErrorMsgFromInfo(hr, &excepInfo, nm);
env->ReleaseStringUTFChars(name, nm);
// two buffers that may have to be freed later
char *buf = NULL;
char *dispIdAsName = NULL;
// this method can get called with a name or a dispatch id
// we need to handle both SF 1114159
if (name != NULL){
const char *nm = env->GetStringUTFChars(name, NULL);
buf = CreateErrorMsgFromInfo(hr, &excepInfo, nm);
env->ReleaseStringUTFChars(name, nm);
} else {
dispIdAsName = new char[256];
// get the id string
itoa (dispID,dispIdAsName,10);
//continue on mostly as before
buf = CreateErrorMsgFromInfo(hr,&excepInfo,dispIdAsName);
}
// jacob-msg 3696 - SF 1053866
if(hr == DISP_E_EXCEPTION)
@@ -429,6 +442,7 @@ JNIEXPORT jobject JNICALL Java_com_jacob_com_Dispatch_invokev
ThrowComFail(env, buf, hr);
if (buf) delete buf;
if (dispIdAsName) delete dispIdAsName;
return NULL;
}

View File

@@ -72,7 +72,10 @@ void putProxy(JNIEnv *env, jobject arg, EventProxy *ep)
* Signature: (LDispatch;Ljava/lang/Object;Ljava/lang/String;)V
*/
JNIEXPORT void JNICALL Java_com_jacob_com_DispatchEvents_init2
(JNIEnv *env, jobject _this, jobject src, jobject sink, jstring _progid)
(JNIEnv *env,
jobject _this, jobject src,
jobject sink, jobject protoVariant,
jstring _progid)
{
USES_CONVERSION;
// find progid if any
@@ -104,10 +107,11 @@ JNIEXPORT void JNICALL Java_com_jacob_com_DispatchEvents_init2
return;
}
HRESULT hr = pCPC->FindConnectionPoint(eventIID, &pCP);
DWORD dwEventCookie;
// VC++ 6.0 compiler realiized we weren't using this variable
//DWORD dwEventCookie;
if (SUCCEEDED(hr))
{
EventProxy *ep = new EventProxy(env, sink, pCP, eventIID, mNames, mIDs, n_EventMethods);
EventProxy *ep = new EventProxy(env, sink, protoVariant, pCP, eventIID, mNames, mIDs, n_EventMethods);
// need to store ep on _this, in case it gets collected
putProxy(env, _this, ep);
} else {
@@ -121,9 +125,9 @@ JNIEXPORT void JNICALL Java_com_jacob_com_DispatchEvents_init2
* Signature: (LDispatch;Ljava/lang/Object;)V
*/
JNIEXPORT void JNICALL Java_com_jacob_com_DispatchEvents_init
(JNIEnv *env, jobject _this, jobject src, jobject sink)
(JNIEnv *env, jobject _this, jobject src, jobject sink, jobject protoVariant)
{
Java_com_jacob_com_DispatchEvents_init2(env,_this,src,sink,NULL);
Java_com_jacob_com_DispatchEvents_init2(env,_this,src,sink, protoVariant, NULL);
}
/*

View File

@@ -13,7 +13,7 @@ extern "C" {
* Signature: (LDispatch;Ljava/lang/Object;)V
*/
JNIEXPORT void JNICALL Java_com_jacob_com_DispatchEvents_init
(JNIEnv *, jobject, jobject, jobject);
(JNIEnv *, jobject, jobject, jobject, jobject);
/*
* Class: DispatchEvents
@@ -21,7 +21,7 @@ JNIEXPORT void JNICALL Java_com_jacob_com_DispatchEvents_init
* Signature: (LDispatch;Ljava/lang/Object;Ljava/lang/String;)V
*/
JNIEXPORT void JNICALL Java_com_jacob_com_DispatchEvents_init2
(JNIEnv *, jobject, jobject, jobject, jstring);
(JNIEnv *, jobject, jobject, jobject, jobject, jstring);
/*
* Class: DispatchEvents

View File

@@ -28,34 +28,44 @@
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "EventProxy.h"
#include "Variant.h"
// hook myself up as a listener for delegate
EventProxy::EventProxy(JNIEnv *env, jobject aSinkObj,
EventProxy::EventProxy(JNIEnv *env,
jobject aSinkObj,
jobject aVariantObj,
CComPtr<IConnectionPoint> pConn,
IID eid, CComBSTR mName[], DISPID mID[], int mNum) :
IID eid,
CComBSTR mName[],
DISPID mID[],
int mNum) :
// initialize some variables
m_cRef(0), pCP(pConn),
eventIID(eid), MethNum(mNum), MethName(mName),
MethID(mID), JMethID(NULL), javaSinkClass(NULL),
variantClassMethod(NULL)
MethID(mID), JMethID(NULL),
javaSinkClass(NULL)
{
// don't really need the variant object but we keep a reference
// anyway
javaSinkObj = env->NewGlobalRef(aSinkObj);
if (env->ExceptionOccurred()) { env->ExceptionDescribe();}
if (env->ExceptionOccurred()) { env->ExceptionDescribe(); env->ExceptionClear();}
javaVariantObj = env->NewGlobalRef(aVariantObj);
if (env->ExceptionOccurred()) { env->ExceptionDescribe(); env->ExceptionClear();}
// we need this to attach to the event invocation thread
env->GetJavaVM(&jvm);
if (env->ExceptionOccurred()) { env->ExceptionDescribe(); }
if (env->ExceptionOccurred()) { env->ExceptionDescribe(); env->ExceptionClear();}
AddRef();
HRESULT hr = pCP->Advise(this, &dwEventCookie);
if (SUCCEEDED(hr)) {
// create a mapping from the DISPID's to jmethodID's by using
// the method names I extracted from the classinfo
JMethID = new jmethodID[MethNum];
javaSinkClass = env->GetObjectClass(javaSinkObj);
if (javaSinkClass == NULL){ printf("can't figure out java sink class"); }
if (env->ExceptionOccurred()) { env->ExceptionDescribe(); }
variantClassMethod = env->GetMethodID(javaSinkClass, "getVariantClass", "()Ljava/lang/Class;");
if (env->ExceptionOccurred()) { env->ExceptionDescribe(); }
if (variantClassMethod == NULL) { printf("variantClassMethod == null\n"); }
if (env->ExceptionOccurred()) { env->ExceptionDescribe(); env->ExceptionClear();}
const char *method;
for(int i=0;i<MethNum;i++)
@@ -69,6 +79,7 @@ EventProxy::EventProxy(JNIEnv *env, jobject aSinkObj,
// if the user didn't implement all the methods
env->ExceptionClear();
}
} else {
ThrowComFail(env, "Advise failed", hr);
}
@@ -85,10 +96,10 @@ EventProxy::~EventProxy()
#else
jvm->AttachCurrentThread((void**)&env, NULL);
#endif
env->DeleteGlobalRef(javaSinkObj);
if (env->ExceptionOccurred()) { env->ExceptionDescribe(); }
if (env->ExceptionOccurred()) { env->ExceptionDescribe(); env->ExceptionClear();}
if (MethNum) {
delete [] MethName;
delete [] MethID;
@@ -125,7 +136,8 @@ STDMETHODIMP EventProxy::Invoke(DISPID dispID, REFIID riid,
LCID lcid, unsigned short wFlags, DISPPARAMS *pDispParams,
VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
{
HRESULT hr;
//Visual C++ 6.0 recognized this as an unused variable
//HRESULT hr;
jmethodID meth = 0;
JNIEnv *env = NULL;
@@ -146,29 +158,32 @@ STDMETHODIMP EventProxy::Invoke(DISPID dispID, REFIID riid,
{
// attach to the current running thread
#ifdef JNI_VERSION_1_2
jvm->AttachCurrentThread((void **)&env, jvm);
#else
jvm->AttachCurrentThread((void**)&env, NULL);
#endif
jvm->AttachCurrentThread((void **)&env, jvm);
#else
jvm->AttachCurrentThread((void**)&env, NULL);
#endif
// get variant class
jclass vClass;
jclass vClass = NULL;
// do this in a JACOB 1.8 backwards compatable way
// this succeeds if the class was loaded from the bootstrap class loader
vClass = env->FindClass("com/jacob/com/Variant");
//vClass = env->FindClass("com/jacob/com/Variant");
// this is guarenteed to work so there really isn't any need for the line above
// but I don't want to bust anything so we leave it in
// the following code exists to support launchers like JWS where jacob isn't
// in the system classloader so we wouldn't be able to create a variant class
if (vClass == NULL){
// see if our call back class implements our "special" method
if (variantClassMethod != NULL){
jobject variantFound = env->CallObjectMethod(javaSinkObj, variantClassMethod);
if (env->ExceptionOccurred()) { env->ExceptionDescribe(); }
if (variantFound == NULL) { printf("variantFound == null\n"); }
vClass = (jclass)variantFound;
} else {
// dang they didn't. lets tell the user they are having a bad day
printf("We're going to fail now in a way that is probably pretty ugly");
// there will be a stored up exception if FindClass failed so lets clear it
if (env->ExceptionOccurred()) { env->ExceptionClear(); }
//printf("using variant class passed in via constructor\n");
jclass javaVariantClass = env->GetObjectClass(javaVariantObj);
if (javaVariantClass == NULL){ printf("can't figure out java Variant class"); }
if (env->ExceptionOccurred()) { env->ExceptionDescribe(); env->ExceptionClear();}
vClass = javaVariantClass;
if (vClass == NULL){
printf("This application is probably running from a launcher where system class loader knows not Jacob\n");
printf("The call back class does not implement 'Class getVariantClass()' that we can use to work around this\n");
printf("And for some reason we couldn't find the variant class from the passed in variant\n");
}
}
@@ -176,16 +191,16 @@ STDMETHODIMP EventProxy::Invoke(DISPID dispID, REFIID riid,
int num = pDispParams->cArgs;
// and the constructor
jmethodID vCons = env->GetMethodID(vClass, "<init>", "()V");
if (env->ExceptionOccurred()) { env->ExceptionDescribe(); }
if (env->ExceptionOccurred()) { env->ExceptionDescribe(); env->ExceptionClear();}
// make an array of them
jobjectArray varr = env->NewObjectArray(num, vClass, 0);
if (env->ExceptionOccurred()) { env->ExceptionDescribe(); }
if (env->ExceptionOccurred()) { env->ExceptionDescribe(); env->ExceptionClear();}
int i,j;
for(i=num-1,j=0;i>=0;i--,j++)
{
// construct a java variant holder
jobject arg = env->NewObject(vClass, vCons);
if (env->ExceptionOccurred()) { env->ExceptionDescribe(); }
if (env->ExceptionOccurred()) { env->ExceptionDescribe(); env->ExceptionClear();}
// get the empty variant from it
VARIANT *va = extractVariant(env, arg);
// copy the value
@@ -193,11 +208,11 @@ STDMETHODIMP EventProxy::Invoke(DISPID dispID, REFIID riid,
// put it in the array
env->SetObjectArrayElement(varr, j, arg);
env->DeleteLocalRef(arg);
if (env->ExceptionOccurred()) { env->ExceptionDescribe(); }
if (env->ExceptionOccurred()) { env->ExceptionDescribe(); env->ExceptionClear();}
}
// call the method
env->CallVoidMethod(javaSinkObj, meth, varr);
if (env->ExceptionOccurred()) { env->ExceptionDescribe(); }
if (env->ExceptionOccurred()) { env->ExceptionDescribe(); env->ExceptionClear();}
// Begin code from Jiffie team that copies parameters back from java to COM
@@ -820,6 +835,7 @@ STDMETHODIMP EventProxy::Invoke(DISPID dispID, REFIID riid,
}
zeroVariant(env, arg);
env->DeleteLocalRef(arg);
}
// End code from Jiffie team that copies parameters back from java to COM

View File

@@ -59,7 +59,7 @@ private:
DWORD dwEventCookie; // connection point cookie
jobject javaSinkObj; // the java object to delegate calls
jclass javaSinkClass; // the java class of the object
jmethodID variantClassMethod; // the method on the javaSinkObj that will return the Variant class
jobject javaVariantObj; // a variant object passed in so we can find Variant later
IID eventIID; // the interface iid passed in
int MethNum;
@@ -70,9 +70,14 @@ private:
public:
// constuct with a global JNI ref to a sink object
// to which we will delegate event callbacks
EventProxy(JNIEnv *jenv, jobject aSinkObj,
EventProxy(JNIEnv *jenv,
jobject aSinkObj,
jobject aVariantObj,
CComPtr<IConnectionPoint> pConn,
IID eventIID, CComBSTR *mName, DISPID *mID, int mNum);
IID eventIID,
CComBSTR *mName,
DISPID *mID,
int mNum);
~EventProxy();
// IUnknown methods

View File

@@ -99,13 +99,12 @@ SAFEARRAY *copySA(SAFEARRAY *psa)
VARIANT v1, v2;
VariantInit(&v1);
VariantInit(&v2);
VariantInit(&v2);
V_VT(&v1) = VT_ARRAY | vt;
V_ARRAY(&v1) = psa;
VariantCopy(&v2, &v1);
SAFEARRAY *sa = V_ARRAY(&v2);
VariantInit(&v2); // make sure it's not owned by this variant
VariantClear(&v2);
VariantInit(&v1);
VariantClear(&v1);
@@ -1719,8 +1718,8 @@ JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_setString__IILjava_lang_Stri
ThrowComFail(env, "safearray object corrupted", -1);
return;
}
if (SafeArrayGetDim(sa) != 1) {
ThrowComFail(env, "safearray is not 1D", -1);
if (SafeArrayGetDim(sa) != 2) {
ThrowComFail(env, "safearray is not 2D", -1);
return;
}
VARTYPE vt;
@@ -2035,8 +2034,8 @@ JNIEXPORT jboolean JNICALL Java_com_jacob_com_SafeArray_getBoolean__II
ThrowComFail(env, "safearray object corrupted", -1);
return NULL;
}
if (SafeArrayGetDim(sa) != 1) {
ThrowComFail(env, "safearray is not 1D", -1);
if (SafeArrayGetDim(sa) != 2) {
ThrowComFail(env, "safearray is not 2D", -1);
return NULL;
}
VARTYPE vt;
@@ -2110,10 +2109,10 @@ JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_setBoolean__IIZ
ThrowComFail(env, "safearray object corrupted", -1);
return;
}
if (SafeArrayGetDim(sa) != 1) {
ThrowComFail(env, "safearray is not 1D", -1);
if (SafeArrayGetDim(sa) != 2) {
ThrowComFail(env, "safearray is not 2D", -1);
return;
}
}
VARTYPE vt;
SafeArrayGetVartype(sa, &vt);
long idx[2] = {i,j};

View File

@@ -91,6 +91,25 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Variant_init
env->SetIntField(_this, jf, (unsigned int)v);
}
/*
* Class: com_jacob_com_Variant
* Method: zeroVariant
* Signature: ()V
*
* This should only be used on variant objects created by teh
* com layer as part of a call through EventProxy.
* This zeros out the variant pointer in the Variant object
* so that the calling COM program can free the memory.
* instead of both the COM program and the Java GC doing it.
*/
void zeroVariant(JNIEnv *env, jobject _this)
{
jclass clazz = env->GetObjectClass(_this);
jfieldID jf = env->GetFieldID(clazz, VARIANT_FLD, "I");
env->SetIntField(_this, jf, (unsigned int)0);
}
JNIEXPORT void JNICALL Java_com_jacob_com_Variant_Save
(JNIEnv *env, jobject _this, jobject outStream)
{
@@ -351,6 +370,7 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putDateRef
}
}
// SF 1065533 added unicode support
JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putStringRef
(JNIEnv *env, jobject _this, jstring s)
{
@@ -358,21 +378,15 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putStringRef
if (v) {
VariantClear(v); // whatever was there before
// need to convert to C-style char buffer
jclass strcls = env->FindClass("java/lang/String");
jmethodID getBytes = env->GetMethodID(strcls, "getBytes", "()[B");
jbyteArray ba = (jbyteArray)env->CallObjectMethod(s, getBytes);
int len = env->GetArrayLength(ba);
jbyte* buf = (jbyte*)alloca(len + 1);
env->GetByteArrayRegion(ba, 0, len, buf);
buf[len] = '\0';
CComBSTR bs((char*)buf);
const jchar *cStr = env->GetStringChars(s,NULL);
CComBSTR bs(cStr);
BSTR *pbs = (BSTR *)CoTaskMemAlloc(sizeof(BSTR));
bs.CopyTo(pbs);
V_VT(v) = VT_BSTR|VT_BYREF;
V_BSTRREF(v) = pbs;
}
env->ReleaseStringChars(s,cStr); }
}
JNIEXPORT jshort JNICALL Java_com_jacob_com_Variant_getShortRef
@@ -858,6 +872,7 @@ JNIEXPORT jstring JNICALL Java_com_jacob_com_Variant_getString
return NULL;
}
// SF 1065533 added unicode support
JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putString
(JNIEnv *env, jobject _this, jstring s)
{
@@ -866,18 +881,13 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putString
VariantClear(v); // whatever was there before
V_VT(v) = VT_BSTR;
// get C-style byte array
jclass strcls = env->FindClass("java/lang/String");
jmethodID getBytes = env->GetMethodID(strcls, "getBytes", "()[B");
jbyteArray ba = (jbyteArray)env->CallObjectMethod(s, getBytes);
int len = env->GetArrayLength(ba);
jbyte* buf = (jbyte*)alloca(len + 1);
env->GetByteArrayRegion(ba, 0, len, buf);
buf[len] = '\0';
const jchar *cStr = env->GetStringChars(s,NULL);
CComBSTR bs(cStr);
CComBSTR bs((char*)buf);
V_VT(v) = VT_BSTR;
V_BSTR(v) = bs.Copy();
env->ReleaseStringChars(s,cStr);
}
}

View File

@@ -607,6 +607,19 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Variant_Load
JNIEXPORT jboolean JNICALL Java_com_jacob_com_Variant_isNull
(JNIEnv *, jobject);
/*
* Class: com_jacob_com_Variant
* Method: zeroVariant
* Signature: ()V
*
* This should only be used on variant objects created by teh
* com layer as part of a call through EventProxy.
* This zeros out the variant pointer in the Variant object
* so that the calling COM program can free the memory.
* instead of both the COM program and the Java GC doing it.
*/
void zeroVariant (JNIEnv *, jobject);
#ifdef __cplusplus
}
#endif

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -1,51 +0,0 @@
JDK = d:\j2sdk1.4.2_06
DEST_DIR = d:\jacob_18
MSDEVDIR = d:\apps\\"Microsoft Visual Studio"\VC98
JDK_INC = -I$(JDK)\include -I$(JDK)\include\win32
JDK_LIB = $(JDK)\lib\jvm.lib
MS_INC = -I$(MSDEVDIR)\Include -I$(MSDEVDIR)\ATL\Include
SYS_LIB = oleaut32.lib ole32.lib uuid.lib kernel32.lib shell32.lib user32.lib
OPT = /O2
CC = cl $(OPT) $(JDK_INC) $(MS_INC)
OBJFILES = stdafx.obj util.obj EventProxy.obj Variant.obj Dispatch.obj SafeArray.obj DispatchEvents.obj ComThread.obj EnumVariant.obj STA.obj DispatchProxy.obj
all: jacob.dll
cp jacob.dll $(DEST_DIR)
jacob.dll: $(OBJFILES)
link /dll /out:jacob.dll $(OBJFILES) $(JDK_LIB) $(SYS_LIB)
stdafx.obj: stdafx.cpp *.h
$(CC) -c stdafx.cpp
util.obj: util.cpp *.h
$(CC) -c util.cpp
EventProxy.obj: EventProxy.cpp *.h
$(CC) -c EventProxy.cpp
Variant.obj: Variant.cpp *.h
$(CC) -c Variant.cpp
Dispatch.obj: Dispatch.cpp *.h
$(CC) -c Dispatch.cpp
SafeArray.obj: SafeArray.cpp *.h
$(CC) -c SafeArray.cpp
DispatchEvents.obj: DispatchEvents.cpp *.h
$(CC) -c DispatchEvents.cpp
ComThread.obj: ComThread.cpp *.h
$(CC) -c ComThread.cpp
EnumVariant.obj: EnumVariant.cpp *.h
$(CC) -c EnumVariant.cpp
STA.obj: STA.cpp *.h
$(CC) -c STA.cpp
DispatchProxy.obj: DispatchProxy.cpp *.h
$(CC) -c DispatchProxy.cpp

View File

@@ -5,6 +5,5 @@ extern "C" {
IDispatch *extractDispatch(JNIEnv *env, jobject arg);
SAFEARRAY *extractSA(JNIEnv *env, jobject arg);
void setSA(JNIEnv *env, jobject arg, SAFEARRAY *sa, int copy);
SAFEARRAY *copySA(SAFEARRAY *psa)
SAFEARRAY *copySA(SAFEARRAY *psa);
}