[Visual C++] boite dlg Sauvegarde ferme l'application...

boite dlg Sauvegarde ferme l'application... [Visual C++] - Programmation

Marsh Posté le 29-05-2001 à 10:07:58    

Dans mon prog, j'utilise une boite de dialogue appelée par getSaveFileName(..)
 
Le pb, c'est que quand le programme appelle cette fonction, il se ferme...
 
 
Voilà le code, si quelqu'un pouvait regarder si il y des erreurs ou si quelqu'un pouvait le tester sur une autre machine, ça pourrait être sympatique...
 
char * returnChar = 0;
 
 OPENFILENAME * structSauvegarde = new OPENFILENAME();
 structSauvegarde->lStructSize = sizeof (OPENFILENAME) ;
 structSauvegarde->hwndOwner = hwnd ;
 structSauvegarde->lpstrFilter = filter ;
 structSauvegarde->nFilterIndex = 1 ;  
 structSauvegarde->lpstrFile = returnChar ;  
 structSauvegarde->nMaxFile = sizeof(returnChar) ;  
 structSauvegarde->lpstrFileTitle = NULL ;
 structSauvegarde->lpstrInitialDir = NULL ;
 structSauvegarde->lpstrTitle = "Sauvegarder le fichier" ;
 structSauvegarde->Flags = OFN_CREATEPROMPT | OFN_OVERWRITEPROMPT ;  
// view more : http://msdn.microsoft.com/library/ [...] 3_1hma.htm
 
 
 if (GetSaveFileName(structSauvegarde))
 {
  MessageBox(NULL, returnChar,
      NULL, MB_OK | MB_ICONINFORMATION | MB_SYSTEMMODAL | MB_DEFBUTTON2) ;
  return returnChar ;  
 }
 else
 {
  return NULL ;
 }
 
merci d'avance !  :jap:
 
 
 
 
(Visual C++, win98)

 

[edit]--Message édité par Moustaaki--[/edit]

Reply

Marsh Posté le 29-05-2001 à 10:07:58   

Reply

Marsh Posté le 29-05-2001 à 11:19:03    

les erreurs générées par le debugger :
 
Loaded 'C:\WINDOWS\SYSTEM\SHELL32.DLL', no matching symbolic information found.
Loaded 'C:\WINDOWS\SYSTEM\COMCTL32.DLL', no matching symbolic information found.
Loaded 'C:\WINDOWS\SYSTEM\SHLWAPI.DLL', no matching symbolic information found.
Loaded 'C:\WINDOWS\SYSTEM\COMDLG32.DLL', no matching symbolic information found.
Loaded 'C:\WINDOWS\SYSTEM\ADVAPI32.DLL', no matching symbolic information found.
Loaded 'C:\WINDOWS\SYSTEM\GDI32.DLL', no matching symbolic information found.
Loaded 'C:\WINDOWS\SYSTEM\USER32.DLL', no matching symbolic information found.
Loaded 'C:\WINDOWS\SYSTEM\KERNEL32.DLL', no matching symbolic information found.
Loaded 'C:\WINDOWS\SYSTEM\VERSION.DLL', no matching symbolic information found.
Loaded 'C:\WINDOWS\SYSTEM\OLEAUT32.DLL', no matching symbolic information found.
Loaded 'C:\WINDOWS\SYSTEM\OLE32.DLL', no matching symbolic information found.
Loaded 'C:\Program Files\Caere\OmniPagePro90\OPHOOK32.dll', no matching symbolic information found.
First-chance exception in tradNSP.exe (KERNEL32.DLL): 0xC0000005: Access Violation.
First-chance exception in tradNSP.exe (KERNEL32.DLL): 0xC0000005: Access Violation.
First-chance exception in tradNSP.exe (COMDLG32.DLL): 0xC0000005: Access Violation.
First-chance exception in tradNSP.exe (COMDLG32.DLL): 0xC0000005: Access Violation.
First-chance exception in tradNSP.exe (COMDLG32.DLL): 0xC0000005: Access Violation.
First-chance exception in tradNSP.exe (COMDLG32.DLL): 0xC0000005: Access Violation.
The program 'E:\hugo\MesDoc\Visual\tradNSP\Debug\tradNSP.exe' has exited with code 0 (0x0).

Reply

Marsh Posté le 29-05-2001 à 11:19:16    

argl

Reply

Marsh Posté le 29-05-2001 à 12:26:20    

Il ya 2 err :
1) tu definit un ptr char que tu initialises a null (char * returnChar = 0), t'etonnes pas apres que ca merde.
2) tu utilse un new alors que ten a pas besoin
Essaies plutot ca :
 
char returnChar[MAX_PATH];  
 
OPENFILENAME structSauvegarde:
structSauvegarde.lStructSize = sizeof (OPENFILENAME) ;  
structSauvegarde.hwndOwner = hwnd ;  
structSauvegarde.lpstrFilter = filter ;  
structSauvegarde.nFilterIndex = 1 ;  
structSauvegarde.lpstrFile = returnChar ;  
structSauvegarde.nMaxFile = sizeof(returnChar) ;  
structSauvegarde.lpstrFileTitle = NULL ;  
structSauvegarde.lpstrInitialDir = NULL ;  
structSauvegarde.lpstrTitle = "Sauvegarder le fichier" ;  
structSauvegarde.Flags = OFN_CREATEPROMPT | OFN_OVERWRITEPROMPT ;  
// ...  la suite idem sauf kil faut passer l'addr de la struct :
GetSaveFileName(&structSauvegarde) au lieu de GetSaveFileName(structSauvegarde)

 

[edit]--Message édité par Amadeus--[/edit]

Reply

Marsh Posté le 29-05-2001 à 14:22:31    

j'ai déclaré la variable char comme tu m'as dit, en global...
ensuite j'ai changé ça dans le code :
 
 // définition des paramètres pour la boite de dialogue de sauvegarde.
 OPENFILENAME structSauvegarde ;
 structSauvegarde.lStructSize = sizeof (OPENFILENAME) ;
 structSauvegarde.hwndOwner = hwnd ;
 structSauvegarde.lpstrFilter = filter ;
 structSauvegarde.nFilterIndex = 1 ;  
 structSauvegarde.lpstrFile = fileName ;  
 structSauvegarde.nMaxFile = sizeof(fileName) ;  
 structSauvegarde.lpstrFileTitle = NULL ;
 structSauvegarde.lpstrInitialDir = "C:\\Mes documents\\" ;
 structSauvegarde.lpstrTitle = "Sauvegarder le fichier" ;
 structSauvegarde.Flags = OFN_CREATEPROMPT | OFN_OVERWRITEPROMPT ;
// view more : http://msdn.microsoft.com/library/ [...] 3_1hma.htm
 
 
 if (GetSaveFileName(&structSauvegarde))
 {
  MessageBox(NULL, fileName,
      NULL, MB_OK | MB_ICONINFORMATION | MB_SYSTEMMODAL | MB_DEFBUTTON2) ;
  return fileName ;  
 }
 else
 {
  return NULL ;
 }
 
 
 
ET ça me fait toujours la même chose . violation d'accès.
Si j'ouvre le debugger, le context est : Comdlg32.dll, je suppose vue le nom et le contexte que c'est la dll "s'occupant" des boites de dialogues.  
 
Sans le debugger, je n'ai aucune erreur mais ça quite quand même.
 
ARGL
 
 
 
Petite info sup ; le debugger liste les erreurs suivantes pendant l'execution :
 
Loaded 'C:\WINDOWS\SYSTEM\SHELL32.DLL', no matching symbolic information found.
Loaded 'C:\WINDOWS\SYSTEM\COMCTL32.DLL', no matching symbolic information found.
Loaded 'C:\WINDOWS\SYSTEM\SHLWAPI.DLL', no matching symbolic information found.
Loaded 'C:\WINDOWS\SYSTEM\COMDLG32.DLL', no matching symbolic information found.
Loaded 'C:\WINDOWS\SYSTEM\ADVAPI32.DLL', no matching symbolic information found.
Loaded 'C:\WINDOWS\SYSTEM\GDI32.DLL', no matching symbolic information found.
Loaded 'C:\WINDOWS\SYSTEM\USER32.DLL', no matching symbolic information found.
Loaded 'C:\WINDOWS\SYSTEM\KERNEL32.DLL', no matching symbolic information found.
Loaded 'C:\WINDOWS\SYSTEM\VERSION.DLL', no matching symbolic information found.
Loaded 'C:\WINDOWS\SYSTEM\OLEAUT32.DLL', no matching symbolic information found.
Loaded 'C:\WINDOWS\SYSTEM\OLE32.DLL', no matching symbolic information found.
Loaded 'C:\Program Files\Caere\OmniPagePro90\OPHOOK32.dll', no matching symbolic information found.
First-chance exception in tradNSP.exe (KERNEL32.DLL): 0xC0000005: Access Violation.
First-chance exception in tradNSP.exe (KERNEL32.DLL): 0xC0000005: Access Violation.
First-chance exception in tradNSP.exe (COMDLG32.DLL): 0xC0000005: Access Violation.
The program 'E:\hugo\MesDoc\Visual\tradNSP\Debug\tradNSP.exe' has exited with code 0 (0x0).

 

[edit]--Message édité par Moustaaki--[/edit]

Reply

Marsh Posté le 29-05-2001 à 14:45:20    

// voila ta fonction retouche :
// elle marche : g fait un test vite fait donc ya pas de raison  
// kel marche pas chez toi
 
int Test(char* nomdefichier)
{
 
 OPENFILENAME structSauvegarde;
 char szNom[MAX_PATH];
 
 ZeroMemory(&structSauvegarde, sizeof(structSauvegarde));
 szNom[0] = '\0'; // n oublies surtout pas cette ligne
 structSauvegarde.lStructSize = sizeof (OPENFILENAME) ;
 structSauvegarde.hwndOwner = 0 ;
 structSauvegarde.lpstrFilter = "hfr (*.hfr)\0*.hfr\0" ;
 structSauvegarde.nFilterIndex = 1 ;  
 structSauvegarde.lpstrFile = szNom ;  
 structSauvegarde.nMaxFile = sizeof(szNom) ;  
 structSauvegarde.lpstrFileTitle = NULL ;
 structSauvegarde.lpstrInitialDir = "C:\\" ;
 structSauvegarde.lpstrTitle = "Sauvegarder le fichier" ;
 structSauvegarde.Flags = OFN_CREATEPROMPT | OFN_OVERWRITEPROMPT ;
 
 if (GetSaveFileName(&structSauvegarde))
 {
   MessageBox(NULL, (LPCTSTR)szNom,
   NULL, MB_OK | MB_ICONINFORMATION | MB_SYSTEMMODAL | MB_DEFBUTTON2) ;
   strcpy(nomdefichier,  (const char*)szNom);
   return 0; // retourne juste un int et la chaine nomdefichier contiendra... le nom de fichier    :)
 }
 // le else est superflu ici
 return -1; // erreur
 
 // et ca marche! teste et approuve!
}

Reply

Marsh Posté le 29-05-2001 à 15:00:58    

merci beaucoup !
c'est vraiment sympa de ta part !
 
 
ça marche nikel...

 

[edit]--Message édité par Moustaaki--[/edit]

Reply

Marsh Posté le 29-05-2001 à 15:07:12    

de rien ;)
 

Moustaaki a écrit a écrit :

merci beaucoup !
c'est vraiment sympa de ta part !



Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed