1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
   |  
// Ouverture de la communication avec le fichier...
JNIEXPORT jboolean JNICALL Java_jni_LibraryInterface_openFile
  (JNIEnv * env, jobject obj, jstring path)
{
	try {
		// Initialisation du fichier contenant les infos de test...
		FILE * fic;
		// Remise à zéro du fichier 
		fic = fopen("C:/MyLogFile.txt", "a+");
		fprintf(fic, "OpenFile()...\n");
 
 
		//NOTE: It you are in a MFC project, Do not forget to Add ::CoInitialize() like in method InitInstance() 
		//before calling CreateInstance, if you don't put this call, CreateInstance will fail!!!
		if (m_pDataFile == NULL ) {
			fprintf(fic, "m_pDataFile == NULL\n");
			// Smart pointer used to access the COM object.
			HRESULT hr = m_pDataFile.CreateInstance( __uuidof(DataFile::DataFile) );
			if(FAILED(hr))
			{
				fprintf(fic, "m_pDataFile.CreateInstance() failed...\n");
				throw(hr);
			}
 
			// Unlock security with the IDataFileEx::InternalUse() method
			DataFile::IDataFileExPtr pDataFileEx = m_pDataFile;
			pDataFileEx->InternalUse( _bstr_t("Unlock") );
		}
 
 
		// on remplace les accents...
		char * pathConverted = JNU_GetStringNativeChars(env, path);
 
		if (pathConverted == NULL) {
			printf("OpenFile () => pathConverted == NULL\n");
			fprintf(fic, "OpenFile () => pathConverted == NULL\n");
		}
		else {
			fprintf(fic, "En attente de l'OpenFile()...\n");
			m_pDataFile->OpenFile((_bstr_t)pathConverted);
			fprintf(fic, "m_pDataFile->OpenFile() ok...\n");
		}
 
		// Fermeture du fichier 
		fclose(fic);
 
		return TRUE;
	}
	catch(_com_error &e)
	{
		DisplayErrorDescription(e);
		return FALSE;
	}
}
 
 
//Fermeture de la communication avec le fichier.
JNIEXPORT jboolean JNICALL Java_jni_LibraryInterface_closeFile
  (JNIEnv * env, jobject)
{
	// Initialisation du fichier contenant les infos de test...
	FILE * fic;
	fic = fopen("C:/MyLogFile.txt", "a+");
	// Remise à zéro du fichier 
	fprintf(fic, "CloseFile() en cours...\n");
 
 
	if(m_pDataFile != NULL) {
		m_pDataFile->CloseFile();
		fprintf(fic, "m_pDataFile->CloseFile()...\n");
		m_pDataFile = NULL;
		fprintf(fic, "m_pDataFile = NULL...\n");
	}
 
	m_pChannel = NULL;
	m_pBeam = NULL;
	m_pGate = NULL;
	m_pDataGroup = NULL;
 
	fprintf(fic, "CloseFile() fait...\n");
	// Fermeture du fichier 
	fclose(fic);
 
	return TRUE;
} |