Пример #1
0
jlong GetComReferencePointer(JNIEnv* env, jobject obj, const char* fieldName)
{
	jclass cls;
	jobject reference;

	cls = env->GetObjectClass(obj);
	reference = env->GetObjectField(obj, env->GetFieldID(cls, fieldName, "Lbe/derycke/pieter/com/COMReference;"));
	return ConvertComReferenceToPointer(env, reference);
}
JNIEXPORT jobject JNICALL Java_jmtp_PortableDevicePropertiesImplWin32_setValues
	(JNIEnv* env, jobject obj, jstring jsObjectID, jobject jobjValues)
{
	//variabelen
	HRESULT hr;
	IPortableDeviceProperties* pProperties;
	IPortableDeviceValues* pValues;
	IPortableDeviceValues* pResults;
	LPWSTR wszObjectID;
	jclass cls;
	jmethodID mid;
	jobject jobjReference;


	//methode implementatie
	if(jsObjectID != NULL && jobjValues != NULL)
	{
		pProperties = GetPortableDeviceProperties(env, obj);

		jobjReference = RetrieveCOMReferenceFromCOMReferenceable(env, jobjValues);
		pValues = (IPortableDeviceValues*)ConvertComReferenceToPointer(env, jobjReference);
		
		wszObjectID = (WCHAR*)env->GetStringChars(jsObjectID, NULL);
		hr = pProperties->SetValues(wszObjectID, pValues, &pResults);
		env->ReleaseStringChars(jsObjectID, (jchar*)wszObjectID);

		if(SUCCEEDED(hr))
		{
			//smart reference object aanmaken
			cls = env->FindClass("be/derycke/pieter/com/COMReference");
			mid = env->GetMethodID(cls, "<init>", "(J)V");
			jobjReference = env->NewObject(cls, mid, pResults);
			
			cls = env->FindClass("jmtp/PortableDeviceValuesImplWin32");
			mid = env->GetMethodID(cls, "<init>", "(Lbe/derycke/pieter/com/COMReference;)V");
			return env->NewObject(cls, mid, jobjReference);
		}
		else
		{
			ThrowCOMException(env, L"Couldn't change the properties of the element", hr);
			return NULL;
		}
	}
	else
	{
		env->ThrowNew(env->FindClass("java/lang/NullPointerException"), "arguments can't be null");
		return NULL;
	}
}
JNIEXPORT jobject JNICALL Java_jmtp_PortableDevicePropertiesImplWin32_getValues
	(JNIEnv* env, jobject obj, jstring jsObjectID, jobject jobjKeyCollection)
{
	HRESULT hr;
	IPortableDeviceProperties* pProperties;
	IPortableDeviceValues* pValues;
	IPortableDeviceKeyCollection* pKeyCollection;
	LPWSTR wszObjectID;
	jclass cls;
	jmethodID mid;
	jobject jobjKeyCollectionReference;
	jobject jobjReference;

	pProperties = GetPortableDeviceProperties(env, obj);
	mid = env->GetMethodID(env->GetObjectClass(jobjKeyCollection), "getReference", 
		"()Lbe/derycke/pieter/com/COMReference;");
	jobjKeyCollectionReference = env->CallObjectMethod(jobjKeyCollection, mid);
	pKeyCollection = 
		(IPortableDeviceKeyCollection*)ConvertComReferenceToPointer(env, jobjKeyCollectionReference);
	wszObjectID = (WCHAR*)env->GetStringChars(jsObjectID, NULL);

	hr = pProperties->GetValues(wszObjectID, pKeyCollection, &pValues);
	env->ReleaseStringChars(jsObjectID,(jchar*)wszObjectID);

	if(FAILED(hr))
	{
		ThrowCOMException(env, L"Failed to retrieve the properties", hr);
		return NULL;
	}

	//smart reference object aanmaken
	cls = env->FindClass("be/derycke/pieter/com/COMReference");
	mid = env->GetMethodID(cls, "<init>", "(J)V");
	jobjReference = env->NewObject(cls, mid, pValues);
	
	cls = env->FindClass("jmtp/PortableDeviceValuesImplWin32");
	mid = env->GetMethodID(cls, "<init>", "(Lbe/derycke/pieter/com/COMReference;)V");
	return env->NewObject(cls, mid, jobjReference);
}
Пример #4
0
jlong GetComReferencePointerFromComReferenceable(JNIEnv* env, jobject jobjCOMReferenceable)
{
	jobject jobjReference = RetrieveCOMReferenceFromCOMReferenceable(env, jobjCOMReferenceable);
	return ConvertComReferenceToPointer(env, jobjReference);
}
Пример #5
0
void* RetrievePointerFromCOMReferenceable(JNIEnv* env, jobject jobjCOMReferenceable) {
	jobject jobjValuesReference = RetrieveCOMReferenceFromCOMReferenceable(env, jobjCOMReferenceable);
	return (void *)ConvertComReferenceToPointer(env, jobjValuesReference);
}
Пример #6
0
JNIEXPORT jstring JNICALL Java_jmtp_PortableDeviceContentImplWin32_createObjectWithPropertiesAndData
	(JNIEnv* env, jobject obj, jobject jobjValues, jobject jobjFile)
{
	//variabelen
	HRESULT hr;
	IPortableDeviceContent* pDeviceContent;
	IPortableDeviceValues* pDeviceObjectValues;
	jobject jobjValuesReference;
	jstring jsFileLocation;
	LPWSTR wszFileLocation;
	DWORD dwBufferSize;
	CComPtr<IStream> pFileStream;
	CComPtr<IStream> pDeviceStream;
	CComPtr<IPortableDeviceDataStream> pDeviceDataStream;
	STATSTG fileStats;
	BYTE* pBuffer;
	DWORD dwReadFromStream;
	LPWSTR wszObjectID;
	jstring jsObjectID;
	jmethodID mid;


	//Methode implementatie
	pDeviceContent = GetPortableDeviceContent(env, obj);
	jobjValuesReference = RetrieveCOMReferenceFromCOMReferenceable(env, jobjValues);
	pDeviceObjectValues = (IPortableDeviceValues*)ConvertComReferenceToPointer(env, jobjValuesReference);
	
	//COM stream object aanmaken
	mid = env->GetMethodID(env->FindClass("java/io/File"), "getAbsolutePath", "()Ljava/lang/String;");
	jsFileLocation = (jstring)env->CallObjectMethod(jobjFile, mid);
	wszFileLocation = (WCHAR*)env->GetStringChars(jsFileLocation, NULL);
	hr = SHCreateStreamOnFileW(wszFileLocation, STGM_READ, &pFileStream);
	env->ReleaseStringChars(jsFileLocation, (jchar*)wszFileLocation); //string resources terug vrijgeven

	if(SUCCEEDED(hr))
	{
		//groote van het bestand bepalen
		//(door een beperking in java op het gebied van unsigned integers, moeten we het wel in c++ doen)
		pFileStream->Stat(&fileStats, STATFLAG_NONAME);
		pDeviceObjectValues->SetUnsignedLargeIntegerValue(WPD_OBJECT_SIZE, fileStats.cbSize.QuadPart);

		hr = pDeviceContent->CreateObjectWithPropertiesAndData(pDeviceObjectValues, 
			&pDeviceStream, &dwBufferSize, NULL);
		
		if(SUCCEEDED(hr))
		{
			pDeviceStream->QueryInterface(IID_IPortableDeviceDataStream, (void**)&pDeviceDataStream);

			//data kopieren
			pBuffer = new BYTE[dwBufferSize];
			dwReadFromStream = 0;
			do
			{
				pFileStream->Read(pBuffer, dwBufferSize, &dwReadFromStream);
				pDeviceDataStream->Write(pBuffer, dwReadFromStream, NULL);
			}
			while(dwReadFromStream > 0);
			delete[] pBuffer;
			hr = pDeviceDataStream->Commit(STGC_DEFAULT);

			if(SUCCEEDED(hr))
			{
				pDeviceDataStream->GetObjectID(&wszObjectID);
				jsObjectID = (jstring)env->NewString((jchar*)wszObjectID, wcslen(wszObjectID));
				CoTaskMemFree(wszObjectID);
				return jsObjectID;
			}
			else
			{
				ThrowCOMException(env, L"Couldn't commit the data to the portable device", hr);
			}
		}
		else
		{
			ThrowCOMException(env, L"Couldn't create a COM stream object to the portable device", hr);
		}
	}
	else
	{
		ThrowCOMException(env, L"Couldn't create a COM stream object to the file", hr);
	}

	return NULL;
}