DOCUMENTATION EN LIGNE
DE WINDEVWEBDEV ET WINDEV MOBILE

Aide / WLangage / Fonctions WLangage / Fonctions standard / Fonctions de gestion de Windows / Fonctions diverses Windows
  • Création d'une interface COM
COMRécupèreInterface (Exemple)
Création d'une interface COM
Cet exemple permet de récupérer 2 interfaces COM et de les utiliser.
// L'utilisation d'objets COM nécessite d'avoir les GUID des objets COM à manipuler
// et le fichier ".ild" qui décrit l'interface
sGUID_MapAndGuide est une chaîne = "3BC6D73B-C10D-4E76-B90F0B40C657FEE4"
sGUID_Interface_IMGApplication est une chaîne = "5FD5D92B-A4B6-4B32-AC3DA6FF7AE83CD8"
InterfaceApplication est un COMObjet dynamique
 
// Crée une interface COM basée sur le GUID "sGUID_MapAndGuide"
// pour l'interface "sGUID_Interface_IMGApplication"
InterfaceApplication = COMCréeInstance(sGUID_MapAndGuide, sGUID_Interface_IMGApplication)
SI InterfaceApplication = Null ALORS
Erreur("Echec de la récupération de l'interface COM", ErreurInfo())
RETOUR
FIN
 
// Interface COM récupérée
 
 
 
// Exemple de récupération d'une autre interface COM depuis l'interface déjà récupérée
sGUID_Interface_IMGMapping est une chaîne = "D536890C-A0D2-490D-B05A2236F509DFEA"
InterfaceMapping est un COMObjet dynamique
// Crée une interface COM basée sur le GUID "sGUID_Interface_IMGMapping"
// depuis l'interface "InterfaceApplication"
InterfaceMapping = COMRécupèreInterface(InterfaceApplication, sGUID_Interface_IMGMapping)
SI InterfaceMapping = Null ALORS
Erreur("Echec de la récupération de l'interface COM IMGMapping", ErreurInfo())
RETOUR
FIN
 
// Interface COM IMGMapping récupérée
 
 
 
// Numéro des méthodes des interfaces COM
// Il faut pour cela récupérer les méthodes dans l'ordre du fichier "ild",
// et ajouter les méthodes héritées
// Ici :
// - le fichier idl est : mgAPI_doxygen.idl
//--------- Numéro des fonctions de l'interface COM IMGApplication
// - l'interface "IMGApplication" hérite de IDispatch (interface IMGApplication: IDispatch)
//  niDispatch_NumeroMethode a déjà 7 méthodes (de 0 à 6)
nIDispatch_NumeroMethode est un entier = 6
// - dans le fichier idl les méthodes sont :
// [id(0x00000001)]
// HRESULT _stdcall BringToFront( void );
nIMGApplication_BringToFront est un entier = nIDispatch_NumeroMethode+1
// [id(0x00000002)]
// HRESULT _stdcall Minimize( void );
nIMGApplication_Minimize est un entier = nIDispatch_NumeroMethode+2
// etc...
nIMGApplication_StartMG est un entier = nIDispatch_NumeroMethode+14
nIMGApplication_GetPosition est un entier = nIDispatch_NumeroMethode+15
//------------------------------------
 
// Initialisation, appel d'une méthode d'initialisation de l'interface COM IMGApplication
// Pour récupérer le résultat
nRes est un entier
// Méthode StartMG pour démarrer
// Paramètre en entrée
nAffichage est un entier = 1
// Appel de la méthode selon son numéro avec son paramètre en entrée
nRes = COMAppelleMéthode(InterfaceApplication, nIMGApplication_StartMG, nAffichage)
// Vérification et affichage du résultat
SI nRes <> 0 ALORS
Erreur("Echec de la méthode StartMG (code erreur " + nRes + ")", ErreurInfo())
RETOUR
FIN
 
// --------- Numéro des fonctions de l'interface COM IMGMapping
// l'interface com IMGMapping hérite aussi de IDispatch (interface IMGMapping: IDispatch)
// les numéros de ses fonctions partent donc aussi de 7 (niDispatch_NumeroMethode)
// [id(0x00000001)]
// HRESULT _stdcall SetFullMapView([in] long Enabled );
nIMGMapping_SetFullMapView est un entier = nIDispatch_NumeroMethode+1
//------------------------------------
 
// Appel de la méthode selon son numéro avec ses paramètres en sortie (donc leurs adresses)
// Paramètre en entrée
nModeAffichage est un entier = 1
// Appel
nRes = COMAppelleMéthode(InterfaceMapping, nIMGMapping_SetFullMapView, nModeAffichage)
// Vérification et affichage du résultat
SI nRes <> 0 ALORS
Erreur("Echec de la méthode SetFullMapView (code erreur " + nRes + ")", ErreurInfo())
SINON
Info("La méthode SetFullMapView a été appelée avec succès")
FIN
Version minimum requise
  • Version 17
Documentation également disponible pour…
Commentaires
Cliquez sur [Ajouter] pour publier un commentaire

Dernière modification : 25/05/2022

Signaler une erreur ou faire une suggestion | Aide en ligne locale