Les Snippets

Connexion

Obtenir le message d'erreur d'une fonction Win32

Niveau requis pour utiliser/comprendre cette source : 1 ( Débutant )
Créé le 09/04/2007 00:09:47 et initié par Lutinore [Liste]
Date de mise à jour : 26/10/2007 14:22:16
Vue : 5497
Catégorie(s) : API
Langages dispo pour ce code :
- C# 1.x, C# 2.x
- VB 2005, VB.NET 1.x
- Voir tous les langages pour ce code snippet



Langage : VB.NET 1.x , VB 2005
Date ajout : 26/10/2007
Posté par Willi [Liste]
DateMAJ : 26/10/2007

.5 ' using System.Runtime.InteropServices;

<DllImport("kernel32.dll", CharSet := CharSet.Auto)> _
Private Shared Function FormatMessage(ByVal dwFlags As UInteger, ByVal lpSource As IntPtr, ByVal dwMessageId As UInteger, ByVal dwLanguageId As UInteger, ByRef lpBuffer As IntPtr, ByVal nSize As UInteger, _ 
ByVal Arguments As IntPtr) As UInteger

End Function
Public Function GetLastWin32ErrorMessage() As String 
Return GetLastWin32ErrorMessage(Marshal.GetLastWin32Error())

End Function
Public Function GetLastWin32ErrorMessage(ByVal errorCode As Integer) As String 
Dim buffer As IntPtr = IntPtr.Zero
Dim cnt As UInteger = FormatMessage(256 Or 512 Or 4096, IntPtr.Zero, DirectCast(errorCode, UInteger), 0, buffer, 0, _ 
IntPtr.Zero)
If cnt = 0 OrElse buffer = IntPtr.Zero Then 
Return [String].Format("Unknown error: {0}.", errorCode)
End IfDim errorMessage As String = Marshal.PtrToStringAuto(buffer, DirectCast(cnt, Integer)) 
Marshal.FreeHGlobal(buffer)

Return errorMessage

End Function




Codes sources en rapport avec : Erreur, Getlasterror, Formatmessage, Getlastwin32error

{C / C++ / C++.NET} EXPLICATIF D'ERREURS : EXPLICITELASTERROR() <= GETLASTERROR
Cette fonction donne l'explication de la derniere erreur levée récupérée avec GetLastError Elle...

{Visual Basic, VB6, VB.NET, VB 2005} COMBOBOX FAÇON ERRORPROVIDER
Ce que je reproche au contrôle ErrorProvider, dans le cas d'un formulaire contenant des onglets, c'e...

{PHP} TRAITER LES ERREURS PHP GRAVES, NON INTERCEPTABLES
Comment traiter les erreurs PHP qui ne peuvent être interceptées et gérées par script PHP? Impossibl...

{Delphi} RÉELS ET RÉALITÉ
Soucieux d'assurer un certain confort à mes vieux jours, je suis allé trouver mon banquier. Comme je...

{PHP} [PHP5] EXCEPTIONERROR PACKAGE : TRANSFORMER TOUTES LES ERREURS PHP EN EXCEPTIONS INTERCEPTABLES
Ce package permet de transformer toutes les erreurs PHP en exceptions interceptables. En clair, sur...

{Delphi} SIGNIFICATION DES CODES D'ERREUR DE L'API WIN32 - UTILISATION D'UNE TLISTVIEW
Les différents messages d'erreur Win32 sont présentés dans une ListView avec tri croissant/décroissa...

{JAVA / J2EE} DKSERRORFRAMEWORK : UN PETIT ENSEMBLE DE CLASSE POUR AUTOMATISER LES MESSAGES D'ERREUR
Je vous propose une toute petite source qui vous permet d'automatiser les messages d'erreurs. Rie...

{PHP} TRACE DES ERREURS EN PHP
Bonjour, Ci-joint un exemple permettant de voir un trace des fonctions qui ont abouti à une erreur...

{Javascript / DHTML} GESTION DES MESSAGES D'ERREUR 404 PERSONALISÉS ET PAGE DE MAINTENANCE
Je vous présente 2 petites astuces pour gérer les erreurs de type "ERREUR 404", ... et aussi comment...

{Delphi} LA LISTE DES ERREURS DU BDE
salut Voila un example qui affiche une liste complete des erreurs du BDE. je cherche longtemps pou...