JNIEXPORT jobject JNICALL Java_jmtp_implWin32_PortableDeviceKeyCollectionImplWin32_getAt (JNIEnv* env, jobject obj, jlong jlPosition) { HRESULT hr; IPortableDeviceKeyCollection* pKeyCollection; PROPERTYKEY key; DWORD dwCount; pKeyCollection = GetPortableDeviceKeyCollection(env, obj); hr = pKeyCollection->GetCount(&dwCount); if(FAILED(hr)) { ThrowCOMException(env, L"Failed to count the collection", hr); return NULL; } if(jlPosition < dwCount && jlPosition >= 0) { hr = pKeyCollection->GetAt(static_cast<DWORD>(jlPosition), &key); if(FAILED(hr)) { ThrowCOMException(env, L"Failed to retrieve the specified element of the collection", hr); return NULL; } } else { env->ThrowNew(env->FindClass("java/lang/IndexOutOfBoundsException"), "Invalid index"); return NULL; } return ConvertPropertyKeyToJava(env, key); }
JNIEXPORT void JNICALL Java_jmtp_PortableDevicePropVariantCollectionImplWin32_removeAt (JNIEnv* env, jobject obj, jlong jlIndex) { //variabelen HRESULT hr; IPortableDevicePropVariantCollection* pPropVariantCollection; DWORD dwCount; //methode implementatie pPropVariantCollection = GetPortableDevicePropVariantCollection(env, obj); hr = pPropVariantCollection->GetCount(&dwCount); if(SUCCEEDED(hr)) { if(jlIndex >= 0 && jlIndex < dwCount) { hr = pPropVariantCollection->RemoveAt((DWORD)jlIndex); if(FAILED(hr)) { ThrowCOMException(env, L"Failed to remove the element from the collection", hr); return; } } else { env->ThrowNew(env->FindClass("java/lang/IndexOutOfBoundsException"), "index out of range"); } } else { ThrowCOMException(env, L"Failed to check the bounds of the collection", hr); } }
JNIEXPORT void JNICALL Java_jmtp_implWin32_PortableDeviceKeyCollectionImplWin32_removeAt (JNIEnv* env, jobject obj, jlong jlPosition) { HRESULT hr; IPortableDeviceKeyCollection* pKeyCollection; DWORD dwCount; pKeyCollection = GetPortableDeviceKeyCollection(env, obj); hr = pKeyCollection->GetCount(&dwCount); if(FAILED(hr)) { ThrowCOMException(env, L"Failed to count the collection", hr); return; } if(jlPosition < dwCount && jlPosition >= 0) { hr = pKeyCollection->RemoveAt(static_cast<DWORD>(jlPosition)); if(FAILED(hr)) { ThrowCOMException(env, L"Failed to remove the specified element from the collection", hr); return; } } else { env->ThrowNew(env->FindClass("java/lang/IndexOutOfBoundsException"), "Invalid index"); } }
JNIEXPORT void JNICALL Java_jmtp_PortableDeviceContentImplWin32_delete (JNIEnv* env, jobject obj, jint jiOptions, jobject jobjObjectIDs) { //variabelen HRESULT hr; IPortableDeviceContent* pDeviceContent; IPortableDevicePropVariantCollection* pObjectIDs; //Methode implementatie if(jiOptions == 0 || jiOptions == 1) { pDeviceContent = GetPortableDeviceContent(env, obj); pObjectIDs = (IPortableDevicePropVariantCollection*)GetComReferencePointerFromComReferenceable(env, jobjObjectIDs); hr = pDeviceContent->Delete(jiOptions, pObjectIDs, NULL); if(FAILED(hr)) { ThrowCOMException(env, L"Failed to delete the files", hr); return; } } else { env->ThrowNew(env->FindClass("java/lang/IllegalArgumentException"), "The parameter options has an invalid value."); return; } }
JNIEXPORT void JNICALL Java_jmtp_PortableDeviceImplWin32_openImpl (JNIEnv* env, jobject obj, jobject values) { HRESULT hr; IPortableDevice* pDevice; jobject reference; jmethodID mid; IPortableDeviceValues* pClientInfo; LPWSTR wszDeviceID; jfieldID fid; jstring jsDeviceID; pDevice = GetPortableDevice(env, obj); //clientinfo value object opvragen mid = env->GetMethodID(env->GetObjectClass(values), "getReference", "()Lbe/derycke/pieter/com/COMReference;"); reference = env->CallObjectMethod(values, mid); mid = env->GetMethodID(env->FindClass("be/derycke/pieter/com/COMReference"), "getMemoryAddress", "()J"); pClientInfo = (IPortableDeviceValues*)env->CallLongMethod(reference, mid); //deviceID opvragen fid = env->GetFieldID(env->GetObjectClass(obj), "deviceID", "Ljava/lang/String;"); jsDeviceID = (jstring)env->GetObjectField(obj, fid); wszDeviceID = (WCHAR*)env->GetStringChars(jsDeviceID, NULL); hr = pDevice->Open(wszDeviceID, pClientInfo); env->ReleaseStringChars(jsDeviceID, (jchar*)wszDeviceID); if(FAILED(hr)) { ThrowCOMException(env, L"Couldn't open the device", hr); return; } }
JNIEXPORT jobject JNICALL Java_jmtp_PortableDeviceImplWin32_getDeviceContent (JNIEnv* env, jobject obj) { HRESULT hr; IPortableDevice* pDevice; IPortableDeviceContent* pContent; jclass cls; jmethodID mid; jobject reference; pDevice = GetPortableDevice(env, obj); hr = pDevice->Content(&pContent); if(FAILED(hr)) { ThrowCOMException(env, L"Couldn't retrieve the device content", hr); return NULL; } //smart reference object aanmaken cls = env->FindClass("be/derycke/pieter/com/COMReference"); mid = env->GetMethodID(cls, "<init>", "(J)V"); reference = env->NewObject(cls, mid, pContent); cls = env->FindClass("jmtp/PortableDeviceContentImplWin32"); mid = env->GetMethodID(cls, "<init>", "(Lbe/derycke/pieter/com/COMReference;)V"); return env->NewObject(cls, mid, reference); }
JNIEXPORT void JNICALL Java_jmtp_PortableDevicePropVariantCollectionImplWin32_add (JNIEnv* env, jobject obj, jobject jobjPropVariant) { //variabelen HRESULT hr; IPortableDevicePropVariantCollection* pPropVariantCollection; PROPVARIANT pv; //methode implementatie if(jobjPropVariant != NULL) { pPropVariantCollection = GetPortableDevicePropVariantCollection(env, obj); pv = ConvertJavaToPropVariant(env, jobjPropVariant); hr = pPropVariantCollection->Add(&pv); PropVariantClear(&pv); if(FAILED(hr)) { ThrowCOMException(env, L"Failed to add the element to the collection", hr); return; } } else { env->ThrowNew(env->FindClass("java/lang/NullPointerException"), "propvariant isn't allowed to be null"); } }
JNIEXPORT jobject JNICALL Java_jmtp_PortableDeviceContentImplWin32_getProperties (JNIEnv* env, jobject obj) { //variabelen HRESULT hr; IPortableDeviceContent* pContent; IPortableDeviceProperties* pProperties; jclass cls; jmethodID mid; jobject jobjReference; //Methode implementatie pContent = GetPortableDeviceContent(env, obj); hr = pContent->Properties(&pProperties); 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, pProperties); cls = env->FindClass("jmtp/PortableDevicePropertiesImplWin32"); mid = env->GetMethodID(cls, "<init>", "(Lbe/derycke/pieter/com/COMReference;)V"); return env->NewObject(cls, mid, jobjReference); } else { ThrowCOMException(env, L"Failed to retrieve the property object", hr); return NULL; } }
void CheckSuccess(JNIEnv* env, HRESULT hr, LPWSTR exceptionMessage) { if (!SUCCEEDED(hr)) { ThrowCOMException(env, exceptionMessage, hr); } }
JNIEXPORT jobject JNICALL Java_jmtp_PortableDevicePropVariantCollectionImplWin32_getAt (JNIEnv* env, jobject obj, jlong jlIndex) { //variabelen HRESULT hr; IPortableDevicePropVariantCollection* pPropVariantCollection; PROPVARIANT pv; jobject jobjPropVariant; DWORD dwCount; //methode implementatie pPropVariantCollection = GetPortableDevicePropVariantCollection(env, obj); hr = pPropVariantCollection->GetCount(&dwCount); if(SUCCEEDED(hr)) { if(jlIndex >= 0 && jlIndex < dwCount) { hr = pPropVariantCollection->GetAt((DWORD)jlIndex, &pv); if(SUCCEEDED(hr)) { jobjPropVariant = ConvertPropVariantToJava(env, pv); PropVariantClear(&pv); return jobjPropVariant; } else { ThrowCOMException(env, L"Failed to retrieve the element from the collection", hr); } } else { env->ThrowNew(env->FindClass("java/lang/IndexOutOfBoundsException"), "index out of range"); } } else { ThrowCOMException(env, L"Failed to check the bounds of the collection", hr); } return NULL; }
JNIEXPORT jobjectArray JNICALL Java_jmtp_PortableDeviceManagerImplWin32_getDevicesImpl (JNIEnv* env, jobject obj) { HRESULT hr; IPortableDeviceManager* pDeviceManager; LPWSTR* deviceIDs; DWORD dwCount; jobjectArray jobjaDeviceIDs; pDeviceManager = GetPortableDeviceManager(env, obj); hr = pDeviceManager->GetDevices(NULL, &dwCount); if(FAILED(hr)) { ThrowCOMException(env, L"Failed to count the connected devices", hr); return NULL; } else { deviceIDs = new LPWSTR[dwCount]; hr = pDeviceManager->GetDevices(deviceIDs, &dwCount); if(SUCCEEDED(hr)) { jobjaDeviceIDs = env->NewObjectArray(dwCount, env->FindClass("java/lang/String"), NULL); for(DWORD i = 0; i < dwCount; i++) { env->SetObjectArrayElement(jobjaDeviceIDs, i, env->NewString((jchar*)deviceIDs[i], wcslen(deviceIDs[i]))); CoTaskMemFree(deviceIDs[i]); } } delete[] deviceIDs; if(FAILED(hr)) { ThrowCOMException(env, L"Failed to count the connected devices", hr); return NULL; } return jobjaDeviceIDs; } }
JNIEXPORT void JNICALL Java_jmtp_PortableDeviceManagerImplWin32_refreshDeviceListImpl (JNIEnv* env, jobject obj) { HRESULT hr; IPortableDeviceManager* pDeviceManager; pDeviceManager = GetPortableDeviceManager(env, obj); hr = pDeviceManager->RefreshDeviceList(); if(FAILED(hr)) { ThrowCOMException(env, L"Failed to refresh the devicelist", hr); return; } }
JNIEXPORT void JNICALL Java_jmtp_PortableDevicePropVariantCollectionImplWin32_clear (JNIEnv* env, jobject obj) { HRESULT hr; IPortableDevicePropVariantCollection* pPropVariantCollection; pPropVariantCollection = GetPortableDevicePropVariantCollection(env, obj); hr = pPropVariantCollection->Clear(); if(FAILED(hr)) { ThrowCOMException(env, L"Failed to clear the collection", hr); return; } }
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 jint JNICALL Java_jmtp_implWin32_PortableDeviceObjectOutputStream_readDataToBuffer (JNIEnv *env, jobject jThis, jbyteArray buf, jint byteCount) { IStream* stream = (IStream *)RetrievePointerFromCOMReferenceable(env, jThis); BYTE* localBuf = new BYTE[byteCount]; ULONG toWrite; env->GetByteArrayRegion(buf, 0, byteCount, (jbyte *)localBuf); HRESULT hr = stream->Write(localBuf, byteCount, &toWrite); if (FAILED(hr)) { ThrowCOMException(env, L"Failed to write data into mobile device", hr); return -1; } return toWrite; }
JNIEXPORT jobjectArray JNICALL Java_jmtp_PortableDeviceContentImplWin32_listChildObjects (JNIEnv* env, jobject obj, jstring jsParentID) { //variabelen HRESULT hr; IPortableDeviceContent* pDeviceContent; LPWSTR wszParentID; CComPtr<IEnumPortableDeviceObjectIDs> pEnum; std::list<LPWSTR> childList; std::list<LPWSTR>::iterator iterator; LPWSTR* wszObjectID; ULONG fetched; jobjectArray jobjaChildArray; //Methode implementatie pDeviceContent = GetPortableDeviceContent(env, obj); wszParentID = (WCHAR*)env->GetStringChars(jsParentID, NULL); hr = pDeviceContent->EnumObjects(0, wszParentID, NULL, &pEnum); env->ReleaseStringChars(jsParentID, (jchar*)wszParentID); if(SUCCEEDED(hr)) { wszObjectID = new LPWSTR[1]; while(SUCCEEDED(pEnum->Next(1, wszObjectID, &fetched)) && fetched > 0) { childList.push_back(wszObjectID[0]); } delete[] wszObjectID; jobjaChildArray = env->NewObjectArray(childList.size(), env->FindClass("Ljava/lang/String;"), NULL); int i = 0; for (iterator = childList.begin(); iterator != childList.end(); iterator++) { env->SetObjectArrayElement(jobjaChildArray, i, env->NewString((jchar*)*iterator, wcslen(*iterator))); CoTaskMemFree(*iterator); i++; } return jobjaChildArray; } else { ThrowCOMException(env, L"Failed to retrieve the enumerator", hr); } return NULL; }
JNIEXPORT jlong JNICALL Java_jmtp_implWin32_PortableDeviceKeyCollectionImplWin32_count (JNIEnv* env, jobject obj) { HRESULT hr; IPortableDeviceKeyCollection* pKeyCollection; DWORD dwCount; pKeyCollection = GetPortableDeviceKeyCollection(env, obj); hr = pKeyCollection->GetCount(&dwCount); if(FAILED(hr)) { ThrowCOMException(env, L"Failed to count the collection", hr); return -1; } return dwCount; }
JNIEXPORT jobject JNICALL Java_jmtp_PortableDeviceContentImplWin32_getObjectIDsFromPersistentUniqueIDs (JNIEnv* env, jobject obj, jobject jobjPropVariantCollection) { //variabelen HRESULT hr; IPortableDeviceContent* pContent; IPortableDevicePropVariantCollection* pPersistentUniqueIDs; IPortableDevicePropVariantCollection* pObjectIDs; jclass cls; jmethodID mid; jobject jobjReference; //Methode implementatie if(jobjPropVariantCollection != NULL) { pContent = GetPortableDeviceContent(env, obj); pPersistentUniqueIDs = (IPortableDevicePropVariantCollection*)GetComReferencePointerFromComReferenceable(env, jobjPropVariantCollection); hr = pContent->GetObjectIDsFromPersistentUniqueIDs(pPersistentUniqueIDs, &pObjectIDs); 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, pObjectIDs); cls = env->FindClass("jmtp/PortableDevicePropVariantCollectionImplWin32"); mid = env->GetMethodID(cls, "<init>", "(Lbe/derycke/pieter/com/COMReference;)V"); return env->NewObject(cls, mid, jobjReference); } else { ThrowCOMException(env, L"Failed to retrieve the ObjectIDs", hr); return NULL; } } else { env->ThrowNew(env->FindClass("java/lang/NullPointerException"), "persistentUniqueIDs can't be null"); return NULL; } }
JNIEXPORT jlong JNICALL Java_jmtp_PortableDevicePropVariantCollectionImplWin32_count (JNIEnv* env, jobject obj) { HRESULT hr; IPortableDevicePropVariantCollection* pPropVariantCollection; DWORD dwCount; pPropVariantCollection = GetPortableDevicePropVariantCollection(env, obj); hr = pPropVariantCollection->GetCount(&dwCount); if(SUCCEEDED(hr)) { return (jlong)dwCount; } else { ThrowCOMException(env, L"Failed to count the collection", hr); return -1; } }
JNIEXPORT void JNICALL Java_jmtp_implWin32_PortableDeviceKeyCollectionImplWin32_add (JNIEnv* env, jobject obj, jobject jobjKey) { HRESULT hr; IPortableDeviceKeyCollection* pKeyCollection; if(jobjKey == NULL) { env->ThrowNew(env->FindClass("java/lang/IllegalArgumentException"), "key can't be null"); return; } else { pKeyCollection = GetPortableDeviceKeyCollection(env, obj); hr = pKeyCollection->Add(ConvertJavaToPropertyKey(env, jobjKey)); if(FAILED(hr)) { ThrowCOMException(env, L"Failed to add the key to the collection", hr); return; } } }
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); }
JNIEXPORT jobject JNICALL Java_jmtp_PortableDevicePropertiesImplWin32_getPropertyAttributes (JNIEnv* env, jobject obj, jstring jsObjectID, jobject key) { HRESULT hr; IPortableDeviceProperties* pProperties; IPortableDeviceValues* pValues; LPWSTR wszObjectID; jclass cls; jmethodID mid; jobject reference; pProperties = GetPortableDeviceProperties(env, obj); wszObjectID = (WCHAR*)env->GetStringChars(jsObjectID, NULL); //printf("%ws\n", wszObjectID); //printf("s10001\n"); hr = pProperties->GetPropertyAttributes(L"DEVICE", WPD_RESOURCE_ATTRIBUTE_CAN_DELETE, &pValues); env->ReleaseStringChars(jsObjectID,(jchar*)wszObjectID); if(FAILED(hr)) { ThrowCOMException(env, L"Failed to retrieve the property", hr); } BOOL del; //hr = pValues->GetBoolValue(WPD_RESOURCE_ATTRIBUTE_CAN_DELETE, &del);; //printf("naam: %i\n", del); //smart reference object aanmaken cls = env->FindClass("be/derycke/pieter/com/COMReference"); mid = env->GetMethodID(cls, "<init>", "(J)V"); reference = env->NewObject(cls, mid, pValues); cls = env->FindClass("jmtp/PortableDeviceValues"); mid = env->GetMethodID(cls, "<init>", "(Lbe/derycke/pieter/com/COMReference;)V"); return env->NewObject(cls, mid, reference); }
JNIEXPORT jobject JNICALL Java_jmtp_PortableDeviceImplWin32_sendCommand (JNIEnv* env, jobject obj, jobject values) { HRESULT hr; IPortableDevice* pDevice; IPortableDeviceValues* pValuesIn; IPortableDeviceValues* pValuesOut; jclass cls; jmethodID mid; jobject reference; pDevice = GetPortableDevice(env, obj); //clientinfo value object opvragen mid = env->GetMethodID(env->GetObjectClass(values), "getReference", "()Lbe/derycke/pieter/com/COMReference;"); reference = env->CallObjectMethod(values, mid); mid = env->GetMethodID(env->FindClass("be/derycke/pieter/com/COMReference"), "getMemoryAddress", "()J"); pValuesIn = (IPortableDeviceValues*)env->CallLongMethod(reference, mid); hr = pDevice->SendCommand(0, pValuesIn, &pValuesOut); if(FAILED(hr)) { ThrowCOMException(env, L"The custom command failed.", hr); return NULL; } //smart reference object aanmaken cls = env->FindClass("be/derycke/pieter/com/COMReference"); mid = env->GetMethodID(cls, "<init>", "(J)V"); reference = env->NewObject(cls, mid, pValuesOut); cls = env->FindClass("jmtp/PortableDeviceValuesImplWin32"); mid = env->GetMethodID(cls, "<init>", "(Lbe/derycke/pieter/com/COMReference;)V"); return env->NewObject(cls, mid, reference); }
JNIEXPORT jstring JNICALL Java_jmtp_PortableDeviceContentImplWin32_createObjectWithPropertiesOnly (JNIEnv* env, jobject obj, jobject jobjValues) { //variabelen HRESULT hr; IPortableDeviceContent* pDeviceContent; IPortableDeviceValues* pValues; LPWSTR wszObjectID; jstring jsObjectID; //Methode implementatie if(jobjValues != NULL) { pDeviceContent = GetPortableDeviceContent(env, obj); pValues = (IPortableDeviceValues*)GetComReferencePointerFromComReferenceable(env, jobjValues); hr = pDeviceContent->CreateObjectWithPropertiesOnly(pValues, &wszObjectID); if(SUCCEEDED(hr)) { jsObjectID = (jstring)env->NewString((jchar*)wszObjectID, wcslen(wszObjectID)); CoTaskMemFree(wszObjectID); return jsObjectID; } else { ThrowCOMException(env, L"Couldn't create the file", hr); return NULL; } } else { env->ThrowNew(env->FindClass("java/lang/NullPointerException"), "values can't be null"); return NULL; } }
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; }