ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage functions / Standard functions / Windows functions / Miscellaneous Windows functions
  • Creating a COM interface
COMQueryInterface (Example)
Creating a COM interface
This example retrieves 2 COM interfaces and uses them.
// The use of COM objects requires that you know the GUID of the COM objects to handle
// as well as the ".ild" file describing the interface
sGUID_MapAndGuide is string = "3BC6D73B-C10D-4E76-B90F0B40C657FEE4"
sGUID_Interface_IMGApplication is string = "5FD5D92B-A4B6-4B32-AC3DA6FF7AE83CD8"
ApplicationInterface is COMObject dynamic
 
// Create a COM interface based on the "sGUID_MapAndGuide" GUID
// for the "sGUID_Interface_IMGApplication" interface
ApplicationInterface = COMCreateInstance(sGUID_MapAndGuide, sGUID_Interface_IMGApplication)
IF ApplicationInterface = Null THEN
Error("Failure retrieving the COM interface", ErrorInfo())
RETURN
END
 
// Retrieved COM interface
 
 
 
// Example of retrieval of another COM interface from the interface already retrieved
sGUID_Interface_IMGMapping is string = "D536890C-A0D2-490D-B05A2236F509DFEA"
InterfaceMapping is dynamic COMObject
// Create a COM interface based on the "sGUID_Interface_IMGMapping" GUID
// from the "ApplicationInterface" interface
InterfaceMapping = COMQueryInterface(ApplicationInterface, sGUID_Interface_IMGMapping)
IF InterfaceMapping = Null THEN
Error("Failure while retrieving the IMGMapping COM interface", ErrorInfo())
RETURN
END
 
// Retrieved IMGMapping COM interface
 
 
 
// COM interfaces method number
// We need to retrieve the methods in the order if the "id" file,
// and add inherited methods
// Here:
// - the idl file is: mgAPI_doxygen.idl
//--------- Function number of the IMGApplication COM interface's functions
// - the "IMGApplication" interface inherits from IDispatch (IMGApplication interface: IDispatch)
//  niDispatch_MethodNumber has already 7 methods (from 0 to 6)
nIDispatch_MethodNumber is int = 6
// - in the idl file the methods are:
// [id(0x00000001)]
// HRESULT _stdcall BringToFront( void );
nIMGApplication_BringToFront is int = nIDispatch_MethodNumber+1
// [id(0x00000002)]
// HRESULT _stdcall Minimize( void );
nIMGApplication_Minimize is int = nIDispatch_MethodNumber+2
// etc...
nIMGApplication_StartMG is int = nIDispatch_MethodNumber+14
nIMGApplication_GetPosition is int = nIDispatch_MethodNumber+15
//------------------------------------
 
// Initialization, call an initialization method of the IMGApplication COM interface
// To retrieve the result
nRes is int
// Method StartMG to start
// Input parameter
nDisplay is int = 1
// Call the method using its number and its input parameter
nRes = COMCallMethod(ApplicationInterface, nIMGApplication_StartMG, nDisplay)
// Check and display the result
IF nRes <> 0 THEN
Error("The StartMG method failed (error code " + nRes + ")", ErrorInfo())
RETURN
END
 
// --------- Number of the functions of IMGMapping COM interface
// the IMGMapping interface also inherits from IDispatch (IMGMapping interface: IDispatch)
// the numbers of these functions also start from 7 (niDispatch_MethodNumber)
// [id(0x00000001)]
// HRESULT _stdcall SetFullMapView([in] long Enabled );
nIMGMapping_SetFullMapView is int = nIDispatch_MethodNumber+1
//------------------------------------
 
// Call the method using its number with its output parameters (therefore their addresses)
// Input parameter
nDisplayMode is int = 1
// Call
nRes = COMCallMethod(InterfaceMapping, nIMGMapping_SetFullMapView, nDisplayMode)
// Check and display the result
IF nRes <> 0 THEN
Error("The SetFullMapView method failed (error code " + nRes + ")", ErrorInfo())
ELSE
Info("The SetFullMapView method was successfully called")
END
Minimum version required
  • Version 17
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 05/26/2022

Send a report | Local help